2 // Copyright (c) 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.
7 // tls.h: Simple cross-platform interface for thread local storage.
12 #include "common/platform.h"
14 #ifdef ANGLE_PLATFORM_WINDOWS
16 // TLS does not exist for Windows Store and needs to be emulated
17 # ifdef ANGLE_ENABLE_WINDOWS_STORE
18 # define TLS_OUT_OF_INDEXES -1
19 # ifndef CREATE_SUSPENDED
20 # define CREATE_SUSPENDED 0x00000004
23 typedef DWORD TLSIndex;
24 # define TLS_INVALID_INDEX (TLS_OUT_OF_INDEXES)
25 #elif defined(ANGLE_PLATFORM_POSIX)
27 # include <semaphore.h>
29 typedef pthread_key_t TLSIndex;
30 # define TLS_INVALID_INDEX (static_cast<TLSIndex>(-1))
32 # error Unsupported platform.
35 // TODO(kbr): for POSIX platforms this will have to be changed to take
36 // in a destructor function pointer, to allow the thread-local storage
37 // to be properly deallocated upon thread exit.
38 TLSIndex CreateTLSIndex();
39 bool DestroyTLSIndex(TLSIndex index);
41 bool SetTLSValue(TLSIndex index, void *value);
42 void *GetTLSValue(TLSIndex index);
44 #endif // COMMON_TLS_H_