Skip to content

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

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
Thread detach hook for Java JNI on Android II
  • Loading branch information
johnno1962 committed May 23, 2017
commit 96bc6b645bfbd789bd6ef46e5cb332dfa26792eb
7 changes: 4 additions & 3 deletions dispatch/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,8 @@ dispatch_assert_queue_not(dispatch_queue_t queue)
#define dispatch_assert_queue_not_debug(q) dispatch_assert_queue_not(q)
#endif


#ifdef __ANDROID__
/*!
* @handler dispatch_thread_detach_handler
*
Expand All @@ -1354,10 +1356,9 @@ dispatch_assert_queue_not(dispatch_queue_t queue)
* "detached" before the thread exits or the application will crash.
*/
DISPATCH_EXPORT
void (*dispatch_thread_detach_handler)();

void (*_dispatch_thread_detach_handler)(void);
#endif
__END_DECLS

DISPATCH_ASSUME_NONNULL_END

#endif
10 changes: 7 additions & 3 deletions src/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,9 @@ gettid(void)
if ((f) && tsd->k) ((void(*)(void*))(f))(tsd->k); \
} while (0)

void (*dispatch_thread_detach_handler)();
#ifdef __ANDROID__
void (*_dispatch_thread_detach_handler)(void);
#endif

void
_libdispatch_tsd_cleanup(void *ctx)
Expand All @@ -887,8 +889,10 @@ _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);
if (dispatch_thread_detach_handler)
dispatch_thread_detach_handler();
#ifdef __ANDROID__
if (_dispatch_thread_detach_handler)
_dispatch_thread_detach_handler();
#endif
tsd->tid = 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/swift/Queue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ public extension DispatchQueue {
#if os(Android)
public static var threadCleanupCallback: @convention(c) () -> Void {
get {
return dispatch_thread_detach_handler
return _dispatch_thread_detach_handler
}
set(newValue) {
dispatch_thread_detach_handler = newValue
_dispatch_thread_detach_handler = newValue
}
}
#endif
Expand Down