Branimir Karadžić 7 years ago
parent
commit
cbd6d16338
4 changed files with 112 additions and 28 deletions
  1. 0 1
      include/bx/config.h
  2. 31 9
      src/mutex.cpp
  3. 29 6
      src/semaphore.cpp
  4. 52 12
      src/thread.cpp

+ 0 - 1
include/bx/config.h

@@ -15,7 +15,6 @@
 #ifndef BX_CONFIG_SUPPORTS_THREADING
 #	define BX_CONFIG_SUPPORTS_THREADING !(0 \
 			|| BX_PLATFORM_EMSCRIPTEN       \
-			|| BX_CRT_NONE                  \
 			)
 #endif // BX_CONFIG_SUPPORTS_THREADING
 

+ 31 - 9
src/mutex.cpp

@@ -8,7 +8,8 @@
 
 #if BX_CONFIG_SUPPORTS_THREADING
 
-#if    BX_PLATFORM_ANDROID \
+#if BX_CRT_NONE
+#elif  BX_PLATFORM_ANDROID \
 	|| BX_PLATFORM_LINUX   \
 	|| BX_PLATFORM_IOS     \
 	|| BX_PLATFORM_OSX     \
@@ -24,7 +25,27 @@
 
 namespace bx
 {
-#if    BX_PLATFORM_WINDOWS \
+#if BX_CRT_NONE
+	Mutex::Mutex()
+	{
+		BX_STATIC_ASSERT(sizeof(pthread_mutex_t) <= sizeof(m_internal) );
+	}
+
+	Mutex::~Mutex()
+	{
+	}
+
+	void Mutex::lock()
+	{
+	}
+
+	void Mutex::unlock()
+	{
+	}
+
+#else
+
+#	if BX_PLATFORM_WINDOWS \
 	|| BX_PLATFORM_XBOXONE \
 	|| BX_PLATFORM_WINRT
 	typedef CRITICAL_SECTION pthread_mutex_t;
@@ -49,11 +70,11 @@ namespace bx
 
 	inline int pthread_mutex_init(pthread_mutex_t* _mutex, pthread_mutexattr_t* /*_attr*/)
 	{
-#if BX_PLATFORM_WINRT
+#		if BX_PLATFORM_WINRT
 		InitializeCriticalSectionEx(_mutex, 4000, 0);   // docs recommend 4000 spincount as sane default
-#else
+#		else
 		InitializeCriticalSection(_mutex);
-#endif // BX_PLATFORM_
+#		endif // BX_PLATFORM_
 		return 0;
 	}
 
@@ -62,7 +83,7 @@ namespace bx
 		DeleteCriticalSection(_mutex);
 		return 0;
 	}
-#endif // BX_PLATFORM_
+#	endif // BX_PLATFORM_
 
 	Mutex::Mutex()
 	{
@@ -70,13 +91,13 @@ namespace bx
 
 		pthread_mutexattr_t attr;
 
-#if    BX_PLATFORM_WINDOWS \
+#	if BX_PLATFORM_WINDOWS \
 	|| BX_PLATFORM_XBOXONE \
 	|| BX_PLATFORM_WINRT
-#else
+#	else
 		pthread_mutexattr_init(&attr);
 		pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-#endif // BX_PLATFORM_
+#	endif // BX_PLATFORM_
 
 		pthread_mutex_t* handle = (pthread_mutex_t*)m_internal;
 		pthread_mutex_init(handle, &attr);
@@ -99,6 +120,7 @@ namespace bx
 		pthread_mutex_t* handle = (pthread_mutex_t*)m_internal;
 		pthread_mutex_unlock(handle);
 	}
+#endif // BX_CRT_NONE
 
 } // namespace bx
 

+ 29 - 6
src/semaphore.cpp

@@ -8,8 +8,9 @@
 
 #if BX_CONFIG_SUPPORTS_THREADING
 
-#if BX_PLATFORM_OSX \
-||  BX_PLATFORM_IOS
+#if BX_CRT_NONE
+#elif  BX_PLATFORM_OSX \
+	|| BX_PLATFORM_IOS
 #	include <dispatch/dispatch.h>
 #elif BX_PLATFORM_POSIX
 #	include <errno.h>
@@ -30,8 +31,10 @@ namespace bx
 {
 	struct SemaphoreInternal
 	{
-#if BX_PLATFORM_OSX \
-||  BX_PLATFORM_IOS
+#if BX_CRT_NONE
+
+#elif  BX_PLATFORM_OSX \
+	|| BX_PLATFORM_IOS
 		dispatch_semaphore_t m_handle;
 #elif BX_PLATFORM_POSIX
 		pthread_mutex_t m_mutex;
@@ -44,8 +47,28 @@ namespace bx
 #endif // BX_PLATFORM_
 	};
 
-#if BX_PLATFORM_OSX \
-||  BX_PLATFORM_IOS
+#if BX_CRT_NONE
+	Semaphore::Semaphore()
+	{
+		BX_STATIC_ASSERT(sizeof(SemaphoreInternal) <= sizeof(m_internal) );
+	}
+
+	Semaphore::~Semaphore()
+	{
+	}
+
+	void Semaphore::post(uint32_t _count)
+	{
+		BX_UNUSED(_count);
+	}
+
+	bool Semaphore::wait(int32_t _msecs)
+	{
+		BX_UNUSED(_msecs);
+		return false;
+	}
+#elif  BX_PLATFORM_OSX \
+	|| BX_PLATFORM_IOS
 
 	Semaphore::Semaphore()
 	{

+ 52 - 12
src/thread.cpp

@@ -6,7 +6,10 @@
 #include "bx_p.h"
 #include <bx/thread.h>
 
-#if    BX_PLATFORM_ANDROID \
+#if BX_CONFIG_SUPPORTS_THREADING
+
+#if BX_CRT_NONE
+#elif  BX_PLATFORM_ANDROID \
 	|| BX_PLATFORM_LINUX   \
 	|| BX_PLATFORM_IOS     \
 	|| BX_PLATFORM_OSX     \
@@ -32,8 +35,6 @@ using namespace Windows::System::Threading;
 #	endif // BX_PLATFORM_WINRT
 #endif // BX_PLATFORM_
 
-#if BX_CONFIG_SUPPORTS_THREADING
-
 namespace bx
 {
 	static AllocatorI* getAllocator()
@@ -44,7 +45,9 @@ namespace bx
 
 	struct ThreadInternal
 	{
-#if    BX_PLATFORM_WINDOWS \
+#if BX_CRT_NONE
+		static void* threadFunc(void* _arg);
+#elif  BX_PLATFORM_WINDOWS \
 	|| BX_PLATFORM_WINRT   \
 	|| BX_PLATFORM_XBOXONE
 		static DWORD WINAPI threadFunc(LPVOID _arg);
@@ -90,7 +93,9 @@ namespace bx
 		BX_STATIC_ASSERT(sizeof(ThreadInternal) <= sizeof(m_internal) );
 
 		ThreadInternal* ti = (ThreadInternal*)m_internal;
-#if    BX_PLATFORM_WINDOWS \
+#if BX_CRT_NONE
+		BX_UNUSED(ti);
+#elif  BX_PLATFORM_WINDOWS \
 	|| BX_PLATFORM_WINRT   \
 	|| BX_PLATFORM_XBOXONE
 		ti->m_handle   = INVALID_HANDLE_VALUE;
@@ -118,7 +123,9 @@ namespace bx
 		m_running = true;
 
 		ThreadInternal* ti = (ThreadInternal*)m_internal;
-#if    BX_PLATFORM_WINDOWS \
+#if BX_CRT_NONE
+		BX_UNUSED(ti);
+#elif  BX_PLATFORM_WINDOWS \
 	|| BX_PLATFORM_XBOXONE
 		ti->m_handle = ::CreateThread(NULL
 				, m_stackSize
@@ -170,7 +177,9 @@ namespace bx
 	{
 		BX_CHECK(m_running, "Not running!");
 		ThreadInternal* ti = (ThreadInternal*)m_internal;
-#if BX_PLATFORM_WINDOWS
+#if BX_CRT_NONE
+		BX_UNUSED(ti);
+#elif BX_PLATFORM_WINDOWS
 		WaitForSingleObject(ti->m_handle, INFINITE);
 		GetExitCodeThread(ti->m_handle, (DWORD*)&m_exitCode);
 		CloseHandle(ti->m_handle);
@@ -207,18 +216,21 @@ namespace bx
 	{
 		ThreadInternal* ti = (ThreadInternal*)m_internal;
 		BX_UNUSED(ti);
-#if BX_PLATFORM_OSX || BX_PLATFORM_IOS
+#if BX_CRT_NONE
+		BX_UNUSED(_name);
+#elif  BX_PLATFORM_OSX \
+	|| BX_PLATFORM_IOS
 		pthread_setname_np(_name);
 #elif (BX_CRT_GLIBC >= 21200) && ! BX_PLATFORM_HURD
 		pthread_setname_np(ti->m_handle, _name);
 #elif BX_PLATFORM_LINUX
 		prctl(PR_SET_NAME,_name, 0, 0, 0);
 #elif BX_PLATFORM_BSD
-#	ifdef __NetBSD__
+#	if defined(__NetBSD__)
 		pthread_setname_np(ti->m_handle, "%s", (void*)_name);
 #	else
 		pthread_set_name_np(ti->m_handle, _name);
-#	endif // __NetBSD__
+#	endif // defined(__NetBSD__)
 #elif BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC
 #	pragma pack(push, 8)
 		struct ThreadName
@@ -276,14 +288,42 @@ namespace bx
 
 	struct TlsDataInternal
 	{
-#if BX_PLATFORM_WINDOWS
+#if BX_CRT_NONE
+#elif BX_PLATFORM_WINDOWS
 		uint32_t m_id;
 #elif !(BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT)
 		pthread_key_t m_id;
 #endif // BX_PLATFORM_*
 	};
 
-#if BX_PLATFORM_WINDOWS
+#if BX_CRT_NONE
+	TlsData::TlsData()
+	{
+		BX_STATIC_ASSERT(sizeof(TlsDataInternal) <= sizeof(m_internal) );
+
+		TlsDataInternal* ti = (TlsDataInternal*)m_internal;
+		BX_UNUSED(ti);
+	}
+
+	TlsData::~TlsData()
+	{
+		TlsDataInternal* ti = (TlsDataInternal*)m_internal;
+		BX_UNUSED(ti);
+	}
+
+	void* TlsData::get() const
+	{
+		return NULL;
+	}
+
+	void TlsData::set(void* _ptr)
+	{
+		BX_UNUSED(_ptr);
+
+		TlsDataInternal* ti = (TlsDataInternal*)m_internal;
+		BX_UNUSED(ti);
+	}
+#elif BX_PLATFORM_WINDOWS
 	TlsData::TlsData()
 	{
 		BX_STATIC_ASSERT(sizeof(TlsDataInternal) <= sizeof(m_internal) );