Small fixes to stdlib. (#1247)

Small fixes to stdlib. Match the signature of `NativeConditionVariable.wait_timeout` and `NativeMutex.lock_timeout` of thread_win32.c3 to `ConditionVariable.wait_timeout` and `TimedMutex.lock_timeout` to avoid casting errors. Add `time::us`.
This commit is contained in:
Christian Buttner
2024-07-20 19:19:16 +02:00
committed by GitHub
parent 480325177c
commit edc55a2afd
7 changed files with 19 additions and 10 deletions

View File

@@ -62,7 +62,7 @@ fn void! NativeMutex.lock_timeout(&self, ulong ms)
{
if (!ms) break;
ulong sleep = min(5, ms);
if (!libc::nanosleep(&& TimeSpec { .s = 0, .ns = (CLong)sleep * 1000_000 }, null)) return ThreadFault.LOCK_FAILED?;
if (!libc::nanosleep(&&time::ms(ms).to_timespec(), null)) return ThreadFault.LOCK_FAILED?;
ms -= sleep;
}
switch (result)

View File

@@ -90,8 +90,9 @@ fn void! NativeMutex.lock(&mtx)
/**
* @require mtx.timed "Only available for timed locks"
**/
fn void! NativeMutex.lock_timeout(&mtx, usz ms)
fn void! NativeMutex.lock_timeout(&mtx, ulong ms)
{
if (ms > uint.max) ms = uint.max;
switch (win32::waitForSingleObject(mtx.handle, (uint)ms))
{
case win32::WAIT_OBJECT_0:
@@ -244,9 +245,10 @@ fn void! NativeConditionVariable.wait(&cond, NativeMutex* mtx) @inline
return timedwait(cond, mtx, win32::INFINITE) @inline;
}
fn void! NativeConditionVariable.wait_timeout(&cond, NativeMutex* mtx, uint time) @inline
fn void! NativeConditionVariable.wait_timeout(&cond, NativeMutex* mtx, ulong ms) @inline
{
return timedwait(cond, mtx, time) @inline;
if (ms > uint.max) ms = uint.max;
return timedwait(cond, mtx, (uint)ms) @inline;
}
fn void! NativeThread.create(&thread, ThreadFn func, void* args)