Skip to content

Commit

Permalink
win32: thread: rework the conversion to milliseconds in vlc_atomic_ti…
Browse files Browse the repository at this point in the history
…medwait()

First we convert the delay to int64_t (same width/sign as a vlc_tick_t) in
milliseconds from vlc_tick_t/time_t. Then we check it fits in a DWORD, aka an
unsigned long. If it doesn't fit we clip the value to ULONG_MAX.
  • Loading branch information
robUx4 committed Aug 19, 2022
1 parent 62a88b4 commit 0169059
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/win32/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,14 @@ int vlc_atomic_timedwait(void *addr, unsigned val, vlc_tick_t deadline)

if (delay < 0)
return ETIMEDOUT; // deadline passed
if (delay >= VLC_TICK_FROM_MS(LONG_MAX))
ms = LONG_MAX;

DWORD ms;
int64_t idelay = MS_FROM_VLC_TICK(delay);
static_assert(sizeof(unsigned long) <= sizeof(DWORD), "unknown max DWORD");
if (unlikely(idelay > ULONG_MAX))
ms = ULONG_MAX;
else
ms = MS_FROM_VLC_TICK(delay);
ms = idelay;

if (WaitOnAddress(addr, &val, sizeof (val), ms))
return 0;
Expand Down

0 comments on commit 0169059

Please sign in to comment.