Commit fafd033e by alokp@chromium.org

Added NSPR support for thread-local storage. Patch submitted by vladimirv. I…

Added NSPR support for thread-local storage. Patch submitted by vladimirv. I have slightly modified the patch to still define ANGLE_OS_WIN and ANGLE_OS_POSIX. BUG=54 Review URL: http://codereview.appspot.com/2497041 git-svn-id: https://angleproject.googlecode.com/svn/trunk@454 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent d300f5b0
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#define __OSINCLUDE_H #define __OSINCLUDE_H
// //
// This file contains contains the window's specific datatypes and // This file contains contains os-specific datatypes and
// declares any windows specific functions. // declares any os-specific functions.
// //
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
#error Unsupported platform. #error Unsupported platform.
#endif #endif
#if defined(ANGLE_OS_WIN) #if defined(ANGLE_USE_NSPR)
#include "prthread.h"
#elif defined(ANGLE_OS_WIN)
#define STRICT #define STRICT
#define VC_EXTRALEAN 1 #define VC_EXTRALEAN 1
#include <windows.h> #include <windows.h>
...@@ -30,20 +32,24 @@ ...@@ -30,20 +32,24 @@
#include <pthread.h> #include <pthread.h>
#include <semaphore.h> #include <semaphore.h>
#include <errno.h> #include <errno.h>
#endif // ANGLE_OS_WIN #endif // ANGLE_USE_NSPR
#include "compiler/debug.h" #include "compiler/debug.h"
// //
// Thread Local Storage Operations // Thread Local Storage Operations
// //
#if defined(ANGLE_OS_WIN) #if defined(ANGLE_USE_NSPR)
typedef PRUintn OS_TLSIndex;
#define OS_INVALID_TLS_INDEX 0xFFFFFFFF
#elif defined(ANGLE_OS_WIN)
typedef DWORD OS_TLSIndex; typedef DWORD OS_TLSIndex;
#define OS_INVALID_TLS_INDEX (TLS_OUT_OF_INDEXES) #define OS_INVALID_TLS_INDEX (TLS_OUT_OF_INDEXES)
#elif defined(ANGLE_OS_POSIX) #elif defined(ANGLE_OS_POSIX)
typedef unsigned int OS_TLSIndex; typedef unsigned int OS_TLSIndex;
#define OS_INVALID_TLS_INDEX 0xFFFFFFFF #define OS_INVALID_TLS_INDEX 0xFFFFFFFF
#endif // ANGLE_OS_WIN #endif // ANGLE_USE_NSPR
OS_TLSIndex OS_AllocTLSIndex(); OS_TLSIndex OS_AllocTLSIndex();
bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue); bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue);
...@@ -51,8 +57,10 @@ bool OS_FreeTLSIndex(OS_TLSIndex nIndex); ...@@ -51,8 +57,10 @@ bool OS_FreeTLSIndex(OS_TLSIndex nIndex);
inline void* OS_GetTLSValue(OS_TLSIndex nIndex) inline void* OS_GetTLSValue(OS_TLSIndex nIndex)
{ {
assert(nIndex != OS_INVALID_TLS_INDEX); ASSERT(nIndex != OS_INVALID_TLS_INDEX);
#if defined(ANGLE_OS_WIN) #if defined(ANGLE_USE_NSPR)
return PR_GetThreadPrivate(nIndex);
#elif defined(ANGLE_OS_WIN)
return TlsGetValue(nIndex); return TlsGetValue(nIndex);
#elif defined(ANGLE_OS_POSIX) #elif defined(ANGLE_OS_POSIX)
return pthread_getspecific(nIndex); return pthread_getspecific(nIndex);
......
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
//
// This file contains the nspr specific functions
//
#include "compiler/osinclude.h"
//
// Thread Local Storage Operations
//
OS_TLSIndex OS_AllocTLSIndex()
{
PRUintn index;
PRStatus status = PR_NewThreadPrivateIndex(&index, NULL);
if (status) {
assert(0 && "OS_AllocTLSIndex(): Unable to allocate Thread Local Storage");
return OS_INVALID_TLS_INDEX;
}
return index;
}
bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue)
{
if (nIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
return false;
}
return PR_SetThreadPrivate(nIndex, lpvValue) == 0;
}
bool OS_FreeTLSIndex(OS_TLSIndex nIndex)
{
// Can't delete TLS keys with nspr
return true;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment