OPEN-282 Use pthreads for TLS on mac
parent
a74d0d44d1
commit
5f608c0a23
|
|
@ -314,6 +314,7 @@ Cinder Roxley
|
|||
BUG-2326
|
||||
BUG-3863
|
||||
OPEN-185
|
||||
OPEN-282
|
||||
STORM-1703
|
||||
STORM-1948
|
||||
STORM-1831
|
||||
|
|
|
|||
|
|
@ -92,11 +92,9 @@ void set_thread_name( DWORD dwThreadID, const char* threadName)
|
|||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#if LL_DARWIN
|
||||
// statically allocated thread local storage not supported in Darwin executable formats
|
||||
#elif LL_WINDOWS
|
||||
#if LL_WINDOWS
|
||||
U32 __declspec(thread) sThreadID = 0;
|
||||
#elif LL_LINUX
|
||||
#else
|
||||
U32 __thread sThreadID = 0;
|
||||
#endif
|
||||
|
||||
|
|
@ -115,9 +113,7 @@ LL_COMMON_API void assert_main_thread()
|
|||
|
||||
void LLThread::registerThreadID()
|
||||
{
|
||||
#if !LL_DARWIN
|
||||
sThreadID = ++sIDIter;
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -134,9 +130,7 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap
|
|||
// for now, hard code all LLThreads to report to single master thread recorder, which is known to be running on main thread
|
||||
threadp->mRecorder = new LLTrace::ThreadRecorder(*LLTrace::get_master_thread_recorder());
|
||||
|
||||
#if !LL_DARWIN
|
||||
sThreadID = threadp->mID;
|
||||
#endif
|
||||
|
||||
// Run the user supplied function
|
||||
threadp->run();
|
||||
|
|
@ -347,13 +341,7 @@ void LLThread::setQuitting()
|
|||
// static
|
||||
U32 LLThread::currentID()
|
||||
{
|
||||
#if LL_DARWIN
|
||||
// statically allocated thread local storage not supported in Darwin executable formats
|
||||
return (U32)apr_os_thread_current();
|
||||
#else
|
||||
return sThreadID;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
|||
|
|
@ -130,56 +130,29 @@ class LLThreadLocalSingletonPointer
|
|||
public:
|
||||
LL_FORCE_INLINE static DERIVED_TYPE* getInstance()
|
||||
{
|
||||
#if LL_DARWIN
|
||||
createTLSKey();
|
||||
return (DERIVED_TYPE*)pthread_getspecific(sInstanceKey);
|
||||
#else
|
||||
return sInstance;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void setInstance(DERIVED_TYPE* instance)
|
||||
{
|
||||
#if LL_DARWIN
|
||||
createTLSKey();
|
||||
pthread_setspecific(sInstanceKey, (void*)instance);
|
||||
#else
|
||||
sInstance = instance;
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
#if LL_WINDOWS
|
||||
static __declspec(thread) DERIVED_TYPE* sInstance;
|
||||
#elif LL_LINUX
|
||||
#else
|
||||
static __thread DERIVED_TYPE* sInstance;
|
||||
#elif LL_DARWIN
|
||||
static void TLSError()
|
||||
{
|
||||
LL_ERRS() << "Could not create thread local storage" << LL_ENDL;
|
||||
}
|
||||
static void createTLSKey()
|
||||
{
|
||||
static S32 key_created = pthread_key_create(&sInstanceKey, NULL);
|
||||
if (key_created != 0)
|
||||
{
|
||||
LL_ERRS() << "Could not create thread local storage" << LL_ENDL;
|
||||
}
|
||||
}
|
||||
static pthread_key_t sInstanceKey;
|
||||
#endif
|
||||
};
|
||||
|
||||
#if LL_WINDOWS
|
||||
template<typename DERIVED_TYPE>
|
||||
__declspec(thread) DERIVED_TYPE* LLThreadLocalSingletonPointer<DERIVED_TYPE>::sInstance = NULL;
|
||||
#elif LL_LINUX
|
||||
#else
|
||||
template<typename DERIVED_TYPE>
|
||||
__thread DERIVED_TYPE* LLThreadLocalSingletonPointer<DERIVED_TYPE>::sInstance = NULL;
|
||||
#elif LL_DARWIN
|
||||
template<typename DERIVED_TYPE>
|
||||
pthread_key_t LLThreadLocalSingletonPointer<DERIVED_TYPE>::sInstanceKey;
|
||||
#endif
|
||||
|
||||
#endif // LL_LLTHREADLOCALSTORAGE_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue