mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Hopefully the last fixes to the win32 thread backend
This commit is contained in:
@@ -59,20 +59,17 @@ namespace thread
|
|||||||
|
|
||||||
ThreadBase::~ThreadBase()
|
ThreadBase::~ThreadBase()
|
||||||
{
|
{
|
||||||
if (running) {
|
if (running)
|
||||||
wait();
|
wait();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ThreadBase::start()
|
bool ThreadBase::start()
|
||||||
{
|
{
|
||||||
thread = CreateThread(NULL, 0, thread_runner, this, NULL);
|
thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) thread_runner, this, 0, NULL);
|
||||||
if (thread == NULL) {
|
if (thread == NULL)
|
||||||
return false;
|
return false;
|
||||||
} else {
|
else
|
||||||
running = true;
|
return (running = true);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadBase::wait()
|
void ThreadBase::wait()
|
||||||
@@ -93,15 +90,10 @@ namespace thread
|
|||||||
return (unsigned int)GetCurrentThreadId();
|
return (unsigned int)GetCurrentThreadId();
|
||||||
}
|
}
|
||||||
|
|
||||||
Semaphore::Semaphore()
|
|
||||||
: Semaphore(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Semaphore::Semaphore(unsigned int initial_value)
|
Semaphore::Semaphore(unsigned int initial_value)
|
||||||
: count(initial_value)
|
: count(initial_value)
|
||||||
{
|
{
|
||||||
semaphore = CreateSemaphore(NULL, initial_value, 65535, NULL);
|
semaphore = CreateSemaphore(NULL, initial_value, UINT_MAX, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Semaphore::~Semaphore()
|
Semaphore::~Semaphore()
|
||||||
@@ -117,9 +109,8 @@ namespace thread
|
|||||||
void Semaphore::post()
|
void Semaphore::post()
|
||||||
{
|
{
|
||||||
InterlockedIncrement(&count);
|
InterlockedIncrement(&count);
|
||||||
if (ReleaseSemaphore(semaphore, 1, NULL) == FALSE) {
|
if (ReleaseSemaphore(semaphore, 1, NULL) == FALSE)
|
||||||
InterlockedDecrement(&count);
|
InterlockedDecrement(&count);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semaphore::wait(int timeout)
|
bool Semaphore::wait(int timeout)
|
||||||
@@ -132,15 +123,8 @@ namespace thread
|
|||||||
InterlockedDecrement(&count);
|
InterlockedDecrement(&count);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (result == WAIT_TIMEOUT)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
// error
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semaphore::tryWait()
|
bool Semaphore::tryWait()
|
||||||
@@ -187,9 +171,11 @@ namespace thread
|
|||||||
{
|
{
|
||||||
int num = waiting - signals;
|
int num = waiting - signals;
|
||||||
signals = waiting;
|
signals = waiting;
|
||||||
for(int i = 0; i < num; i++) sem.post();
|
for (int i = 0; i < num; i++)
|
||||||
|
sem.post();
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
for(int i = 0; i < num; i++) done.wait();
|
for (int i = 0; i < num; i++)
|
||||||
|
done.wait();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -206,7 +192,6 @@ namespace thread
|
|||||||
cmutex->unlock();
|
cmutex->unlock();
|
||||||
bool ret = sem.wait(timeout);
|
bool ret = sem.wait(timeout);
|
||||||
|
|
||||||
|
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
if (signals > 0)
|
if (signals > 0)
|
||||||
{
|
{
|
||||||
@@ -218,6 +203,8 @@ namespace thread
|
|||||||
waiting--;
|
waiting--;
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
cmutex->lock();
|
cmutex->lock();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // thread
|
} // thread
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#define LOVE_THREAD_WIN32_THREADS_H
|
#define LOVE_THREAD_WIN32_THREADS_H
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
@@ -50,7 +50,7 @@ namespace thread
|
|||||||
ThreadBase(ThreadBase& thread) {}
|
ThreadBase(ThreadBase& thread) {}
|
||||||
bool running;
|
bool running;
|
||||||
|
|
||||||
static int thread_runner(void* param);
|
static int WINAPI thread_runner(void* param);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@@ -76,8 +76,7 @@ namespace thread
|
|||||||
unsigned int count;
|
unsigned int count;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Semaphore();
|
Semaphore(unsigned int initial_value = 0);
|
||||||
Semaphore(unsigned int initial_value);
|
|
||||||
~Semaphore();
|
~Semaphore();
|
||||||
|
|
||||||
unsigned int value();
|
unsigned int value();
|
||||||
|
|||||||
Reference in New Issue
Block a user