OLD | NEW |
(Empty) | |
| 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 #include <build/build_config.h> |
| 11 |
| 12 #if defined(OS_WIN) |
| 13 #include <windows.h> |
| 14 #else |
| 15 #include <pthread.h> |
| 16 #endif |
| 17 |
| 18 namespace gpu { |
| 19 |
| 20 #if defined(OS_WIN) |
| 21 typedef DWORD ThreadLocalKey; |
| 22 #else |
| 23 typedef pthread_key_t ThreadLocalKey; |
| 24 #endif |
| 25 |
| 26 inline ThreadLocalKey ThreadLocalAlloc() { |
| 27 #if defined(OS_WIN) |
| 28 return TlsAlloc(); |
| 29 #else |
| 30 ThreadLocalKey key; |
| 31 pthread_key_create(&key, NULL); |
| 32 return key; |
| 33 #endif |
| 34 } |
| 35 |
| 36 inline void ThreadLocalFree(ThreadLocalKey key) { |
| 37 #if defined(OS_WIN) |
| 38 TlsFree(key); |
| 39 #else |
| 40 pthread_key_delete(key); |
| 41 #endif |
| 42 } |
| 43 |
| 44 inline void ThreadLocalSetValue(ThreadLocalKey key, void* value) { |
| 45 #if defined(OS_WIN) |
| 46 TlsSetValue(key, value); |
| 47 #else |
| 48 pthread_setspecific(key, value); |
| 49 #endif |
| 50 } |
| 51 |
| 52 inline void* ThreadLocalGetValue(ThreadLocalKey key) { |
| 53 #if defined(OS_WIN) |
| 54 return TlsGetValue(key); |
| 55 #else |
| 56 return pthread_getspecific(key); |
| 57 #endif |
| 58 } |
| 59 } // namespace gpu |
| 60 |
| 61 #endif // GPU_COMMAND_BUFFER_COMMON_THREAD_LOCAL_H_ |
OLD | NEW |