Fix one missing conditional for Android
authorSean Cannella <seanc@fb.com>
Thu, 16 Oct 2014 19:16:41 +0000 (12:16 -0700)
committerdcsommer <dcsommer@fb.com>
Fri, 17 Oct 2014 18:45:21 +0000 (11:45 -0700)
Summary:
pthread_atfork isn't defined in the Android NDK (and therefore is not actually supported even though it's in bionic/libc) so don't call it there.

Test Plan: compiled on Linux, Android

Reviewed By: meyering@fb.com

Subscribers: njormrod, shikong, kmdent, fma

FB internal diff: D1620584

Tasks: 5183325

folly/detail/ThreadLocalDetail.h

index 55985ad3fb6715528e8a251fdc4d822178a377b2..efaadc57d77fb379fe180b35334cf8ea393a38fb 100644 (file)
@@ -193,10 +193,15 @@ struct StaticMeta {
     int ret = pthread_key_create(&pthreadKey_, &onThreadExit);
     checkPosixError(ret, "pthread_key_create failed");
 
+    // pthread_atfork is not part of the Android NDK at least as of n9d. If
+    // something is trying to call native fork() directly at all with Android's
+    // process management model, this is probably the least of the problems.
+#if !__ANDROID__
     ret = pthread_atfork(/*prepare*/ &StaticMeta::preFork,
                          /*parent*/ &StaticMeta::onForkParent,
                          /*child*/ &StaticMeta::onForkChild);
     checkPosixError(ret, "pthread_atfork failed");
+#endif
   }
   ~StaticMeta() {
     LOG(FATAL) << "StaticMeta lives forever!";