From 7d3bbfee07d6216cebf403e975bea355e154e1a9 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Wed, 4 May 2016 10:27:25 -0700 Subject: [PATCH] Use std::thread::id in Fiber rather than a syscall 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 | 10 ++-------- folly/experimental/fibers/Fiber.h | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/folly/experimental/fibers/Fiber.cpp b/folly/experimental/fibers/Fiber.cpp index 67ea620d..54f086d1 100644 --- a/folly/experimental/fibers/Fiber.cpp +++ b/folly/experimental/fibers/Fiber.cpp @@ -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 */ diff --git a/folly/experimental/fibers/Fiber.h b/folly/experimental/fibers/Fiber.h index efa43715..f68df6ce 100644 --- a/folly/experimental/fibers/Fiber.h +++ b/folly/experimental/fibers/Fiber.h @@ -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_{}; }; } } -- 2.34.1