static LocalStorageKey CreateThreadLocalKey();
static void DeleteThreadLocalKey(LocalStorageKey key);
static void* GetThreadLocal(LocalStorageKey key);
+ static int GetThreadLocalInt(LocalStorageKey key) {
+ return static_cast<int>(reinterpret_cast<intptr_t>(GetThreadLocal(key)));
+ }
static void SetThreadLocal(LocalStorageKey key, void* value);
+ static void SetThreadLocalInt(LocalStorageKey key, int value) {
+ SetThreadLocal(key, reinterpret_cast<void*>(static_cast<intptr_t>(value)));
+ }
+ static bool HasThreadLocal(LocalStorageKey key) {
+ return GetThreadLocal(key) != NULL;
+ }
// A hint to the scheduler to let another thread run.
static void YieldCPU();
int ThreadManager::CurrentId() {
- return bit_cast<int, void*>(Thread::GetThreadLocal(thread_id_key));
+ return Thread::GetThreadLocalInt(thread_id_key);
}
void ThreadManager::AssignId() {
- if (Thread::GetThreadLocal(thread_id_key) == NULL) {
- Thread::SetThreadLocal(thread_id_key, bit_cast<void*, int>(next_id_++));
+ if (!Thread::HasThreadLocal(thread_id_key)) {
+ Thread::SetThreadLocalInt(thread_id_key, next_id_++);
}
}