Updates
This commit is contained in:
parent
a8d3b205ca
commit
944eb01fb4
|
@ -437,11 +437,17 @@ void scond_free(scond_t *cond)
|
||||||
#ifdef USE_WIN32_THREADS
|
#ifdef USE_WIN32_THREADS
|
||||||
static bool _scond_wait_win32(scond_t *cond, slock_t *lock, DWORD dwMilliseconds)
|
static bool _scond_wait_win32(scond_t *cond, slock_t *lock, DWORD dwMilliseconds)
|
||||||
{
|
{
|
||||||
static bool beginPeriod = false;
|
|
||||||
|
|
||||||
struct QueueEntry myentry;
|
struct QueueEntry myentry;
|
||||||
struct QueueEntry **ptr;
|
struct QueueEntry **ptr;
|
||||||
|
|
||||||
|
#if _WIN32_WINNT >= 0x0500
|
||||||
|
static LARGE_INTEGER performanceCounterFrequency = { .QuadPart = 0 };
|
||||||
|
LARGE_INTEGER tsBegin;
|
||||||
|
#else
|
||||||
|
static bool beginPeriod = false;
|
||||||
DWORD tsBegin;
|
DWORD tsBegin;
|
||||||
|
#endif
|
||||||
|
|
||||||
DWORD waitResult;
|
DWORD waitResult;
|
||||||
DWORD dwFinalTimeout = dwMilliseconds; /* Careful! in case we begin in the head,
|
DWORD dwFinalTimeout = dwMilliseconds; /* Careful! in case we begin in the head,
|
||||||
we don't do the hot potato stuff,
|
we don't do the hot potato stuff,
|
||||||
|
@ -453,16 +459,27 @@ static bool _scond_wait_win32(scond_t *cond, slock_t *lock, DWORD dwMilliseconds
|
||||||
|
|
||||||
/* since this library is meant for realtime game software
|
/* since this library is meant for realtime game software
|
||||||
* I have no problem setting this to 1 and forgetting about it. */
|
* I have no problem setting this to 1 and forgetting about it. */
|
||||||
|
#if _WIN32_WINNT >= 0x0500
|
||||||
|
if (performanceCounterFrequency.QuadPart == 0)
|
||||||
|
{
|
||||||
|
QueryPerformanceFrequency(&performanceCounterFrequency);
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (!beginPeriod)
|
if (!beginPeriod)
|
||||||
{
|
{
|
||||||
beginPeriod = true;
|
beginPeriod = true;
|
||||||
timeBeginPeriod(1);
|
timeBeginPeriod(1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Now we can take a good timestamp for use in faking the timeout ourselves. */
|
/* Now we can take a good timestamp for use in faking the timeout ourselves. */
|
||||||
/* But don't bother unless we need to (to save a little time) */
|
/* But don't bother unless we need to (to save a little time) */
|
||||||
if (dwMilliseconds != INFINITE)
|
if (dwMilliseconds != INFINITE)
|
||||||
|
#if _WIN32_WINNT >= 0x0500
|
||||||
|
QueryPerformanceCounter(&tsBegin);
|
||||||
|
#else
|
||||||
tsBegin = timeGetTime();
|
tsBegin = timeGetTime();
|
||||||
|
#endif
|
||||||
|
|
||||||
/* add ourselves to a queue of waiting threads */
|
/* add ourselves to a queue of waiting threads */
|
||||||
ptr = &cond->head;
|
ptr = &cond->head;
|
||||||
|
@ -504,8 +521,16 @@ static bool _scond_wait_win32(scond_t *cond, slock_t *lock, DWORD dwMilliseconds
|
||||||
/* Assess the remaining timeout time */
|
/* Assess the remaining timeout time */
|
||||||
if (dwMilliseconds != INFINITE)
|
if (dwMilliseconds != INFINITE)
|
||||||
{
|
{
|
||||||
DWORD now = timeGetTime();
|
#if _WIN32_WINNT >= 0x0500
|
||||||
|
LARGE_INTEGER now;
|
||||||
|
QueryPerformanceCounter(&now);
|
||||||
|
LONGLONG elapsed = now.QuadPart - tsBegin.QuadPart;
|
||||||
|
elapsed *= 1000;
|
||||||
|
elapsed /= performanceCounterFrequency.QuadPart;
|
||||||
|
#else
|
||||||
|
DWORD now = timeGetTime();
|
||||||
DWORD elapsed = now - tsBegin;
|
DWORD elapsed = now - tsBegin;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Try one last time with a zero timeout (keeps the code simpler) */
|
/* Try one last time with a zero timeout (keeps the code simpler) */
|
||||||
if (elapsed > dwMilliseconds)
|
if (elapsed > dwMilliseconds)
|
||||||
|
|
Loading…
Reference in New Issue