• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2014 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // tls.h: Simple cross-platform interface for thread local storage.
8 
9 #ifndef COMMON_TLS_H_
10 #define COMMON_TLS_H_
11 
12 #include "common/platform.h"
13 
14 #ifdef ANGLE_PLATFORM_WINDOWS
15 
16 // TLS does not exist for Windows Store and needs to be emulated
17 #    ifdef ANGLE_ENABLE_WINDOWS_UWP
18 #        ifndef TLS_OUT_OF_INDEXES
19 #            define TLS_OUT_OF_INDEXES static_cast<DWORD>(0xFFFFFFFF)
20 #        endif
21 #        ifndef CREATE_SUSPENDED
22 #            define CREATE_SUSPENDED 0x00000004
23 #        endif
24 #    endif
25 typedef DWORD TLSIndex;
26 #    define TLS_INVALID_INDEX (TLS_OUT_OF_INDEXES)
27 #elif defined(ANGLE_PLATFORM_POSIX)
28 #    include <errno.h>
29 #    include <pthread.h>
30 #    include <semaphore.h>
31 typedef pthread_key_t TLSIndex;
32 #    define TLS_INVALID_INDEX (static_cast<TLSIndex>(-1))
33 #else
34 #    error Unsupported platform.
35 #endif
36 
37 // TODO(kbr): for POSIX platforms this will have to be changed to take
38 // in a destructor function pointer, to allow the thread-local storage
39 // to be properly deallocated upon thread exit.
40 TLSIndex CreateTLSIndex();
41 bool DestroyTLSIndex(TLSIndex index);
42 
43 bool SetTLSValue(TLSIndex index, void *value);
44 void *GetTLSValue(TLSIndex index);
45 
46 #endif  // COMMON_TLS_H_
47