zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ossource_posix.cpp
Go to the documentation of this file.
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 //
8 // This file contains the posix specific functions
9 //
10 #include "compiler/osinclude.h"
11 
12 #if !defined(ANGLE_OS_POSIX)
13 #error Trying to build a posix specific file in a non-posix build.
14 #endif
15 
16 //
17 // Thread Local Storage Operations
18 //
19 OS_TLSIndex OS_AllocTLSIndex()
20 {
21  pthread_key_t pPoolIndex;
22 
23  //
24  // Create global pool key.
25  //
26  if ((pthread_key_create(&pPoolIndex, NULL)) != 0) {
27  assert(0 && "OS_AllocTLSIndex(): Unable to allocate Thread Local Storage");
28  return false;
29  }
30  else {
31  return pPoolIndex;
32  }
33 }
34 
35 
36 bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue)
37 {
38  if (nIndex == OS_INVALID_TLS_INDEX) {
39  assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
40  return false;
41  }
42 
43  if (pthread_setspecific(nIndex, lpvValue) == 0)
44  return true;
45  else
46  return false;
47 }
48 
49 
50 bool OS_FreeTLSIndex(OS_TLSIndex nIndex)
51 {
52  if (nIndex == OS_INVALID_TLS_INDEX) {
53  assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
54  return false;
55  }
56 
57  //
58  // Delete the global pool key.
59  //
60  if (pthread_key_delete(nIndex) == 0)
61  return true;
62  else
63  return false;
64 }
#define NULL
Definition: ftobjs.h:61
bool OS_FreeTLSIndex(OS_TLSIndex nIndex)
#define assert(x)
Definition: SDL_malloc.c:1234
bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue)
OS_TLSIndex OS_AllocTLSIndex()