mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix posix NativeConditionVariable.wait_timeout. (#1211)
Fix posix NativeConditionVariable.wait_timeout. TimeSpec::ns may not exceed one second.
This commit is contained in:
committed by
GitHub
parent
616bde2c4d
commit
83fe94d497
@@ -183,8 +183,8 @@ extern fn isz write(Fd fd, void* buffer, usz count) @if(!env::WIN32);
|
||||
|
||||
extern fn CFile fmemopen(void* ptr, usz size, ZString mode);
|
||||
extern fn isz getline(char** linep, usz* linecapp, CFile stream);
|
||||
extern fn int timespec_get(TimeSpec* ts, int base);
|
||||
extern fn int nanosleep(TimeSpec* req, TimeSpec* remaining);
|
||||
extern fn CInt timespec_get(TimeSpec* ts, CInt base);
|
||||
extern fn CInt nanosleep(TimeSpec* req, TimeSpec* remaining);
|
||||
extern fn ZString ctime(Time_t *timer);
|
||||
extern fn Time_t time(Time_t *timer);
|
||||
|
||||
|
||||
@@ -128,8 +128,9 @@ fn void! NativeConditionVariable.wait_timeout(&cond, NativeMutex* mtx, ulong ms)
|
||||
{
|
||||
TimeSpec now;
|
||||
if (libc::timespec_get(&now, libc::TIME_UTC) != libc::TIME_UTC) return ThreadFault.WAIT_FAILED?;
|
||||
now.s += (Time_t)(ms / 1000);
|
||||
now.ns += (CLong)((ms % 1000) * 1000_000);
|
||||
now.s += (Time_t)(ms / 1000 + now.ns / 1000_000_000);
|
||||
now.ns = now.ns % 1000_000_000;
|
||||
switch (posix::pthread_cond_timedwait(cond, &mtx.mutex, &now))
|
||||
{
|
||||
case errno::ETIMEDOUT:
|
||||
|
||||
Reference in New Issue
Block a user