• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2002-2010 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 #ifndef __OSINCLUDE_H
8 #define __OSINCLUDE_H
9 
10 //
11 // This file contains contains os-specific datatypes and
12 // declares any os-specific functions.
13 //
14 
15 #if defined(_WIN32) || defined(_WIN64)
16 #define ANGLE_OS_WIN
17 #elif defined(__APPLE__) || defined(__linux__) || \
18       defined(__FreeBSD__) || defined(__OpenBSD__) || \
19       defined(__sun)
20 #define ANGLE_OS_POSIX
21 #else
22 #error Unsupported platform.
23 #endif
24 
25 #if defined(ANGLE_USE_NSPR)
26 #include "prthread.h"
27 #elif defined(ANGLE_OS_WIN)
28 #define STRICT
29 #define VC_EXTRALEAN 1
30 #include <windows.h>
31 #elif defined(ANGLE_OS_POSIX)
32 #include <pthread.h>
33 #include <semaphore.h>
34 #include <errno.h>
35 #endif  // ANGLE_USE_NSPR
36 
37 
38 #include "compiler/debug.h"
39 
40 //
41 // Thread Local Storage Operations
42 //
43 #if defined(ANGLE_USE_NSPR)
44 typedef PRUintn OS_TLSIndex;
45 #define OS_INVALID_TLS_INDEX 0xFFFFFFFF
46 #elif defined(ANGLE_OS_WIN)
47 typedef DWORD OS_TLSIndex;
48 #define OS_INVALID_TLS_INDEX (TLS_OUT_OF_INDEXES)
49 #elif defined(ANGLE_OS_POSIX)
50 typedef unsigned int OS_TLSIndex;
51 #define OS_INVALID_TLS_INDEX 0xFFFFFFFF
52 #endif  // ANGLE_USE_NSPR
53 
54 OS_TLSIndex OS_AllocTLSIndex();
55 bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue);
56 bool OS_FreeTLSIndex(OS_TLSIndex nIndex);
57 
OS_GetTLSValue(OS_TLSIndex nIndex)58 inline void* OS_GetTLSValue(OS_TLSIndex nIndex)
59 {
60     ASSERT(nIndex != OS_INVALID_TLS_INDEX);
61 #if defined(ANGLE_USE_NSPR)
62     return PR_GetThreadPrivate(nIndex);
63 #elif defined(ANGLE_OS_WIN)
64     return TlsGetValue(nIndex);
65 #elif defined(ANGLE_OS_POSIX)
66     return pthread_getspecific(nIndex);
67 #endif  // ANGLE_OS_WIN
68 }
69 
70 #endif // __OSINCLUDE_H
71