1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | #ifndef __OSINCLUDE_H |
16 | #define __OSINCLUDE_H |
17 | |
18 | // |
19 | // This file contains contains os-specific datatypes and |
20 | // declares any os-specific functions. |
21 | // |
22 | |
23 | #if defined(_WIN32) || defined(_WIN64) |
24 | #define ANGLE_OS_WIN |
25 | #elif defined(__APPLE__) || defined(__linux__) || \ |
26 | defined(__FreeBSD__) || defined(__OpenBSD__) || \ |
27 | defined(__sun) || defined(ANDROID) || \ |
28 | defined(__GLIBC__) || defined(__GNU__) || \ |
29 | defined(__QNX__) || defined(__Fuchsia__) |
30 | #define ANGLE_OS_POSIX |
31 | #else |
32 | #error Unsupported platform. |
33 | #endif |
34 | |
35 | #if defined(ANGLE_OS_WIN) |
36 | #define STRICT |
37 | #define VC_EXTRALEAN 1 |
38 | #include <windows.h> |
39 | #elif defined(ANGLE_OS_POSIX) |
40 | #include <pthread.h> |
41 | #include <semaphore.h> |
42 | #include <errno.h> |
43 | #endif // ANGLE_OS_WIN |
44 | |
45 | |
46 | #include "debug.h" |
47 | |
48 | // |
49 | // Thread Local Storage Operations |
50 | // |
51 | #if defined(ANGLE_OS_WIN) |
52 | typedef DWORD OS_TLSIndex; |
53 | #define OS_INVALID_TLS_INDEX (TLS_OUT_OF_INDEXES) |
54 | #elif defined(ANGLE_OS_POSIX) |
55 | typedef pthread_key_t OS_TLSIndex; |
56 | #define OS_INVALID_TLS_INDEX (static_cast<OS_TLSIndex>(-1)) |
57 | #endif // ANGLE_OS_WIN |
58 | |
59 | OS_TLSIndex OS_AllocTLSIndex(); |
60 | bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue); |
61 | bool OS_FreeTLSIndex(OS_TLSIndex nIndex); |
62 | |
63 | inline void* OS_GetTLSValue(OS_TLSIndex nIndex) |
64 | { |
65 | ASSERT(nIndex != OS_INVALID_TLS_INDEX); |
66 | #if defined(ANGLE_OS_WIN) |
67 | return TlsGetValue(nIndex); |
68 | #elif defined(ANGLE_OS_POSIX) |
69 | return pthread_getspecific(nIndex); |
70 | #endif // ANGLE_OS_WIN |
71 | } |
72 | |
73 | #endif // __OSINCLUDE_H |
74 | |