Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / gpu / command_buffer / common / thread_local.h
blobbc9ff66b528bc08bd570621837d683688ecbf8b6
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.
5 // Functions for allocating and accessing thread local values via key.
7 #ifndef GPU_COMMAND_BUFFER_COMMON_THREAD_LOCAL_H_
8 #define GPU_COMMAND_BUFFER_COMMON_THREAD_LOCAL_H_
10 #if defined(_WIN32)
11 #include <windows.h>
12 #else
13 #include <pthread.h>
14 #endif
16 namespace gpu {
18 #if defined(_WIN32)
19 typedef DWORD ThreadLocalKey;
20 #else
21 typedef pthread_key_t ThreadLocalKey;
22 #endif
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
34 inline void ThreadLocalFree(ThreadLocalKey key) {
35 #if defined(_WIN32)
36 TlsFree(key);
37 #else
38 pthread_key_delete(key);
39 #endif
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
50 inline void* ThreadLocalGetValue(ThreadLocalKey key) {
51 #if defined(_WIN32)
52 return TlsGetValue(key);
53 #else
54 return pthread_getspecific(key);
55 #endif
57 } // namespace gpu
59 #endif // GPU_COMMAND_BUFFER_COMMON_THREAD_LOCAL_H_