• 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/angleutils.h"
13 #include "common/platform.h"
14 
15 namespace gl
16 {
17 class Context;
18 }
19 
20 #ifdef ANGLE_PLATFORM_WINDOWS
21 
22 // TLS does not exist for Windows Store and needs to be emulated
23 #    ifdef ANGLE_ENABLE_WINDOWS_UWP
24 #        ifndef TLS_OUT_OF_INDEXES
25 #            define TLS_OUT_OF_INDEXES static_cast<DWORD>(0xFFFFFFFF)
26 #        endif
27 #        ifndef CREATE_SUSPENDED
28 #            define CREATE_SUSPENDED 0x00000004
29 #        endif
30 #    endif
31 typedef DWORD TLSIndex;
32 #    define TLS_INVALID_INDEX (TLS_OUT_OF_INDEXES)
33 #elif defined(ANGLE_PLATFORM_POSIX)
34 #    include <errno.h>
35 #    include <pthread.h>
36 #    include <semaphore.h>
37 typedef pthread_key_t TLSIndex;
38 #    define TLS_INVALID_INDEX (static_cast<TLSIndex>(-1))
39 #else
40 #    error Unsupported platform.
41 #endif
42 
43 // TODO(kbr): for POSIX platforms this will have to be changed to take
44 // in a destructor function pointer, to allow the thread-local storage
45 // to be properly deallocated upon thread exit.
46 TLSIndex CreateTLSIndex();
47 bool DestroyTLSIndex(TLSIndex index);
48 
49 bool SetTLSValue(TLSIndex index, void *value);
50 void *GetTLSValue(TLSIndex index);
51 
52 #endif  // COMMON_TLS_H_
53