Skip to content

Commit

Permalink
pl_thread_win32: initialize time variable before goto
Browse files Browse the repository at this point in the history
Fixes compilation of glslang.cc due to more strict C++ prohibiting to
jump over variable initialization.

Also as a bonus check sleep time after converting to integer as it may
end up zero.

Fixes: #185
  • Loading branch information
kasper93 committed Aug 1, 2023
1 parent b7c9e9c commit abf34ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/pl_thread_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static inline int pl_cond_timedwait(pl_cond *cond, pl_mutex *mutex, uint64_t tim
#define pl_thread_create(t, f, a) pthread_create(t, NULL, f, a)
#define pl_thread_join(t) pthread_join(t, NULL)

// Returns true, if slept full time
// Returns true if slept the full time, false otherwise
static inline bool pl_thread_sleep(double t)
{
if (t <= 0.0)
Expand Down
11 changes: 6 additions & 5 deletions src/pl_thread_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,14 @@ static inline int pl_thread_join(pl_thread thread)
return 0;
}

// Returns true, if slept full time
// Returns true if slept the full time, false otherwise
static inline bool pl_thread_sleep(double t)
{
if (t <= 0.0)
// Time is expected in 100 nanosecond intervals.
// Negative values indicate relative time.
LARGE_INTEGER time = { .QuadPart = -(LONGLONG) (t * 1e7) };

if (time.QuadPart >= 0)
return true;

bool ret = false;
Expand All @@ -164,9 +168,6 @@ static inline bool pl_thread_sleep(double t)
if (!timer)
goto end;

// Time is expected in 100 nanosecond intervals.
// Negative values indicate relative time.
LARGE_INTEGER time = (LARGE_INTEGER){ .QuadPart = -(t * 1e7) };
if (!SetWaitableTimer(timer, &time, 0, NULL, NULL, 0))
goto end;

Expand Down

0 comments on commit abf34ba

Please sign in to comment.