-
Notifications
You must be signed in to change notification settings - Fork 471
Thread detach hook for Java JNI on Android #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
c3c0bef
96bc6b6
b6003ed
8bf5bcf
bd54618
4be52da
10ea8cf
12163ba
0a57226
39eddf2
41772bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -861,6 +861,15 @@ gettid(void) | |
if ((f) && tsd->k) ((void(*)(void*))(f))(tsd->k); \ | ||
} while (0) | ||
|
||
#ifdef __ANDROID__ | ||
static void (*_dispatch_thread_detach_callback)(void); | ||
|
||
void | ||
*(*_dispatch_thread_detach_callback_ptr(void))(void) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is hard to read, also exposing a pointer to a function pointer is really weird. do you really need the getter? it feels like you only want to install it, I would have gone for: void
_dispatch_install_thread_detach_callback(dispatch_function_t cb)
{
if (os_atomic_xchg(&_dispatch_thread_detach_callback, cb, relaxed)) {
DISPATCH_CLIENT_CRASH(0, "Installing a thread detach callback twice");
}
} |
||
return &_dispatch_thread_detach_callback; | ||
} | ||
#endif | ||
|
||
void | ||
_libdispatch_tsd_cleanup(void *ctx) | ||
{ | ||
|
@@ -885,6 +894,11 @@ _libdispatch_tsd_cleanup(void *ctx) | |
_tsd_call_cleanup(dispatch_voucher_key, _voucher_thread_cleanup); | ||
_tsd_call_cleanup(dispatch_deferred_items_key, | ||
_dispatch_deferred_items_cleanup); | ||
#ifdef __ANDROID__ | ||
if (_dispatch_thread_detach_callback) { | ||
_dispatch_thread_detach_callback(); | ||
} | ||
#endif | ||
tsd->tid = 0; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -330,6 +330,20 @@ public extension DispatchQueue { | |
let p = Unmanaged.passRetained(v).toOpaque() | ||
dispatch_queue_set_specific(self.__wrapped, k, p, _destructDispatchSpecificValue) | ||
} | ||
|
||
#if os(Android) | ||
@_silgen_name("_dispatch_thread_detach_callback_ptr") | ||
private static func _dispatch_thread_detach_callback_ptr() -> UnsafeMutablePointer<(@convention(c) () -> Void)?> | ||
|
||
public static var threadDetachCallback: (@convention(c) () -> Void)? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think only a one-way setter should be exposed. having a getter makes the interface un-necessarily ugly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the potiners. It helps me zero in on something you’re happy with. Changed pushed. |
||
get { | ||
return _dispatch_thread_detach_callback_ptr().pointee | ||
} | ||
set(newValue) { | ||
_dispatch_thread_detach_callback_ptr().pointee = newValue | ||
} | ||
} | ||
#endif | ||
} | ||
|
||
private func _destructDispatchSpecificValue(ptr: UnsafeMutableRawPointer?) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it's static then the overlay which is a dynamic library can't pick it up.
@das suggested to me the right place is to export the symbol is from
private/queue_private.h
orprivate/private.h
and also to use silgen like you did.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Global symbol is now a function _dispatch_set_detach_callback_ptr as it doesn’t seem possible to express a global var in a silgen. I’ve moved it's declaration into queue_private.h.