Home | History | Annotate | Download | only in compiler
      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) || defined(ANDROID) || \
     20       defined(__GLIBC__) || defined(__GNU__) || \
     21       defined(__QNX__)
     22 #define ANGLE_OS_POSIX
     23 #else
     24 #error Unsupported platform.
     25 #endif
     26 
     27 #if 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_OS_WIN
     36 
     37 
     38 #include "compiler/debug.h"
     39 
     40 //
     41 // Thread Local Storage Operations
     42 //
     43 #if defined(ANGLE_OS_WIN)
     44 typedef DWORD OS_TLSIndex;
     45 #define OS_INVALID_TLS_INDEX (TLS_OUT_OF_INDEXES)
     46 #elif defined(ANGLE_OS_POSIX)
     47 typedef pthread_key_t OS_TLSIndex;
     48 #define OS_INVALID_TLS_INDEX (static_cast<OS_TLSIndex>(-1))
     49 #endif  // ANGLE_OS_WIN
     50 
     51 OS_TLSIndex OS_AllocTLSIndex();
     52 bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue);
     53 bool OS_FreeTLSIndex(OS_TLSIndex nIndex);
     54 
     55 inline void* OS_GetTLSValue(OS_TLSIndex nIndex)
     56 {
     57     ASSERT(nIndex != OS_INVALID_TLS_INDEX);
     58 #if defined(ANGLE_OS_WIN)
     59     return TlsGetValue(nIndex);
     60 #elif defined(ANGLE_OS_POSIX)
     61     return pthread_getspecific(nIndex);
     62 #endif  // ANGLE_OS_WIN
     63 }
     64 
     65 #endif // __OSINCLUDE_H
     66