summaryrefslogtreecommitdiff
path: root/Runtime/Threads/ThreadSpecificValue.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/ThreadSpecificValue.h
+Unity Runtime codeHEADmaster
Diffstat (limited to 'Runtime/Threads/ThreadSpecificValue.h')
-rw-r--r--Runtime/Threads/ThreadSpecificValue.h108
1 files changed, 108 insertions, 0 deletions
diff --git a/Runtime/Threads/ThreadSpecificValue.h b/Runtime/Threads/ThreadSpecificValue.h
new file mode 100644
index 0000000..cf1cba8
--- /dev/null
+++ b/Runtime/Threads/ThreadSpecificValue.h
@@ -0,0 +1,108 @@
+#ifndef THREADSPECIFICVALUE_H
+#define THREADSPECIFICVALUE_H
+
+#include "Configuration/UnityConfigure.h"
+
+#if !SUPPORT_THREADS
+ class PlatformThreadSpecificValue
+ {
+ public:
+ PlatformThreadSpecificValue();
+ ~PlatformThreadSpecificValue();
+
+ void* GetValue() const;
+ void SetValue(void* value);
+
+ private:
+ void* m_Value;
+ };
+
+ inline PlatformThreadSpecificValue::PlatformThreadSpecificValue()
+ {
+ m_Value = 0;
+ }
+
+ inline PlatformThreadSpecificValue::~PlatformThreadSpecificValue()
+ {
+ //do nothing
+ }
+
+ inline void* PlatformThreadSpecificValue::GetValue() const
+ {
+ return m_Value;
+ }
+
+ inline void PlatformThreadSpecificValue::SetValue(void* value)
+ {
+ m_Value = value;
+ }
+#elif UNITY_WIN || UNITY_XENON
+# include "Winapi/PlatformThreadSpecificValue.h"
+#elif UNITY_OSX || UNITY_IPHONE || UNITY_ANDROID || UNITY_PEPPER || UNITY_LINUX || UNITY_BB10 || UNITY_TIZEN
+# include "Posix/PlatformThreadSpecificValue.h"
+#else
+# include "PlatformThreadSpecificValue.h"
+#endif
+
+#if UNITY_DYNAMIC_TLS
+
+template<class T> class ThreadSpecificValue
+{
+ PlatformThreadSpecificValue m_TLSKey;
+
+public:
+ inline operator T () const
+ {
+ return (T)GetValue ();
+ }
+
+ inline T operator -> () const
+ {
+ return (T)GetValue ();
+ }
+
+ inline T operator ++ ()
+ {
+ *this = *this + 1;
+ return *this;
+ }
+
+ inline T operator -- ()
+ {
+ *this = *this - 1;
+ return *this;
+ }
+
+ inline T operator = (T value)
+ {
+ SetValue((void*)value);
+ return value;
+ }
+
+private:
+
+ void* GetValue() const;
+ void SetValue(void* value);
+};
+
+template<class T> void* ThreadSpecificValue<T>::GetValue () const
+{
+ return m_TLSKey.GetValue();
+}
+
+template <class T> void ThreadSpecificValue<T>::SetValue (void* value)
+{
+ m_TLSKey.SetValue(value);
+}
+
+#define UNITY_TLS_VALUE(type) ThreadSpecificValue<type>
+
+#else
+
+# ifndef UNITY_TLS_VALUE
+# error "A static TLS mechanism is not defined for this platform"
+# endif
+
+#endif // UNITY_DYNAMIC_TLS
+
+#endif