Switch back to SYS_gettid, and fix
authorMichael Lee <mzlee@fb.com>
Mon, 4 Jan 2016 23:35:02 +0000 (15:35 -0800)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Tue, 5 Jan 2016 00:20:22 +0000 (16:20 -0800)
Summary:
SYS_gettid is different on Linux vs. OSX.  `__NR_gettid` is
only sometimes present and `SYS_gettid` is only sometimes present, but
we can pick one name and just follow that one.

Reviewed By: dcolascione

Differential Revision: D2800515

fb-gh-sync-id: 4245de4b9184ac4233ade9da297409c1031869a3

folly/Makefile.am
folly/experimental/fibers/Fiber.cpp
folly/portability/Syscall.h [new file with mode: 0644]

index 929676401b6126032407ec985fe567ce3a157e2f..d6a46bb8a6166593d525f1aab051dc4ea2b9cbe0 100644 (file)
@@ -247,6 +247,7 @@ nobase_follyinclude_HEADERS = \
        Padded.h \
        PicoSpinLock.h \
        Portability.h \
+       portability/Syscall.h \
        Preprocessor.h \
        ProducerConsumerQueue.h \
        Random.h \
index 9721e903f4064df5792a1af2dc73326fb464c76e..d5a8b1e9bac551d669deda7c9690d7eb2f473507 100644 (file)
@@ -27,6 +27,7 @@
 #include <folly/Portability.h>
 #include <folly/experimental/fibers/BoostContextCompatibility.h>
 #include <folly/experimental/fibers/FiberManager.h>
+#include <folly/portability/Syscall.h>
 
 namespace folly { namespace fibers {
 
@@ -38,7 +39,7 @@ pid_t localThreadId() {
   // OSX doesn't support thread_local.
   static FOLLY_TLS pid_t threadId = 0;
   if (UNLIKELY(threadId == 0)) {
-    threadId = syscall(__NR_gettid);
+    threadId = syscall(FOLLY_SYS_gettid);
   }
   return threadId;
 }
diff --git a/folly/portability/Syscall.h b/folly/portability/Syscall.h
new file mode 100644 (file)
index 0000000..05fae6e
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2016 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FOLLY_SYSCALL_H_
+#define FOLLY_SYSCALL_H_
+
+#include <sys/syscall.h>
+
+#if defined(__APPLE__)
+#define FOLLY_SYS_gettid SYS_thread_selfid
+#elif defined(SYS_gettid)
+#define FOLLY_SYS_gettid SYS_gettid
+#else
+#define FOLLY_SYS_gettid __NR_gettid
+#endif
+
+#endif