1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Functions for allocating and accessing thread local values via key. 6 7 #ifndef GPU_COMMAND_BUFFER_COMMON_THREAD_LOCAL_H_ 8 #define GPU_COMMAND_BUFFER_COMMON_THREAD_LOCAL_H_ 9 10 #if defined(_WIN32) 11 #include <windows.h> 12 #else 13 #include <pthread.h> 14 #endif 15 16 namespace gpu { 17 18 #if defined(_WIN32) 19 typedef DWORD ThreadLocalKey; 20 #else 21 typedef pthread_key_t ThreadLocalKey; 22 #endif 23 24 inline ThreadLocalKey ThreadLocalAlloc() { 25 #if defined(_WIN32) 26 return TlsAlloc(); 27 #else 28 ThreadLocalKey key; 29 pthread_key_create(&key, NULL); 30 return key; 31 #endif 32 } 33 34 inline void ThreadLocalFree(ThreadLocalKey key) { 35 #if defined(_WIN32) 36 TlsFree(key); 37 #else 38 pthread_key_delete(key); 39 #endif 40 } 41 42 inline void ThreadLocalSetValue(ThreadLocalKey key, void* value) { 43 #if defined(_WIN32) 44 TlsSetValue(key, value); 45 #else 46 pthread_setspecific(key, value); 47 #endif 48 } 49 50 inline void* ThreadLocalGetValue(ThreadLocalKey key) { 51 #if defined(_WIN32) 52 return TlsGetValue(key); 53 #else 54 return pthread_getspecific(key); 55 #endif 56 } 57 } // namespace gpu 58 59 #endif // GPU_COMMAND_BUFFER_COMMON_THREAD_LOCAL_H_ 60