Use std::thread::id in Fiber rather than a syscall
authorChristopher Dykes <cdykes@fb.com>
Wed, 4 May 2016 17:27:25 +0000 (10:27 -0700)
committerFacebook Github Bot 0 <facebook-github-bot-0-bot@fb.com>
Wed, 4 May 2016 17:35:42 +0000 (10:35 -0700)
Summary: syscall() doesn't exist on Windows, but std::thread::id is standardized, and can do what we need it for, so use it instead.

Reviewed By: yfeldblum

Differential Revision: D3256064

fb-gh-sync-id: efddac82c117ccd8a53c8c93248529000b4326a5
fbshipit-source-id: efddac82c117ccd8a53c8c93248529000b4326a5

folly/experimental/fibers/Fiber.cpp
folly/experimental/fibers/Fiber.h

index 67ea620dc30e2a2fdbff0afd3f789c3b1e4b2acb..54f086d1eabfdbbf5ce3f662e1f8b74cc7abc468 100644 (file)
@@ -35,14 +35,8 @@ namespace fibers {
 namespace {
 static const uint64_t kMagic8Bytes = 0xfaceb00cfaceb00c;
 
-pid_t localThreadId() {
-  // __thread doesn't allow non-const initialization.
-  // OSX doesn't support thread_local.
-  static FOLLY_TLS pid_t threadId = 0;
-  if (UNLIKELY(threadId == 0)) {
-    threadId = syscall(FOLLY_SYS_gettid);
-  }
-  return threadId;
+std::thread::id localThreadId() {
+  return std::this_thread::get_id();
 }
 
 /* Size of the region from p + nBytes down to the last non-magic value */
index efa43715b9ae3eec758f9afcab6d60690e743df8..f68df6ce22b8a0636288d86100d8085cd7bfe622 100644 (file)
@@ -184,7 +184,7 @@ class Fiber {
   folly::IntrusiveListHook listHook_; /**< list hook for different FiberManager
                                            queues */
   folly::IntrusiveListHook globalListHook_; /**< list hook for global list */
-  pid_t threadId_{0};
+  std::thread::id threadId_{};
 };
 }
 }