From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- .../Threads/Posix/PlatformThreadSpecificValue.h | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Runtime/Threads/Posix/PlatformThreadSpecificValue.h (limited to 'Runtime/Threads/Posix/PlatformThreadSpecificValue.h') diff --git a/Runtime/Threads/Posix/PlatformThreadSpecificValue.h b/Runtime/Threads/Posix/PlatformThreadSpecificValue.h new file mode 100644 index 0000000..7513834 --- /dev/null +++ b/Runtime/Threads/Posix/PlatformThreadSpecificValue.h @@ -0,0 +1,63 @@ +#ifndef PLATFORMTHREADSPECIFICVALUE_H +#define PLATFORMTHREADSPECIFICVALUE_H + +#if UNITY_DYNAMIC_TLS + +#include +#include "Runtime/Utilities/LogAssert.h" +#include "Runtime/Utilities/Utility.h" + +class PlatformThreadSpecificValue +{ +public: + PlatformThreadSpecificValue(); + ~PlatformThreadSpecificValue(); + + void* GetValue() const; + void SetValue(void* value); + +private: + pthread_key_t m_TLSKey; +}; + +inline PlatformThreadSpecificValue::PlatformThreadSpecificValue() +{ + int rc = pthread_key_create(&m_TLSKey, NULL); + DebugAssertIf(rc != 0); + UNUSED(rc); +} + +inline PlatformThreadSpecificValue::~PlatformThreadSpecificValue() +{ + int rc = pthread_key_delete(m_TLSKey); + DebugAssertIf(rc != 0); + UNUSED(rc); +} + +inline void* PlatformThreadSpecificValue::GetValue() const +{ +#if !UNITY_LINUX + // 0 is a valid key on Linux and POSIX specifies keys as opaque objects, + // so technically we have no business snopping in them anyway... + DebugAssertIf(m_TLSKey == 0); +#endif + return pthread_getspecific(m_TLSKey); +} + +inline void PlatformThreadSpecificValue::SetValue(void* value) +{ +#if !UNITY_LINUX + // 0 is a valid key on Linux and POSIX specifies keys as opaque objects, + // so technically we have no business snopping in them anyway... + DebugAssertIf(m_TLSKey == 0); +#endif + pthread_setspecific(m_TLSKey, value); +} + +#else + + #error "POSIX doesn't define a static TLS path" + +#endif // UNITY_DYNAMIC_TLS + +#endif // PLATFORMTHREADSPECIFICVALUE_H -- cgit v1.1-26-g67d0