24 #ifndef __IDTHREADINGPRIMITIVES__ 25 #define __IDTHREADINGPRIMITIVES__ 27 #include <boost/shared_ptr.hpp> 28 #include <boost/noncopyable.hpp> 29 #include <boost/static_assert.hpp> 30 #include <boost/mpl/or.hpp> 31 #include <boost/utility/enable_if.hpp> 32 #include <boost/type_traits.hpp> 37 #include <libkern/OSAtomic.h> 47 typedef pthread_t ThreadID;
48 #elif defined(WINDOWS) 49 typedef DWORD ThreadID;
58 typedef ThreadID ThreadDomainID;
61 extern RUNTIME_DECL
const ThreadID kInvalidThreadID;
62 extern RUNTIME_DECL
const ThreadDomainID kInvalidThreadDomainID;
69 RUNTIME_DECL ThreadID GetCurrentThreadId();
82 RUNTIME_DECL ThreadDomainID GetCurrentThreadDomainId ();
89 RUNTIME_DECL
bool IsMainThreadDomain();
94 RUNTIME_DECL uint32 GetHardwareConcurrency();
100 enum { valueSize = s };
103 template<
size_t sizeInBytes>
106 template <
typename T>
107 static T Increment(T& value);
109 template <
typename T>
110 static T Decrement(T& value);
121 typename boost::enable_if<boost::is_integral<T>, T>::type
122 AtomicIncrement(T& value)
125 BOOST_STATIC_ASSERT(
sizeof(T) == 4 ||
sizeof(T) == 8);
137 typename boost::enable_if<boost::is_integral<T>, T>::type
138 AtomicDecrement(T& value)
141 BOOST_STATIC_ASSERT(
sizeof(T) == 4 ||
sizeof(T) == 8);
142 return AtomicTraits<sizeof(T)>::Decrement(value);
150 struct AtomicTraits<4>
152 template <
typename T>
153 static inline T Increment(T& value)
155 return ::OSAtomicIncrement32Barrier((int32_t*)(&value));
158 template <
typename T>
159 static inline T Decrement(T& value)
161 return ::OSAtomicDecrement32Barrier((int32_t*)(&value));
165 #if defined(__ppc64__) || defined(__i386__) || defined(__x86_64__) || defined(__arm64__) 168 struct AtomicTraits<8>
170 template <
typename T>
171 static inline T Increment(T& value)
173 return ::OSAtomicIncrement64Barrier((int64_t*)(&value));
176 template <
typename T>
177 static inline T Decrement(T& value)
179 return ::OSAtomicDecrement64Barrier((int64_t*)(&value));
183 #endif // defined(__ppc64__) || defined(__i386__) || defined(__x86_64__) 185 #elif defined(WINDOWS) 188 struct AtomicTraits<4>
190 template <
typename T>
191 static inline T Increment(T& value)
193 return ::InterlockedIncrement(reinterpret_cast<volatile long*>(&value));
196 template <
typename T>
197 static inline T Decrement(T& value)
199 return ::InterlockedDecrement(reinterpret_cast<volatile long*>(&value));
205 struct AtomicTraits<8>
207 template <
typename T>
208 static inline T Increment(T& value)
210 return ::InterlockedIncrement64(reinterpret_cast<volatile long long*>(&value));
213 template <
typename T>
214 static inline T Decrement(T& value)
216 return ::InterlockedDecrement64(reinterpret_cast<volatile long long*>(&value));
220 #endif // defined(WINDOWS) 224 struct AtomicTraits<4>
226 template <
typename T>
227 static inline T Increment(T& value)
232 template <
typename T>
233 static inline T Decrement(T& value)
239 struct AtomicTraits<8>
241 template <
typename T>
242 static inline T Increment(T& value)
247 template <
typename T>
248 static inline T Decrement(T& value)
257 #endif // __IDTHREADINGPRIMITIVES__