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:
Allan Odgaard
2016-11-02 23:04:37 +07:00
parent 5a5f5e8d75
commit 39ec2d008c
2 changed files with 39 additions and 2 deletions

View File

@@ -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;
}
}

View 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 */