Remove pthread dependency from CacheLocality.h
authorAndrew Krieger <andrew.krieger@oculus.com>
Fri, 14 Apr 2017 05:57:20 +0000 (22:57 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 14 Apr 2017 06:08:03 +0000 (23:08 -0700)
Summary:
For getting a thread id for hashing, std::this_thread::get_id()
is just as good and also removes an unneeded pthreads dependency. This enables
using MPMCQueue on Windows without pthreads as well.

Reviewed By: Orvid, yfeldblum

Differential Revision: D4879940

fbshipit-source-id: c4fb5eea165eb450240f94904aa26a10aa394d1b

folly/detail/CacheLocality.h

index 965387b..617182d 100644 (file)
 #include <string>
 #include <type_traits>
 #include <vector>
-#include <pthread.h>
+
 #include <folly/Hash.h>
 #include <folly/Likely.h>
 #include <folly/Portability.h>
+#include <folly/ThreadId.h>
 
 namespace folly {
 namespace detail {
@@ -174,10 +175,7 @@ extern template struct SequentialThreadId<std::atomic>;
 
 struct HashingThreadId {
   static unsigned get() {
-    pthread_t pid = pthread_self();
-    uint64_t id = 0;
-    memcpy(&id, &pid, std::min(sizeof(pid), sizeof(id)));
-    return hash::twang_32from64(id);
+    return hash::twang_32from64(getCurrentThreadID());
   }
 };