Commits

Bart van Strien committed 5b0814e

Hopefully the last fixes to the win32 thread backend

Comments (0)

Files changed (2)

src/modules/thread/win32/threads.cpp

 
 	ThreadBase::~ThreadBase()
 	{
-		if (running) {
+		if (running)
 			wait();
-		}
 	}
 
 	bool ThreadBase::start()
 	{
-		thread = CreateThread(NULL, 0, thread_runner, this, NULL);
-		if (thread == NULL) {
+		thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) thread_runner, this, 0, NULL);
+		if (thread == NULL)
 			return false;
-		} else {
-			running = true;
-			return true;
-		}
+		else
+			return (running = true);
 	}
 
 	void ThreadBase::wait()
 		return (unsigned int)GetCurrentThreadId();
 	}
 
-	Semaphore::Semaphore()
-		: Semaphore(0)
-	{
-	}
-
 	Semaphore::Semaphore(unsigned int initial_value)
 		: count(initial_value)
 	{
-		semaphore = CreateSemaphore(NULL, initial_value, 65535, NULL);
+		semaphore = CreateSemaphore(NULL, initial_value, UINT_MAX, NULL);
 	}
 
 	Semaphore::~Semaphore()
 	void Semaphore::post()
 	{
 		InterlockedIncrement(&count);
-		if (ReleaseSemaphore(semaphore, 1, NULL) == FALSE) {
+		if (ReleaseSemaphore(semaphore, 1, NULL) == FALSE)
 			InterlockedDecrement(&count);
-		}
 	}
 
 	bool Semaphore::wait(int timeout)
 			InterlockedDecrement(&count);
 			return true;
 		}
-		else if (result == WAIT_TIMEOUT)
-		{
+		else
 			return false;
-		}
-		else
-		{
-			// error
-			return false;
-		}
 	}
 
 	bool Semaphore::tryWait()
 		{
 			int num = waiting - signals;
 			signals = waiting;
-			for(int i = 0; i < num; i++) sem.post();
+			for (int i = 0; i < num; i++)
+				sem.post();
 			mutex.unlock();
-			for(int i = 0; i < num; i++) done.wait();
+			for (int i = 0; i < num; i++)
+				done.wait();
 		}
 		else
 		{
 		cmutex->unlock();
 		bool ret = sem.wait(timeout);
 
-
 		mutex.lock();
 		if (signals > 0)
 		{
 		waiting--;
 		mutex.unlock();
 		cmutex->lock();
+		
+		return true;
 	}
 
 } // thread

src/modules/thread/win32/threads.h

 #define LOVE_THREAD_WIN32_THREADS_H
 
 #include <windows.h>
-
+#include <limits.h>
 
 namespace love
 {
 		ThreadBase(ThreadBase& thread) {}
 		bool running;
 
-		static int thread_runner(void* param);
+		static int WINAPI thread_runner(void* param);
 
 	protected:
 
 		unsigned int count;
 
 	public:
-		Semaphore();
-		Semaphore(unsigned int initial_value);
+		Semaphore(unsigned int initial_value = 0);
 		~Semaphore();
 
 		unsigned int value();