Fix folly/ThreadLocal with clang after PthreadKeyUnregister change
[folly.git] / folly / detail / CacheLocality.h
index 3645c8b6a5b21aeeae87a66bb010c03aefca01f2..8731d485aafbcc6f8067bea95ae9e341ed277c3d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
 #define FOLLY_DETAIL_CACHELOCALITY_H_
 
 #include <sched.h>
+#include <algorithm>
 #include <atomic>
 #include <cassert>
 #include <functional>
@@ -25,7 +26,8 @@
 #include <string>
 #include <type_traits>
 #include <vector>
-#include "folly/Likely.h"
+#include <folly/Likely.h>
+#include <folly/Portability.h>
 
 namespace folly { namespace detail {
 
@@ -126,7 +128,7 @@ struct CacheLocality {
 
 /// An attribute that will cause a variable or field to be aligned so that
 /// it doesn't have false sharing with anything at a smaller memory address.
-#define FOLLY_ALIGN_TO_AVOID_FALSE_SHARING __attribute__((aligned(128)))
+#define FOLLY_ALIGN_TO_AVOID_FALSE_SHARING FOLLY_ALIGNED(128)
 
 /// Holds a function pointer to the VDSO implementation of getcpu(2),
 /// if available
@@ -172,8 +174,7 @@ struct SequentialThreadId {
  private:
   static Atom<size_t> prevId;
 
-  // TODO: switch to thread_local
-  static __thread size_t currentId;
+  static FOLLY_TLS size_t currentId;
 };
 
 template <template<typename> class Atom, size_t kMaxCpus>
@@ -322,6 +323,10 @@ struct AccessSpreader {
   static Getcpu::Func pickGetcpuFunc(size_t numStripes);
 };
 
+template<>
+Getcpu::Func AccessSpreader<std::atomic>::pickGetcpuFunc(size_t);
+
+
 /// An array of kMaxCpus+1 AccessSpreader<Atom> instances constructed
 /// with default params, with the zero-th element having 1 stripe
 template <template<typename> class Atom, size_t kMaxStripe>
@@ -363,4 +368,3 @@ struct AccessSpreaderArray {
 } }
 
 #endif /* FOLLY_DETAIL_CacheLocality_H_ */
-