blob: 0e12fdafd7ff520b07db41ea0797187b23c19d21 [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman89401822014-05-06 15:04:28 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// 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 Bauman89401822014-05-06 15:04:28 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// 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 Bauman89401822014-05-06 15:04:28 -040014
15//
16// This file contains the posix specific functions
17//
Nicolas Capenscc863da2015-01-21 15:50:55 -050018#include "osinclude.h"
John Bauman89401822014-05-06 15:04:28 -040019
20#if !defined(ANGLE_OS_POSIX)
21#error Trying to build a posix specific file in a non-posix build.
22#endif
23
24//
25// Thread Local Storage Operations
26//
27OS_TLSIndex OS_AllocTLSIndex()
28{
Nicolas Capens0bac2852016-05-07 06:09:58 -040029 pthread_key_t pPoolIndex;
John Bauman89401822014-05-06 15:04:28 -040030
Nicolas Capens0bac2852016-05-07 06:09:58 -040031 //
32 // Create global pool key.
33 //
34 if ((pthread_key_create(&pPoolIndex, NULL)) != 0) {
35 assert(0 && "OS_AllocTLSIndex(): Unable to allocate Thread Local Storage");
36 return false;
37 }
38 else {
39 return pPoolIndex;
40 }
John Bauman89401822014-05-06 15:04:28 -040041}
42
43
44bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue)
45{
Nicolas Capens0bac2852016-05-07 06:09:58 -040046 if (nIndex == OS_INVALID_TLS_INDEX) {
47 assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
48 return false;
49 }
John Bauman89401822014-05-06 15:04:28 -040050
Nicolas Capens0bac2852016-05-07 06:09:58 -040051 if (pthread_setspecific(nIndex, lpvValue) == 0)
52 return true;
53 else
54 return false;
John Bauman89401822014-05-06 15:04:28 -040055}
56
57
58bool OS_FreeTLSIndex(OS_TLSIndex nIndex)
59{
Nicolas Capens0bac2852016-05-07 06:09:58 -040060 if (nIndex == OS_INVALID_TLS_INDEX) {
61 assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
62 return false;
63 }
John Bauman89401822014-05-06 15:04:28 -040064
Nicolas Capens0bac2852016-05-07 06:09:58 -040065 //
66 // Delete the global pool key.
67 //
68 if (pthread_key_delete(nIndex) == 0)
69 return true;
70 else
71 return false;
John Bauman89401822014-05-06 15:04:28 -040072}