From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001
From: chai <chaifix@163.com>
Date: Wed, 14 Aug 2019 22:50:43 +0800
Subject: +Unity Runtime code

---
 Runtime/Threads/ThreadSpecificValue.h | 108 ++++++++++++++++++++++++++++++++++
 1 file changed, 108 insertions(+)
 create mode 100644 Runtime/Threads/ThreadSpecificValue.h

(limited to 'Runtime/Threads/ThreadSpecificValue.h')

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
-- 
cgit v1.1-26-g67d0