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 #ifdef ANGLE_PLATFORM_WINDOWS 16 # include <windows.h> 17 #endif 18 19 namespace gl 20 { 21 class Context; 22 } 23 24 #ifdef ANGLE_PLATFORM_WINDOWS 25 26 // TLS does not exist for Windows Store and needs to be emulated 27 # ifdef ANGLE_ENABLE_WINDOWS_UWP 28 # ifndef TLS_OUT_OF_INDEXES 29 # define TLS_OUT_OF_INDEXES static_cast<DWORD>(0xFFFFFFFF) 30 # endif 31 # ifndef CREATE_SUSPENDED 32 # define CREATE_SUSPENDED 0x00000004 33 # endif 34 # endif 35 typedef DWORD TLSIndex; 36 # define TLS_INVALID_INDEX (TLS_OUT_OF_INDEXES) 37 #elif defined(ANGLE_PLATFORM_POSIX) 38 # include <errno.h> 39 # include <pthread.h> 40 # include <semaphore.h> 41 typedef pthread_key_t TLSIndex; 42 # define TLS_INVALID_INDEX (static_cast<TLSIndex>(-1)) 43 #else 44 # error Unsupported platform. 45 #endif 46 47 using PthreadKeyDestructor = void (*)(void *); 48 TLSIndex CreateTLSIndex(PthreadKeyDestructor destructor); 49 bool DestroyTLSIndex(TLSIndex index); 50 51 bool SetTLSValue(TLSIndex index, void *value); 52 void *GetTLSValue(TLSIndex index); 53 54 #endif // COMMON_TLS_H_ 55