summaryrefslogtreecommitdiff
path: root/Runtime/Threads/Winapi/PlatformThreadSpecificValue.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-08-14 22:50:43 +0800
committerchai <chaifix@163.com>2019-08-14 22:50:43 +0800
commit15740faf9fe9fe4be08965098bbf2947e096aeeb (patch)
treea730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Threads/Winapi/PlatformThreadSpecificValue.h
+Unity Runtime codeHEADmaster
Diffstat (limited to 'Runtime/Threads/Winapi/PlatformThreadSpecificValue.h')
-rw-r--r--Runtime/Threads/Winapi/PlatformThreadSpecificValue.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/Runtime/Threads/Winapi/PlatformThreadSpecificValue.h b/Runtime/Threads/Winapi/PlatformThreadSpecificValue.h
new file mode 100644
index 0000000..8e6d42a
--- /dev/null
+++ b/Runtime/Threads/Winapi/PlatformThreadSpecificValue.h
@@ -0,0 +1,61 @@
+#ifndef PLATFORMTHREADSPECIFICVALUE_H
+#define PLATFORMTHREADSPECIFICVALUE_H
+
+#if UNITY_DYNAMIC_TLS
+
+#if UNITY_WINRT
+#include "PlatformDependent/MetroPlayer/Win32Threads.h"
+using win32::TlsAlloc;
+using win32::TlsFree;
+using win32::TlsGetValue;
+using win32::TlsSetValue;
+#endif
+
+class PlatformThreadSpecificValue
+{
+public:
+ PlatformThreadSpecificValue();
+ ~PlatformThreadSpecificValue();
+
+ void* GetValue() const;
+ void SetValue(void* value);
+
+private:
+ DWORD m_TLSKey;
+};
+
+inline PlatformThreadSpecificValue::PlatformThreadSpecificValue ()
+{
+ m_TLSKey = TlsAlloc();
+ AssertIf( m_TLSKey == TLS_OUT_OF_INDEXES );
+}
+
+inline PlatformThreadSpecificValue::~PlatformThreadSpecificValue ()
+{
+ TlsFree( m_TLSKey );
+}
+
+inline void* PlatformThreadSpecificValue::GetValue () const
+{
+#if UNITY_WIN
+ void* result = TlsGetValue(m_TLSKey);
+ DebugAssertIf( result == NULL && GetLastError() != ERROR_SUCCESS );
+ return result;
+#elif UNITY_XENON
+ return TlsGetValue(m_TLSKey); // on XENON TlsGetValue does not call SetLastError
+#endif
+}
+
+inline void PlatformThreadSpecificValue::SetValue (void* value)
+{
+ BOOL ok = TlsSetValue( m_TLSKey, value );
+ DebugAssertIf( !ok );
+}
+
+#else
+
+ #define UNITY_TLS_VALUE(type) __declspec(thread) type
+
+#endif // UNITY_DYNAMIC_TLS
+
+#endif // PLATFORMTHREADSPECIFICVALUE_H