|
@@ -33,7 +33,12 @@
|
|
|
static JavaVM *java_vm = nullptr;
|
|
static JavaVM *java_vm = nullptr;
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
|
|
+// See comment in header file.
|
|
|
|
|
+#ifdef ANDROID
|
|
|
|
|
+static __thread Thread *_current_thread = nullptr;
|
|
|
|
|
+#else
|
|
|
__thread Thread *ThreadPosixImpl::_current_thread = nullptr;
|
|
__thread Thread *ThreadPosixImpl::_current_thread = nullptr;
|
|
|
|
|
+#endif
|
|
|
static patomic_flag _main_thread_known = ATOMIC_FLAG_INIT;
|
|
static patomic_flag _main_thread_known = ATOMIC_FLAG_INIT;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -53,6 +58,10 @@ ThreadPosixImpl::
|
|
|
_detached = true;
|
|
_detached = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (_current_thread == _parent_obj) {
|
|
|
|
|
+ _current_thread = nullptr;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
_mutex.unlock();
|
|
_mutex.unlock();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -332,7 +341,9 @@ root_func(void *data) {
|
|
|
#ifdef ANDROID
|
|
#ifdef ANDROID
|
|
|
// We cannot let the thread end without detaching it.
|
|
// We cannot let the thread end without detaching it.
|
|
|
if (self->_jni_env != nullptr) {
|
|
if (self->_jni_env != nullptr) {
|
|
|
- java_vm->DetachCurrentThread();
|
|
|
|
|
|
|
+ if (java_vm != nullptr) {
|
|
|
|
|
+ java_vm->DetachCurrentThread();
|
|
|
|
|
+ }
|
|
|
self->_jni_env = nullptr;
|
|
self->_jni_env = nullptr;
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
@@ -341,6 +352,8 @@ root_func(void *data) {
|
|
|
// might delete the parent object, and in turn, delete the ThreadPosixImpl
|
|
// might delete the parent object, and in turn, delete the ThreadPosixImpl
|
|
|
// object.
|
|
// object.
|
|
|
unref_delete(self->_parent_obj);
|
|
unref_delete(self->_parent_obj);
|
|
|
|
|
+
|
|
|
|
|
+ _current_thread = nullptr;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
return nullptr;
|
|
@@ -360,6 +373,17 @@ init_current_thread() {
|
|
|
return thread;
|
|
return thread;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#ifdef ANDROID
|
|
|
|
|
+/**
|
|
|
|
|
+ *
|
|
|
|
|
+ */
|
|
|
|
|
+Thread *ThreadPosixImpl::
|
|
|
|
|
+do_get_current_thread() {
|
|
|
|
|
+ Thread *thread = _current_thread;
|
|
|
|
|
+ return (thread != nullptr) ? thread : init_current_thread();
|
|
|
|
|
+}
|
|
|
|
|
+#endif // ANDROID
|
|
|
|
|
+
|
|
|
#ifdef ANDROID
|
|
#ifdef ANDROID
|
|
|
/**
|
|
/**
|
|
|
* Called by Java when loading this library from the Java virtual machine.
|
|
* Called by Java when loading this library from the Java virtual machine.
|