Daniele Bartolini 11 лет назад
Родитель
Сommit
3cfb489438

+ 1 - 1
engine/Config.h

@@ -99,7 +99,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #define CROWN_PLATFORM_POSIX (CROWN_PLATFORM_ANDROID \
 						|| CROWN_PLATFORM_IOS \
 						|| CROWN_PLATFORM_LINUX \
-						|| CROWN_PLATFORM_OSX \
+						|| CROWN_PLATFORM_OSX)
 
 // http://sourceforge.net/apps/mediawiki/predef/index.php?title=Architectures
 #if defined(__arm__)

+ 1 - 2
engine/Crown.h

@@ -107,9 +107,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "LuaEnvironment.h"
 
 // Engine/Os
-#include "OsThread.h"
+#include "Thread.h"
 #include "Mutex.h"
-#include "ScopedMutex.h"
 #include "Cond.h"
 #include "OsFile.h"
 #include "OsWindow.h"

+ 1 - 1
engine/core/mem/Memory.cpp

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Memory.h"
 #include "Allocator.h"
-#include "ScopedMutex.h"
+#include "Mutex.h"
 
 // //-----------------------------------------------------------------------------
 // void* operator new(size_t) throw (std::bad_alloc)

+ 3 - 3
engine/core/mem/Memory.h

@@ -34,7 +34,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-CE_EXPORT Allocator& default_allocator();
+Allocator& default_allocator();
 
 /// @defgroup Memory Memory
 namespace memory
@@ -46,12 +46,12 @@ const uint32_t PADDING_VALUE = 0xFFFFFFFFu;
 /// Constructs the initial default allocators.
 /// @note
 /// Has to be called before anything else during the engine startup.
-CE_EXPORT void init();
+void init();
 
 /// Destroys the allocators created with memory::init().
 /// @note
 /// Should be the last call of the program.
-CE_EXPORT void shutdown();
+void shutdown();
 
 /// Returns the pointer @a p aligned to the desired @a align byte
 inline void* align_top(void* p, size_t align)

+ 1 - 1
engine/core/mem/ProxyAllocator.cpp

@@ -27,7 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Assert.h"
 #include "ProxyAllocator.h"
 #include "StringUtils.h"
-#include "ScopedMutex.h"
+#include "Mutex.h"
 
 namespace crown
 {

+ 18 - 2
engine/os/android/AtomicInt.h → engine/core/thread/AtomicInt.h

@@ -26,8 +26,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#ifndef __GNUG__
-	#error "Compiler not supported"
+#include "Config.h"
+
+#if CROWN_PLATFORM_WINDOWS
+	#include "Types.h"
+	#include "WinHeaders.h"
 #endif
 
 namespace crown
@@ -42,18 +45,31 @@ struct AtomicInt
 
 	int load() const
 	{
+		#if CROWN_PLATFORM_POSIX && CROWN_COMPILER_GCC
 		__sync_fetch_and_add(&m_val, 0);
 		return m_val;
+		#elif CROWN_PLATFORM_WINDOWS
+		InterlockedExchangeAdd(&m_val, (int32_t)0);
+		return m_val;
+		#endif
 	}
 
 	void store(int val)
 	{
+		#if CROWN_PLATFORM_POSIX && CROWN_COMPILER_GCC
 		__sync_lock_test_and_set(&m_val, val);
+		#elif CROWN_PLATFORM_WINDOWS
+		InterlockedExchange(&m_val, val);
+		#endif
 	}
 
 private:
 
+	#if CROWN_PLATFORM_POSIX && CROWN_COMPILER_GCC
 	mutable int m_val;
+	#elif CROWN_PLATFORM_WINDOWS
+	mutable LONG m_val;
+	#endif
 };
 
 } // namespace crown

+ 140 - 0
engine/core/thread/Mutex.h

@@ -0,0 +1,140 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+#include "Config.h"
+#include "Types.h"
+#include "Assert.h"
+
+#if CROWN_PLATFORM_POSIX
+	#include <pthread.h>
+#elif CROWN_PLATFORM_WINDOWS
+	#include <windows.h>
+#endif
+
+namespace crown
+{
+
+struct Mutex
+{
+	Mutex()
+	{
+		#if CROWN_PLATFORM_POSIX
+		int result = pthread_mutexattr_init(&m_attr);
+		CE_ASSERT(result == 0, "pthread_mutexattr_init: errno = %d", result);
+		result = pthread_mutexattr_settype(&m_attr, PTHREAD_MUTEX_ERRORCHECK);
+		CE_ASSERT(result == 0, "pthread_mutexattr_settype: errno = %d", result);
+		result = pthread_mutex_init(&m_mutex, &m_attr);
+		CE_ASSERT(result == 0, "pthread_mutex_init: errno = %d", result);
+		CE_UNUSED(result);
+		#elif CROWN_PLATFORM_WINDOWS
+		InitializeCriticalSection(&m_cs);
+		#endif
+	}
+
+	~Mutex()
+	{
+		#if CROWN_PLATFORM_POSIX
+		int result = pthread_mutex_destroy(&m_mutex);
+		CE_ASSERT(result == 0, "pthread_mutex_destroy: errno = %d", result);
+		result = pthread_mutexattr_destroy(&m_attr);
+		CE_ASSERT(result == 0, "pthread_mutexattr_destroy: errno = %d", result);
+		CE_UNUSED(result);
+		#elif CROWN_PLATFORM_WINDOWS
+		DeleteCriticalSection(&m_cs);
+		#endif
+
+	}
+
+	void lock()
+	{
+		#if CROWN_PLATFORM_POSIX
+		int result = pthread_mutex_lock(&m_mutex);
+		CE_ASSERT(result == 0, "pthread_mutex_lock: errno = %d", result);
+		CE_UNUSED(result);
+		#elif CROWN_PLATFORM_WINDOWS
+		EnterCriticalSection(&m_cs);
+		#endif
+	}
+
+	void unlock()
+	{
+		#if CROWN_PLATFORM_POSIX
+		int result = pthread_mutex_unlock(&m_mutex);
+		CE_ASSERT(result == 0, "pthread_mutex_unlock: errno = %d", result);
+		CE_UNUSED(result);
+		#elif CROWN_PLATFORM_WINDOWS
+		LeaveCriticalSection(&m_cs);
+		#endif
+	}
+
+public:
+
+	#if CROWN_PLATFORM_POSIX
+	pthread_mutex_t m_mutex;
+	pthread_mutexattr_t m_attr;
+	#elif CROWN_PLATFORM_WINDOWS
+	CRITICAL_SECTION m_cs;
+	#endif
+
+private:
+
+	// Disable copying.
+	Mutex(const Mutex&);
+	Mutex& operator=(const Mutex&);
+};
+
+/// Automatically locks a mutex when created and unlocks when destroyed.
+class ScopedMutex
+{
+public:
+
+	/// Locks the given @a m mutex.
+	ScopedMutex(Mutex& m)
+		: m_mutex(m)
+	{
+		m_mutex.lock();
+	}
+
+	/// Unlocks the mutex passed to ScopedMutex::ScopedMutex()
+	~ScopedMutex()
+	{
+		m_mutex.unlock();
+	}
+
+private:
+
+	Mutex& m_mutex;
+
+private:
+
+	// Disable copying
+	ScopedMutex(const ScopedMutex&);
+	ScopedMutex& operator=(const ScopedMutex&);
+};
+
+} // namespace crown

+ 131 - 0
engine/core/thread/Semaphore.h

@@ -0,0 +1,131 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+#include "Config.h"
+#include "Assert.h"
+#include "Mutex.h"
+#include "Cond.h"
+
+#if CROWN_PLATFORM_POSIX
+	#include <pthread.h>
+#elif CROWN_PLATFORM_WINDOWS
+	#include "WinHeaders.h"
+	#include <limits.h>
+#endif
+
+namespace crown
+{
+
+struct Semaphore
+{
+	Semaphore()
+		#if CROWN_PLATFORM_POSIX
+		: m_count(0)
+		#elif CROWN_PLATFORM_WINDOWS
+		: m_handle(INVALID_HANDLE_VALUE)
+		#endif
+	{
+		#if CROWN_PLATFORM_POSIX
+		int result = pthread_cond_init(&m_cond, NULL);
+		CE_ASSERT(result == 0, "pthread_cond_init: errno = %d", result);
+		CE_UNUSED(result);
+		#elif CROWN_PLATFORM_WINDOWS
+		m_handle = CreateSemaphore(NULL, 0, LONG_MAX, NULL);
+		CE_ASSERT(m_handle != NULL, "Unable to create semaphore!");
+		CE_UNUSED(m_handle);
+		#endif
+	}
+
+	~Semaphore()
+	{
+		#if CROWN_PLATFORM_POSIX
+		int result = pthread_cond_destroy(&m_cond);
+		CE_ASSERT(result == 0, "pthread_cond_destroy: errno = %d", result);
+		CE_UNUSED(result);
+		#elif CROWN_PLATFORM_WINDOWS
+		CloseHandle(m_handle);
+		#endif
+	}
+
+	void post(uint32_t count = 1)
+	{
+		#if CROWN_PLATFORM_POSIX
+		m_mutex.lock();
+		for (uint32_t i = 0; i < count; i++)
+		{
+			int result = pthread_cond_signal(&m_cond);
+			CE_ASSERT(result == 0, "pthread_cond_signal: errno = %d", result);
+			CE_UNUSED(result);
+		}
+
+		m_count += count;
+		m_mutex.unlock();
+		#elif CROWN_PLATFORM_WINDOWS
+		ReleaseSemaphore(m_handle, count, NULL);
+		#endif
+	}
+
+	void wait()
+	{
+		#if CROWN_PLATFORM_POSIX
+		m_mutex.lock();
+		while (m_count <= 0)
+		{
+			int result = pthread_cond_wait(&m_cond, &(m_mutex.m_mutex));
+			CE_ASSERT(result == 0, "pthread_cond_wait: errno = %d", result);
+			CE_UNUSED(result);	
+		}
+
+		m_count--;
+		m_mutex.unlock();
+		#elif CROWN_PLATFORM_WINDOWS
+		DWORD milliseconds = (0 > msecs) ? INFINITE : msecs;
+		DWORD result = WaitForSingleObject(m_handle, milliseconds);
+		CE_ASSERT(result == WAIT_OBJECT_0, "Semaphore can not signal!");
+		CE_UNUSED(result);
+		#endif
+	}
+
+private:
+
+	#if CROWN_PLATFORM_POSIX
+	Mutex m_mutex;
+	pthread_cond_t m_cond;
+	int32_t m_count;
+	#elif CROWN_PLATFORM_WINDOWS
+	HANDLE m_handle;
+	#endif
+
+private:
+
+	// Disable copying
+	Semaphore(const Semaphore& s);
+	Semaphore& operator=(const Semaphore& s);
+};
+
+} // namespace crown

+ 173 - 0
engine/core/thread/Thread.h

@@ -0,0 +1,173 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+#include "Config.h"
+#include "Assert.h"
+#include "Types.h"
+#include "Semaphore.h"
+
+#if CROWN_PLATFORM_POSIX
+	#include <pthread.h>
+#elif CROWN_PLATFORM_WINDOWS
+	#include "WinHeaders.h"
+	#include <process.h>
+	#include <WinBase.h>
+#endif
+
+namespace crown
+{
+
+typedef int32_t (*ThreadFunction)(void*);
+
+struct Thread
+{
+	Thread()
+		#if CROWN_PLATFORM_POSIX
+		: m_handle(0)
+		#elif CROWN_PLATFORM_WINDOWS
+		: m_handle(INVALID_HANDLE_VALUE)
+		#endif
+		, m_function(NULL)
+		, m_data(NULL)
+		, m_stack_size(0)
+		, m_is_running(false)
+	{
+	}
+
+	~Thread()
+	{
+		if (m_is_running)
+			stop();
+	}
+
+	void start(ThreadFunction func, void* data = NULL, size_t stack_size = 0)
+	{
+		CE_ASSERT(!m_is_running, "Thread is already running");
+		CE_ASSERT(func != NULL, "Function must be != NULL");
+		m_function = func;
+		m_data = data;
+		m_stack_size = stack_size;
+
+		#if CROWN_PLATFORM_POSIX
+		pthread_attr_t attr;
+		int result = pthread_attr_init(&attr);
+		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+		CE_ASSERT(result == 0, "pthread_attr_init: errno = %d", result);
+
+		if (m_stack_size != 0)
+		{
+			result = pthread_attr_setstacksize(&attr, m_stack_size);
+			CE_ASSERT(result == 0, "pthread_attr_setstacksize: errno = %d", result);
+		}
+
+		result = pthread_create(&m_handle, &attr, thread_proc, this);
+		CE_ASSERT(result == 0, "pthread_create: errno = %d", result);
+
+		// Free attr memory
+		result = pthread_attr_destroy(&attr);
+		CE_ASSERT(result == 0, "pthread_attr_destroy: errno = %d", result);
+		CE_UNUSED(result);
+		#elif CROWN_PLATFORM_WINDOWS
+		m_handle = CreateThread(NULL, stack_size, Thread::thread_proc, this, 0, NULL);
+		CE_ASSERT(m_handle != NULL, "Failed to create the thread '%s'", m_name);
+		#endif
+
+		m_is_running = true;
+		m_sem.wait();
+	}
+
+	void stop()
+	{
+		CE_ASSERT(m_is_running, "Thread is not running");
+
+		#if CROWN_PLATFORM_POSIX
+		int result = pthread_join(m_handle, NULL);
+		CE_ASSERT(result == 0, "pthread_join: errno = %d", result);
+		CE_UNUSED(result);
+		m_handle = 0;
+		#elif CROWN_PLATFORM_WINDOWS
+		WaitForSingleObject(m_handle, INFINITE);
+		GetExitCodeThread(m_handle, &m_exit_code);
+		CloseHandle(m_handle);
+		m_handle = INVALID_HANDLE_VALUE;
+		#endif
+
+		m_is_running = false;
+	}
+
+	bool is_running()
+	{
+		return m_is_running;
+	}
+
+private:
+
+	int32_t run()
+	{
+		m_sem.post();
+		return m_function(m_data);
+	}
+
+	#if CROWN_PLATFORM_POSIX
+	static void* thread_proc(void* arg)
+	{
+		static int32_t result = -1;
+		result = ((Thread*)arg)->run();
+		return (void*)&result;			
+	}
+	#elif CROWN_PLATFORM_WINDOWS
+	static DWORD WINAPI OsThread::thread_proc(void* arg)
+	{
+		OsThread* thread = (OsThread*)arg;
+		int32_t result = thread->run();
+		return result;
+	}
+	#endif
+
+private:
+
+	#if CROWN_PLATFORM_POSIX
+	pthread_t m_handle;
+	#elif CROWN_PLATFORM_WINDOWS
+	HANDLE m_handle;
+	#endif
+
+	ThreadFunction m_function;
+	void* m_data;
+	Semaphore m_sem;
+	size_t m_stack_size;
+	bool m_is_running;
+
+private:
+
+	// Disable copying
+	Thread(const Thread&);
+	Thread& operator=(const Thread&);
+};
+
+} // namespace crown

+ 0 - 63
engine/os/ScopedMutex.h

@@ -1,63 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Mutex.h"
-
-namespace crown
-{
-
-/// Automatically locks a mutex when created and unlocks when destroyed.
-class ScopedMutex
-{
-public:
-
-	/// Locks the given @a m mutex.
-	ScopedMutex(Mutex& m)
-		: m_mutex(m)
-	{
-		m_mutex.lock();
-	}
-
-	/// Unlocks the mutex passed to ScopedMutex::ScopedMutex()
-	~ScopedMutex()
-	{
-		m_mutex.unlock();
-	}
-
-private:
-
-	Mutex& m_mutex;
-
-private:
-
-	// Disable copying
-	ScopedMutex(const ScopedMutex&);
-	ScopedMutex& operator=(const ScopedMutex&);
-};
-
-} // namespace crown

+ 0 - 29
engine/os/android/Mutex.h

@@ -1,29 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "../posix/Mutex.h"

+ 0 - 29
engine/os/android/OsThread.h

@@ -1,29 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "../posix/OsThread.h"

+ 0 - 59
engine/os/linux/AtomicInt.h

@@ -1,59 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#ifndef __GNUG__
-	#error "Compiler not supported"
-#endif
-
-namespace crown
-{
-
-struct AtomicInt
-{
-	AtomicInt(int val)
-	{
-		store(val);
-	}
-
-	int load() const
-	{
-		__sync_fetch_and_add(&m_val, 0);
-		return m_val;
-	}
-
-	void store(int val)
-	{
-		__sync_lock_test_and_set(&m_val, val);
-	}
-
-private:
-
-	mutable int m_val;
-};
-
-} // namespace crown

+ 0 - 29
engine/os/linux/Mutex.h

@@ -1,29 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "../posix/Mutex.h"

+ 0 - 29
engine/os/linux/OsThread.h

@@ -1,29 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "../posix/OsThread.h"

+ 0 - 29
engine/os/linux/Semaphore.h

@@ -1,29 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "../posix/Semaphore.h"

+ 1 - 1
engine/os/linux/main.cpp

@@ -313,7 +313,7 @@ public:
 		Rotation rr_old_rot;
 		const SizeID rr_old_sizeid = XRRConfigCurrentConfiguration(m_screen_config, &rr_old_rot);
 
-		OsThread game_thread("game-thread");
+		Thread game_thread;
 		game_thread.start(main_loop, (void*)this);
 
 		while (!m_exit)

+ 0 - 106
engine/os/posix/Mutex.h

@@ -1,106 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include <pthread.h>
-#include <cstring>
-
-#include "Types.h"
-#include "OS.h"
-#include "Assert.h"
-
-namespace crown
-{
-
-class Mutex
-{
-public:
-
-						Mutex();
-						~Mutex();
-
-	void				lock();
-	void				unlock();
-
-private:
-
-	pthread_mutex_t		m_mutex;
-	pthread_mutexattr_t m_attr;
-
-private:
-
-	// Disable copying.
-						Mutex(const Mutex&);
-	Mutex&				operator=(const Mutex&);
-
-	friend class		Cond;
-};
-
-//-----------------------------------------------------------------------------
-inline Mutex::Mutex()
-{
-	memset(&m_mutex, 0, sizeof(pthread_mutex_t));
-	int result;
-
-	result = pthread_mutexattr_init(&m_attr);
-	CE_ASSERT(result == 0, "Failed to init mutex attr. errno: %d", result);
-	result = pthread_mutexattr_settype(&m_attr, PTHREAD_MUTEX_ERRORCHECK);
-	CE_ASSERT(result == 0, "Failed to set mutex type. errno: %d", result);
-	result = pthread_mutex_init(&m_mutex, &m_attr);
-	CE_ASSERT(result == 0, "Failed to init mutex. errno: %d", result);
-	CE_UNUSED(result);
-}
-
-//-----------------------------------------------------------------------------
-inline Mutex::~Mutex()
-{
-	int result;
-
-	result = pthread_mutex_destroy(&m_mutex);
-	CE_ASSERT(result == 0, "Failed to destroy mutex. errno: %d", result);
-	result = pthread_mutexattr_destroy(&m_attr);
-	CE_ASSERT(result == 0, "Failed to destroy mutex attr. errno: %d", result);
-	CE_UNUSED(result);
-}
-
-//-----------------------------------------------------------------------------
-inline void Mutex::lock()
-{
-	int result = pthread_mutex_lock(&m_mutex);
-	CE_ASSERT(result == 0, "Failed to acquire lock. errno: %d", result);
-	CE_UNUSED(result);
-}
-
-//-----------------------------------------------------------------------------
-inline void Mutex::unlock()
-{
-	int result = pthread_mutex_unlock(&m_mutex);
-	CE_ASSERT(result == 0, "Failed to release lock. errno: %d", result);
-	CE_UNUSED(result);
-}
-
-} // namespace crown

+ 0 - 161
engine/os/posix/OsThread.h

@@ -1,161 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include <cstring>
-
-#include "Assert.h"
-#include "Types.h"
-#include "Semaphore.h"
-#include "Log.h"
-
-namespace crown
-{
-
-typedef int32_t (*ThreadFunction)(void*);
-
-class OsThread
-{
-public:
-
-						OsThread(const char* name);
-						~OsThread();
-
-	void				start(ThreadFunction func, void* data = NULL, size_t stack_size = 0);
-	void				stop();
-
-	bool				is_running();
-
-private:
-
-	int32_t				run();
-
-	static void* 		thread_proc(void* arg);
-
-private:
-
-	const char* 		m_name;
-
-	pthread_t			m_handle;
-	ThreadFunction 	m_function;
-	void*				m_data;
-	Semaphore			m_sem;
-	size_t 				m_stack_size;
-
-	bool				m_is_running :1;
-};
-
-//-----------------------------------------------------------------------------
-inline OsThread::OsThread(const char* name) :
-	m_name(name),
-	m_handle(0),
-	m_function(NULL),
-	m_data(NULL),
-	m_stack_size(0),
-	m_is_running(false)
-{
-	memset(&m_handle, 0, sizeof(pthread_t));
-}
-
-//-----------------------------------------------------------------------------
-inline OsThread::~OsThread()
-{
-}
-
-//-----------------------------------------------------------------------------
-inline void OsThread::start(ThreadFunction func, void* data, size_t stack_size)
-{
-	CE_ASSERT(!m_is_running, "OsThread is already running");
-	CE_ASSERT(func != NULL, "Function must be != NULL");
-
-	m_function = func;
-	m_data = data;
-	m_stack_size = stack_size;
-
-	pthread_attr_t attr;
-	int32_t result = pthread_attr_init(&attr);
-	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
-
-	CE_ASSERT(result == 0, "pthread_attr_init failed. errno: %d", result);
-
-	if (m_stack_size != 0)
-	{
-		result = pthread_attr_setstacksize(&attr, m_stack_size);
-		CE_ASSERT(result == 0, "pthread_attr_setstacksize failed. errno: %d", result);
-	}
-
-	result = pthread_create(&m_handle, &attr, thread_proc, this);
-	CE_ASSERT(result == 0, "pthread_create failed. errno: %d", result);
-
-	// Free attr memory
-	result = pthread_attr_destroy(&attr);
-	CE_ASSERT(result == 0, "pthread_attr_destroy failed. errno: %d", result);
-	CE_UNUSED(result);
-
-	m_is_running = true;
-
-	m_sem.wait();
-}
-
-//-----------------------------------------------------------------------------
-inline void OsThread::stop()
-{
-	CE_ASSERT(m_is_running, "OsThread is not running");
-	
-	int32_t result = pthread_join(m_handle, NULL);
-	CE_ASSERT(result == 0, "OsThread join failed. errno: %d", result);
-	CE_UNUSED(result);
-
-	m_is_running = false;
-	m_handle = 0;
-}
-
-//-----------------------------------------------------------------------------
-inline bool OsThread::is_running()
-{
-	return m_is_running;
-}
-
-//-----------------------------------------------------------------------------
-inline int32_t OsThread::run()
-{
-	m_sem.post();
-	
-	return m_function(m_data);
-}
-
-//-----------------------------------------------------------------------------
-inline void* OsThread::thread_proc(void* arg)
-{
-	static int32_t result = -1;
-	result = ((OsThread*)arg)->run();
-
-	return (void*)&result;
-}
-
-
-} // namespace crown

+ 0 - 104
engine/os/posix/Semaphore.h

@@ -1,104 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include <errno.h>
-#include <semaphore.h>
-
-#include "Assert.h"
-#include "Mutex.h"
-#include "Cond.h"
-#include "Log.h"
-
-namespace crown
-{
-
-class Semaphore
-{
-public:
-
-			Semaphore();
-			~Semaphore();
-
-	void	post(uint32_t count = 1);
-	void	wait();
-
-private:
-
-	Mutex 	m_mutex;
-	Cond 	m_cond;
-
-	int32_t m_count;
-
-private:
-
-	Semaphore(const Semaphore& s); // no copy constructor
-	Semaphore& operator=(const Semaphore& s); // no assignment operator
-};
-
-//-----------------------------------------------------------------------------
-inline Semaphore::Semaphore() : m_count(0)
-{
-}
-
-//-----------------------------------------------------------------------------
-inline Semaphore::~Semaphore()
-{
-}
-
-//-----------------------------------------------------------------------------
-inline void Semaphore::post(uint32_t count)
-{
-	m_mutex.lock();
-
-	for (uint32_t i = 0; i < count; i++)
-	{
-		m_cond.signal();
-	}
-
-	m_count += count;
-
-	m_mutex.unlock();	
-}
-
-//-----------------------------------------------------------------------------
-inline void Semaphore::wait()
-{
-	m_mutex.lock();
-
-	while (m_count <= 0)
-	{
-		m_cond.wait(m_mutex);
-	}
-
-	m_count--;
-
-	m_mutex.unlock();
-}
-
-
-} // namespace crown

+ 0 - 57
engine/os/win/AtomicInt.h

@@ -1,57 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Types.h"
-#include "WinHeaders.h"
-
-namespace crown
-{
-
-struct AtomicInt
-{
-	explicit AtomicInt(int32_t value)
-	{
-		m_value = value;
-	}
-
-	int load() const
-	{
-		InterlockedExchangeAdd(&m_value, (int32_t)0);
-		return m_value;
-	}
-
-	void store(int val)
-	{
-		InterlockedExchange(&m_value, val);
-	}
-
-private:
-	mutable LONG m_value;
-};
-
-} // namespace crown

+ 0 - 82
engine/os/win/Mutex.h

@@ -1,82 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "WinHeaders.h"
-#include "Types.h"
-#include "OS.h"
-
-namespace crown
-{
-
-class Mutex
-{
-public:
-
-						Mutex();
-						~Mutex();
-
-	void				lock();
-	void				unlock();
-
-private:
-
-	CRITICAL_SECTION	m_cs;
-
-private:
-
-						Mutex(const Mutex&);
-	Mutex&				operator=(const Mutex&);
-
-	friend class		Cond;
-};
-
-//-----------------------------------------------------------------------------
-inline Mutex::Mutex()
-{
-	InitializeCriticalSection(&m_cs);
-}
-
-//-----------------------------------------------------------------------------
-inline Mutex::~Mutex()
-{
-	DeleteCriticalSection(&m_cs);
-}
-
-//-----------------------------------------------------------------------------
-inline void Mutex::lock()
-{
-    EnterCriticalSection(&m_cs); 
-}
-
-//-----------------------------------------------------------------------------
-inline void Mutex::unlock()
-{
-    LeaveCriticalSection(&m_cs);
-}
-
-} // namespace crown

+ 0 - 156
engine/os/win/OsThread.h

@@ -1,156 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "WinHeaders.h"
-#include <process.h>
-#include <WinBase.h>
-
-#include "Types.h"
-#include "OS.h"
-#include "Semaphore.h"
-#include "Assert.h"
-
-namespace crown
-{
-
-typedef int32_t (*ThreadFunction)(void*);
-
-class OsThread
-{
-public:
-						OsThread(const char* name);
-						~OsThread();
-
-	void				start(ThreadFunction func, void* data = NULL, size_t stack_size = 0);
-	void				stop();
-
-	bool				is_running();
-
-private:
-
-	int32_t				run();
-
-	static DWORD WINAPI	thread_proc(void* arg);
-
-	OsThread(const OsThread& t); // no copy constructor
-	OsThread& operator=(const OsThread& t); // no assignment operator	
-
-private:
-
-	const char*			m_name;
-	HANDLE				m_handle;
-
-	ThreadFunction 		m_function;
-	void*				m_data;
-	Semaphore			m_sem;
-	size_t 				m_stack_size;
-
-	bool				m_is_running :1;
-
-	DWORD				m_exit_code;
-};
-
-//-----------------------------------------------------------------------------
-CE_INLINE OsThread::OsThread(const char* name) :
-	m_name(name),
-	m_handle(INVALID_HANDLE_VALUE),
-	m_function(NULL),
-	m_data(NULL),
-	m_stack_size(0),
-	m_is_running(false),
-	m_exit_code(0)
-{
-	memset(&m_handle, 0, sizeof(HANDLE));
-}
-
-//-----------------------------------------------------------------------------
-CE_INLINE OsThread::~OsThread()
-{
-	if (m_is_running)
-	{
-		stop();
-	}
-}
-
-//-----------------------------------------------------------------------------
-CE_INLINE void OsThread::start(ThreadFunction func, void* data, size_t stack_size)
-{
-	CE_ASSERT(!m_is_running, "Thread is already running");
-	CE_ASSERT(func != NULL, "Function must be != NULL");
-
-	m_function = func;
-	m_data = data;
-	m_stack_size = stack_size;
-
-	m_handle = CreateThread(NULL, stack_size, OsThread::thread_proc, this, 0, NULL);
-
-	CE_ASSERT(m_handle != NULL, "Failed to create the thread '%s'", m_name);
-
-	m_is_running = true;
-
-	m_sem.wait();
-}
-
-//-----------------------------------------------------------------------------
-CE_INLINE void OsThread::stop()
-{
-	CE_ASSERT(m_is_running, "Thread is not running");
-
-	WaitForSingleObject(m_handle, INFINITE);
-	GetExitCodeThread(m_handle, &m_exit_code);
-	CloseHandle(m_handle);
-	m_handle = INVALID_HANDLE_VALUE;
-
-	m_is_running = false;
-}
-
-//-----------------------------------------------------------------------------
-CE_INLINE bool OsThread::is_running()
-{
-	return m_is_running;
-}
-
-//-----------------------------------------------------------------------------
-CE_INLINE int32_t OsThread::run()
-{
-	m_sem.post();
-
-	return m_function(m_data);
-}
-
-//-----------------------------------------------------------------------------
-CE_INLINE DWORD WINAPI OsThread::thread_proc(void* arg)
-{
-	OsThread* thread = (OsThread*)arg;
-
-	int32_t result = thread->run();
-	
-	return result;
-}
-
-} // namespace crown

+ 0 - 78
engine/os/win/Semaphore.h

@@ -1,78 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "WinHeaders.h"
-#include <limits.h>
-
-#include "Assert.h"
-
-class Semaphore
-{
-public:
-
-	Semaphore();
-	~Semaphore();
-
-	void post(uint32_t count = 1) const;
-	void wait(int32_t msecs = -1) const;
-
-private:
-
-	Semaphore(const Semaphore& s); // no copy constructor
-	Semaphore& operator=(const Semaphore& s); // no assignment operator
-
-	HANDLE m_handle;
-};
-
-//-----------------------------------------------------------------------------
-inline Semaphore::Semaphore()
-{
-	m_handle = CreateSemaphore(NULL, 0, LONG_MAX, NULL);
-	CE_ASSERT(m_handle != NULL, "Unable to create semaphore!");
-}
-
-//-----------------------------------------------------------------------------
-inline Semaphore::~Semaphore()
-{
-	CloseHandle(m_handle);
-}
-
-//-----------------------------------------------------------------------------
-inline void Semaphore::post(uint32_t count) const
-{
-	ReleaseSemaphore(m_handle, count, NULL);
-}
-
-//-----------------------------------------------------------------------------
-inline void Semaphore::wait(int32_t msecs) const
-{
-	DWORD milliseconds = (0 > msecs) ? INFINITE : msecs;
-	DWORD result = WaitForSingleObject(m_handle, milliseconds);
-
-	CE_ASSERT(result == WAIT_OBJECT_0, "Semaphore can not signal!");
-}

+ 2 - 2
engine/renderers/backend/Renderer.h

@@ -32,7 +32,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "VertexFormat.h"
 #include "StringUtils.h"
 #include "RenderContext.h"
-#include "OsThread.h"
+#include "Thread.h"
 #include "OS.h"
 #include "IdTable.h"
 
@@ -905,7 +905,7 @@ protected:
 	Allocator& m_allocator;
 	RendererImplementation* m_impl;
 
-	OsThread m_thread;
+	Thread m_thread;
 	Semaphore m_render_wait;
 	Semaphore m_main_wait;
 

+ 1 - 1
engine/renderers/backend/gl/GLRenderer.cpp

@@ -1125,7 +1125,7 @@ private:
 
 //-----------------------------------------------------------------------------
 Renderer::Renderer(Allocator& a)
-	: m_allocator(a), m_impl(NULL), m_thread("render-thread"), m_submit(&m_contexts[0]), m_draw(&m_contexts[1]),
+	: m_allocator(a), m_impl(NULL), m_submit(&m_contexts[0]), m_draw(&m_contexts[1]),
 		m_is_initialized(false), m_should_run(false)
 {
 	m_impl = CE_NEW(a, RendererImplementation)(this);

+ 1 - 1
engine/resource/ResourceLoader.cpp

@@ -34,7 +34,7 @@ namespace crown
 
 //-----------------------------------------------------------------------------
 ResourceLoader::ResourceLoader(Bundle& bundle, Allocator& resource_heap) :
-	m_thread("resource-loader"),
+	m_thread(),
 	m_should_run(false),
 	m_bundle(bundle),
 	m_resource_heap(resource_heap),

+ 2 - 2
engine/resource/ResourceLoader.h

@@ -28,7 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Types.h"
 #include "Resource.h"
-#include "OsThread.h"
+#include "Thread.h"
 #include "ContainerTypes.h"
 #include "Mutex.h"
 #include "Cond.h"
@@ -106,7 +106,7 @@ private:
 
 private:
 
-	OsThread m_thread;
+	Thread m_thread;
 	bool m_should_run;
 
 	// Whether to look for resources

+ 2 - 2
makefile

@@ -8,9 +8,9 @@ endif
 PREMAKE=bin/$(OS)/premake4
 
 luajit-linux32:
-	make -R -C third/luajit CC="gcc -m32"
+	make -R -C third/luajit CC="gcc -m32" BUILDMODE="static"
 luajit-linux64:
-	make -R -C third/luajit
+	make -R -C third/luajit CC="gcc -m64" BUILDMODE="static"
 luajit-windows32:
 	cd third/luajit/src && msvcbuild
 luajit-windows64:

+ 1 - 4
premake/premake4.lua

@@ -153,6 +153,7 @@ solution "crown"
 			CROWN_SOURCE_DIR .. "/engine/core/json",
 			CROWN_SOURCE_DIR .. "/engine/core/strings",
 			CROWN_SOURCE_DIR .. "/engine/core/settings",
+			CROWN_SOURCE_DIR .. "/engine/core/thread",
 			CROWN_SOURCE_DIR .. "/engine/os",
 			CROWN_SOURCE_DIR .. "/engine/input",
 			CROWN_SOURCE_DIR .. "/engine/renderers",
@@ -323,9 +324,7 @@ solution "crown"
 
 			postbuildcommands {
 				"cp " .. CROWN_THIRD_DIR .. "luajit/src/luajit " .. CROWN_INSTALL_DIR .. "bin/linux32/",
-				"cp " .. CROWN_THIRD_DIR .. "luajit/src/libluajit.so " .. CROWN_INSTALL_DIR .. "bin/linux32/",
 				"cp " .. CROWN_THIRD_DIR .. "luajit/src/jit " .. CROWN_INSTALL_DIR .. "bin/linux32/" .. " -r",
-				"ln -s " .. CROWN_INSTALL_DIR .. "bin/linux32/libluajit.so " .. CROWN_INSTALL_DIR .. "bin/linux32/libluajit-5.1.so.2"
 			}
 
 		configuration { "linux-*", "x64" }
@@ -364,9 +363,7 @@ solution "crown"
 
 			postbuildcommands {
 				"cp " .. CROWN_THIRD_DIR .. "luajit/src/luajit " .. CROWN_INSTALL_DIR .. "bin/linux64/",
-				"cp " .. CROWN_THIRD_DIR .. "luajit/src/libluajit.so " .. CROWN_INSTALL_DIR .. "bin/linux64/",
 				"cp " .. CROWN_THIRD_DIR .. "luajit/src/jit " .. CROWN_INSTALL_DIR .. "bin/linux64/" .. " -r",
-				"ln -s " .. CROWN_INSTALL_DIR .. "bin/linux64/libluajit.so " .. CROWN_INSTALL_DIR .. "bin/linux64/libluajit-5.1.so.2"
 			}
 
 		configuration { "android" }