Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -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 | 8940182 | 2014-05-06 15:04:28 -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 | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 14 | |
| 15 | // |
| 16 | // This file contains the posix specific functions |
| 17 | // |
Nicolas Capens | cc863da | 2015-01-21 15:50:55 -0500 | [diff] [blame] | 18 | #include "osinclude.h" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 19 | |
| 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 | // |
| 27 | OS_TLSIndex OS_AllocTLSIndex() |
| 28 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 29 | pthread_key_t pPoolIndex; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 30 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 31 | // |
| 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 Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | |
| 44 | bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue) |
| 45 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 46 | if (nIndex == OS_INVALID_TLS_INDEX) { |
| 47 | assert(0 && "OS_SetTLSValue(): Invalid TLS Index"); |
| 48 | return false; |
| 49 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 50 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 51 | if (pthread_setspecific(nIndex, lpvValue) == 0) |
| 52 | return true; |
| 53 | else |
| 54 | return false; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | |
| 58 | bool OS_FreeTLSIndex(OS_TLSIndex nIndex) |
| 59 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 60 | if (nIndex == OS_INVALID_TLS_INDEX) { |
| 61 | assert(0 && "OS_SetTLSValue(): Invalid TLS Index"); |
| 62 | return false; |
| 63 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 64 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 65 | // |
| 66 | // Delete the global pool key. |
| 67 | // |
| 68 | if (pthread_key_delete(nIndex) == 0) |
| 69 | return true; |
| 70 | else |
| 71 | return false; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 72 | } |