Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 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__) |
| 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> |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 43 | #endif // ANGLE_OS_WIN |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 44 | |
| 45 | |
Nicolas Capens | cc863da | 2015-01-21 15:50:55 -0500 | [diff] [blame] | 46 | #include "debug.h" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 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) |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 55 | typedef pthread_key_t OS_TLSIndex; |
| 56 | #define OS_INVALID_TLS_INDEX (static_cast<OS_TLSIndex>(-1)) |
| 57 | #endif // ANGLE_OS_WIN |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 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 |