MCPcopy Create free account
hub / github.com/Snapchat/Valdi / threadDestructor

Function threadDestructor

libs/utils/src/utils/platform/JvmUtils.cpp:31–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29pthread_key_t gJniPtr;
30
31void threadDestructor([[maybe_unused]] void* prevJniPtr) {
32 // This function only runs on threads where gJniPtr is non-null, meaning
33 // we were responsible for originally attaching the thread, so are responsible
34 // for detaching it now. However, because some JVM implementations (notably
35 // Oracle's http://goo.gl/eHApYT) also use the pthread_key_create mechanism,
36 // the JVMs accounting info for this thread may already be wiped out by the
37 // time this is called. Thus it may appear we are already detached even though
38 // it was our responsibility to detach! Oh well.
39 if (getEnv() == nullptr)
40 return;
41
42 assert(getEnv() == prevJniPtr);
43 [[maybe_unused]] jint status = gJvm->DetachCurrentThread();
44 SC_ASSERT(status == JNI_OK);
45}
46} // namespace
47
48// Called when library is loaded by the first class which uses it.

Callers

nothing calls this directly

Calls 1

getEnvFunction · 0.70

Tested by

no test coverage detected