5 #include "src/thread-id.h" 6 #include "src/base/lazy-instance.h" 7 #include "src/base/platform/platform.h" 12 base::Atomic32 ThreadId::highest_thread_id_ = 0;
16 struct LocalStorageKeyAllocator {
17 static void Construct(
void* storage_ptr_arg) {
19 reinterpret_cast<base::Thread::LocalStorageKey*
>(storage_ptr_arg);
20 *storage_ptr = base::Thread::CreateThreadLocalKey();
24 static base::LazyInstance<base::Thread::LocalStorageKey,
25 LocalStorageKeyAllocator>::type thread_id_key =
26 LAZY_INSTANCE_INITIALIZER;
31 ThreadId ThreadId::TryGetCurrent() {
32 int thread_id = base::Thread::GetThreadLocalInt(thread_id_key.Get());
33 return thread_id == 0 ? Invalid() : ThreadId(thread_id);
37 int ThreadId::GetCurrentThreadId() {
38 int thread_id = base::Thread::GetThreadLocalInt(thread_id_key.Get());
40 thread_id = AllocateThreadId();
41 base::Thread::SetThreadLocalInt(thread_id_key.Get(), thread_id);