Daniele Bartolini %!s(int64=11) %!d(string=hai) anos
pai
achega
5b2602e2c3

+ 8 - 8
engine/core/thread/atomic_int.h

@@ -46,29 +46,29 @@ struct AtomicInt
 	int load() const
 	{
 #if CROWN_PLATFORM_POSIX && CROWN_COMPILER_GCC
-		__sync_fetch_and_add(&m_val, 0);
-		return m_val;
+		__sync_fetch_and_add(&_val, 0);
+		return _val;
 #elif CROWN_PLATFORM_WINDOWS
-		InterlockedExchangeAdd(&m_val, (int32_t)0);
-		return m_val;
+		InterlockedExchangeAdd(&_val, (int32_t)0);
+		return _val;
 #endif
 	}
 
 	void store(int val)
 	{
 #if CROWN_PLATFORM_POSIX && CROWN_COMPILER_GCC
-		__sync_lock_test_and_set(&m_val, val);
+		__sync_lock_test_and_set(&_val, val);
 #elif CROWN_PLATFORM_WINDOWS
-		InterlockedExchange(&m_val, val);
+		InterlockedExchange(&_val, val);
 #endif
 	}
 
 private:
 
 #if CROWN_PLATFORM_POSIX && CROWN_COMPILER_GCC
-	mutable int m_val;
+	mutable int _val;
 #elif CROWN_PLATFORM_WINDOWS
-	mutable LONG m_val;
+	mutable LONG _val;
 #endif
 };
 

+ 19 - 21
engine/core/thread/mutex.h

@@ -45,28 +45,28 @@ struct Mutex
 	Mutex()
 	{
 #if CROWN_PLATFORM_POSIX
-		int result = pthread_mutexattr_init(&m_attr);
+		int result = pthread_mutexattr_init(&_attr);
 		CE_ASSERT(result == 0, "pthread_mutexattr_init: errno = %d", result);
-		result = pthread_mutexattr_settype(&m_attr, PTHREAD_MUTEX_ERRORCHECK);
+		result = pthread_mutexattr_settype(&_attr, PTHREAD_MUTEX_ERRORCHECK);
 		CE_ASSERT(result == 0, "pthread_mutexattr_settype: errno = %d", result);
-		result = pthread_mutex_init(&m_mutex, &m_attr);
+		result = pthread_mutex_init(&_mutex, &_attr);
 		CE_ASSERT(result == 0, "pthread_mutex_init: errno = %d", result);
 		CE_UNUSED(result);
 #elif CROWN_PLATFORM_WINDOWS
-		InitializeCriticalSection(&m_cs);
+		InitializeCriticalSection(&_cs);
 #endif
 	}
 
 	~Mutex()
 	{
 #if CROWN_PLATFORM_POSIX
-		int result = pthread_mutex_destroy(&m_mutex);
+		int result = pthread_mutex_destroy(&_mutex);
 		CE_ASSERT(result == 0, "pthread_mutex_destroy: errno = %d", result);
-		result = pthread_mutexattr_destroy(&m_attr);
+		result = pthread_mutexattr_destroy(&_attr);
 		CE_ASSERT(result == 0, "pthread_mutexattr_destroy: errno = %d", result);
 		CE_UNUSED(result);
 #elif CROWN_PLATFORM_WINDOWS
-		DeleteCriticalSection(&m_cs);
+		DeleteCriticalSection(&_cs);
 #endif
 
 	}
@@ -74,32 +74,32 @@ struct Mutex
 	void lock()
 	{
 #if CROWN_PLATFORM_POSIX
-		int result = pthread_mutex_lock(&m_mutex);
+		int result = pthread_mutex_lock(&_mutex);
 		CE_ASSERT(result == 0, "pthread_mutex_lock: errno = %d", result);
 		CE_UNUSED(result);
 #elif CROWN_PLATFORM_WINDOWS
-		EnterCriticalSection(&m_cs);
+		EnterCriticalSection(&_cs);
 #endif
 	}
 
 	void unlock()
 	{
 #if CROWN_PLATFORM_POSIX
-		int result = pthread_mutex_unlock(&m_mutex);
+		int result = pthread_mutex_unlock(&_mutex);
 		CE_ASSERT(result == 0, "pthread_mutex_unlock: errno = %d", result);
 		CE_UNUSED(result);
 #elif CROWN_PLATFORM_WINDOWS
-		LeaveCriticalSection(&m_cs);
+		LeaveCriticalSection(&_cs);
 #endif
 	}
 
 public:
 
 #if CROWN_PLATFORM_POSIX
-	pthread_mutex_t m_mutex;
-	pthread_mutexattr_t m_attr;
+	pthread_mutex_t _mutex;
+	pthread_mutexattr_t _attr;
 #elif CROWN_PLATFORM_WINDOWS
-	CRITICAL_SECTION m_cs;
+	CRITICAL_SECTION _cs;
 #endif
 
 private:
@@ -110,26 +110,24 @@ private:
 };
 
 /// Automatically locks a mutex when created and unlocks when destroyed.
-class ScopedMutex
+struct ScopedMutex
 {
-public:
-
 	/// Locks the given @a m mutex.
 	ScopedMutex(Mutex& m)
-		: m_mutex(m)
+		: _mutex(m)
 	{
-		m_mutex.lock();
+		_mutex.lock();
 	}
 
 	/// Unlocks the mutex passed to ScopedMutex::ScopedMutex()
 	~ScopedMutex()
 	{
-		m_mutex.unlock();
+		_mutex.unlock();
 	}
 
 private:
 
-	Mutex& m_mutex;
+	Mutex& _mutex;
 
 private:
 

+ 19 - 19
engine/core/thread/semaphore.h

@@ -44,9 +44,9 @@ struct Semaphore
 {
 	Semaphore()
 #if CROWN_PLATFORM_POSIX
-		: m_count(0)
+		: _count(0)
 #elif CROWN_PLATFORM_WINDOWS
-		: m_handle(INVALID_HANDLE_VALUE)
+		: _handle(INVALID_HANDLE_VALUE)
 #endif
 	{
 #if CROWN_PLATFORM_POSIX
@@ -54,9 +54,9 @@ struct Semaphore
 		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);
+		_handle = CreateSemaphore(NULL, 0, LONG_MAX, NULL);
+		CE_ASSERT(_handle != NULL, "Unable to create semaphore!");
+		CE_UNUSED(_handle);
 #endif
 	}
 
@@ -67,14 +67,14 @@ struct Semaphore
 		CE_ASSERT(result == 0, "pthread_cond_destroy: errno = %d", result);
 		CE_UNUSED(result);
 #elif CROWN_PLATFORM_WINDOWS
-		CloseHandle(m_handle);
+		CloseHandle(_handle);
 #endif
 	}
 
 	void post(uint32_t count = 1)
 	{
 #if CROWN_PLATFORM_POSIX
-		m_mutex.lock();
+		_mutex.lock();
 		for (uint32_t i = 0; i < count; i++)
 		{
 			int result = pthread_cond_signal(&m_cond);
@@ -82,28 +82,28 @@ struct Semaphore
 			CE_UNUSED(result);
 		}
 
-		m_count += count;
-		m_mutex.unlock();
+		_count += count;
+		_mutex.unlock();
 #elif CROWN_PLATFORM_WINDOWS
-		ReleaseSemaphore(m_handle, count, NULL);
+		ReleaseSemaphore(_handle, count, NULL);
 #endif
 	}
 
 	void wait()
 	{
 #if CROWN_PLATFORM_POSIX
-		m_mutex.lock();
-		while (m_count <= 0)
+		_mutex.lock();
+		while (_count <= 0)
 		{
-			int result = pthread_cond_wait(&m_cond, &(m_mutex.m_mutex));
+			int result = pthread_cond_wait(&m_cond, &(_mutex._mutex));
 			CE_ASSERT(result == 0, "pthread_cond_wait: errno = %d", result);
 			CE_UNUSED(result);
 		}
 
-		m_count--;
-		m_mutex.unlock();
+		_count--;
+		_mutex.unlock();
 #elif CROWN_PLATFORM_WINDOWS
-		DWORD result = WaitForSingleObject(m_handle, INFINITE);
+		DWORD result = WaitForSingleObject(_handle, INFINITE);
 		CE_ASSERT(result == WAIT_OBJECT_0, "WaitForSingleObject: GetLastError = %d", GetLastError());
 		CE_UNUSED(result);
 #endif
@@ -112,11 +112,11 @@ struct Semaphore
 private:
 
 #if CROWN_PLATFORM_POSIX
-	Mutex m_mutex;
+	Mutex _mutex;
 	pthread_cond_t m_cond;
-	int32_t m_count;
+	int32_t _count;
 #elif CROWN_PLATFORM_WINDOWS
-	HANDLE m_handle;
+	HANDLE _handle;
 #endif
 
 private:

+ 36 - 36
engine/core/thread/thread.h

@@ -47,30 +47,30 @@ struct Thread
 {
 	Thread()
 #if CROWN_PLATFORM_POSIX
-		: m_handle(0)
+		: _handle(0)
 #elif CROWN_PLATFORM_WINDOWS
-		: m_handle(INVALID_HANDLE_VALUE)
+		: _handle(INVALID_HANDLE_VALUE)
 #endif
-		, m_function(NULL)
-		, m_data(NULL)
-		, m_stack_size(0)
-		, m_is_running(false)
+		, _function(NULL)
+		, _data(NULL)
+		, _stack_size(0)
+		, _is_running(false)
 	{
 	}
 
 	~Thread()
 	{
-		if (m_is_running)
+		if (_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(!_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;
+		_function = func;
+		_data = data;
+		_stack_size = stack_size;
 
 #if CROWN_PLATFORM_POSIX
 		pthread_attr_t attr;
@@ -78,13 +78,13 @@ struct Thread
 		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
 		CE_ASSERT(result == 0, "pthread_attr_init: errno = %d", result);
 
-		if (m_stack_size != 0)
+		if (_stack_size != 0)
 		{
-			result = pthread_attr_setstacksize(&attr, m_stack_size);
+			result = pthread_attr_setstacksize(&attr, _stack_size);
 			CE_ASSERT(result == 0, "pthread_attr_setstacksize: errno = %d", result);
 		}
 
-		result = pthread_create(&m_handle, &attr, thread_proc, this);
+		result = pthread_create(&_handle, &attr, thread_proc, this);
 		CE_ASSERT(result == 0, "pthread_create: errno = %d", result);
 
 		// Free attr memory
@@ -92,44 +92,44 @@ struct Thread
 		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, "CreateThread: GetLastError = %d", GetLastError());
+		_handle = CreateThread(NULL, stack_size, Thread::thread_proc, this, 0, NULL);
+		CE_ASSERT(_handle != NULL, "CreateThread: GetLastError = %d", GetLastError());
 #endif
 
-		m_is_running = true;
-		m_sem.wait();
+		_is_running = true;
+		_sem.wait();
 	}
 
 	void stop()
 	{
-		CE_ASSERT(m_is_running, "Thread is not running");
+		CE_ASSERT(_is_running, "Thread is not running");
 
 #if CROWN_PLATFORM_POSIX
-		int result = pthread_join(m_handle, NULL);
+		int result = pthread_join(_handle, NULL);
 		CE_ASSERT(result == 0, "pthread_join: errno = %d", result);
 		CE_UNUSED(result);
-		m_handle = 0;
+		_handle = 0;
 #elif CROWN_PLATFORM_WINDOWS
-		WaitForSingleObject(m_handle, INFINITE);
-		// GetExitCodeThread(m_handle, &m_exit_code);
-		CloseHandle(m_handle);
-		m_handle = INVALID_HANDLE_VALUE;
+		WaitForSingleObject(_handle, INFINITE);
+		// GetExitCodeThread(_handle, &m_exit_code);
+		CloseHandle(_handle);
+		_handle = INVALID_HANDLE_VALUE;
 #endif
 
-		m_is_running = false;
+		_is_running = false;
 	}
 
 	bool is_running()
 	{
-		return m_is_running;
+		return _is_running;
 	}
 
 private:
 
 	int32_t run()
 	{
-		m_sem.post();
-		return m_function(m_data);
+		_sem.post();
+		return _function(_data);
 	}
 
 #if CROWN_PLATFORM_POSIX
@@ -151,16 +151,16 @@ private:
 private:
 
 #if CROWN_PLATFORM_POSIX
-	pthread_t m_handle;
+	pthread_t _handle;
 #elif CROWN_PLATFORM_WINDOWS
-	HANDLE m_handle;
+	HANDLE _handle;
 #endif
 
-	ThreadFunction m_function;
-	void* m_data;
-	Semaphore m_sem;
-	size_t m_stack_size;
-	bool m_is_running;
+	ThreadFunction _function;
+	void* _data;
+	Semaphore _sem;
+	size_t _stack_size;
+	bool _is_running;
 
 private: