michael@0: // michael@0: // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: // michael@0: // This file contains the posix specific functions michael@0: // michael@0: #include "compiler/osinclude.h" michael@0: michael@0: #if !defined(ANGLE_OS_POSIX) michael@0: #error Trying to build a posix specific file in a non-posix build. michael@0: #endif michael@0: michael@0: // michael@0: // Thread Local Storage Operations michael@0: // michael@0: OS_TLSIndex OS_AllocTLSIndex() michael@0: { michael@0: pthread_key_t pPoolIndex; michael@0: michael@0: // michael@0: // Create global pool key. michael@0: // michael@0: if ((pthread_key_create(&pPoolIndex, NULL)) != 0) { michael@0: assert(0 && "OS_AllocTLSIndex(): Unable to allocate Thread Local Storage"); michael@0: return false; michael@0: } michael@0: else { michael@0: return pPoolIndex; michael@0: } michael@0: } michael@0: michael@0: michael@0: bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue) michael@0: { michael@0: if (nIndex == OS_INVALID_TLS_INDEX) { michael@0: assert(0 && "OS_SetTLSValue(): Invalid TLS Index"); michael@0: return false; michael@0: } michael@0: michael@0: if (pthread_setspecific(nIndex, lpvValue) == 0) michael@0: return true; michael@0: else michael@0: return false; michael@0: } michael@0: michael@0: michael@0: bool OS_FreeTLSIndex(OS_TLSIndex nIndex) michael@0: { michael@0: if (nIndex == OS_INVALID_TLS_INDEX) { michael@0: assert(0 && "OS_SetTLSValue(): Invalid TLS Index"); michael@0: return false; michael@0: } michael@0: michael@0: // michael@0: // Delete the global pool key. michael@0: // michael@0: if (pthread_key_delete(nIndex) == 0) michael@0: return true; michael@0: else michael@0: return false; michael@0: }