mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Revert "Use thread_local instead of our own implementation"
Unfortunately Xcode 8 and Xcode 8.1 both produce an unstable executable.
This reverts commit 1658d6356a.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "info.h"
|
||||
#include <oak/debug.h>
|
||||
#include <oak/tls_ptr.h>
|
||||
|
||||
/* CrashReporter info */
|
||||
char const* __crashreporter_info__ = nullptr;
|
||||
@@ -58,8 +59,8 @@ namespace
|
||||
|
||||
static stack_t& stack ()
|
||||
{
|
||||
thread_local stack_t stack;
|
||||
return stack;
|
||||
static oak::tls_ptr_t<stack_t> stackPtr;
|
||||
return *stackPtr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
36
Shared/include/oak/tls_ptr.h
Normal file
36
Shared/include/oak/tls_ptr.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef TLS_PTR_H_186F0BAB
|
||||
#define TLS_PTR_H_186F0BAB
|
||||
|
||||
namespace oak
|
||||
{
|
||||
template<typename T>
|
||||
struct tls_ptr_t
|
||||
{
|
||||
tls_ptr_t () { pthread_key_create(&_key, destructor); }
|
||||
~tls_ptr_t () { }
|
||||
|
||||
tls_ptr_t (tls_ptr_t const& rhs) = delete;
|
||||
tls_ptr_t& operator= (tls_ptr_t const& rhs) = delete;
|
||||
|
||||
T& operator* () const { return *get(); }
|
||||
T* operator-> () const { return get(); }
|
||||
|
||||
private:
|
||||
T* get () const
|
||||
{
|
||||
T* valuePtr = static_cast<T*>(pthread_getspecific(_key));
|
||||
if(!valuePtr)
|
||||
{
|
||||
pthread_setspecific(_key, new T);
|
||||
valuePtr = static_cast<T*>(pthread_getspecific(_key));
|
||||
}
|
||||
return valuePtr;
|
||||
}
|
||||
|
||||
static void destructor (void* valuePtr) { delete static_cast<T*>(valuePtr); }
|
||||
|
||||
pthread_key_t _key;
|
||||
};
|
||||
} /* oak */
|
||||
|
||||
#endif /* end of include guard: TLS_PTR_H_186F0BAB */
|
||||
Reference in New Issue
Block a user