diff --git a/lib/std/core/env.c3 b/lib/std/core/env.c3 index 4b6ee4605..79118e13d 100644 --- a/lib/std/core/env.c3 +++ b/lib/std/core/env.c3 @@ -116,8 +116,8 @@ enum ArchType const OsType OS_TYPE = (OsType)$$OS_TYPE; const ArchType ARCH_TYPE = (ArchType)$$ARCH_TYPE; -const bool ARCH_32_BIT = $$REGISTER_SIZE == 4; -const bool ARCH_64_BIT = $$REGISTER_SIZE == 8; +const bool ARCH_32_BIT = $$REGISTER_SIZE == 32; +const bool ARCH_64_BIT = $$REGISTER_SIZE == 64; const bool LIBC = $$COMPILER_LIBC_AVAILABLE; const bool NO_LIBC = !$$COMPILER_LIBC_AVAILABLE; const CompilerOptLevel COMPILER_OPT_LEVEL = (CompilerOptLevel)$$COMPILER_OPT_LEVEL; diff --git a/lib/std/os/win32/winuser.c3 b/lib/std/os/win32/winuser.c3 index e8cca491d..6cd7021ec 100644 --- a/lib/std/os/win32/winuser.c3 +++ b/lib/std/os/win32/winuser.c3 @@ -131,7 +131,8 @@ extern fn Win32_BOOL showWindow(Win32_HWND, CInt) @extern("ShowWindow"); extern fn Win32_BOOL translateMessage(Win32_MSG* lpMsg) @extern("TranslateMessage"); extern fn Win32_BOOL updateWindow(Win32_HWND) @extern("UpdateWindow"); -macro getWindowLongPtr(Win32_HWND hWnd, CInt nIndex) { +macro getWindowLongPtr(Win32_HWND hWnd, CInt nIndex) +{ $if env::ARCH_64_BIT: return getWindowLongPtrW(hWnd, nIndex); $else @@ -139,7 +140,8 @@ macro getWindowLongPtr(Win32_HWND hWnd, CInt nIndex) { $endif } -macro setWindowLongPtr(Win32_HWND hWnd, CInt nIndex, dwNewLong) { +macro setWindowLongPtr(Win32_HWND hWnd, CInt nIndex, dwNewLong) +{ $if env::ARCH_64_BIT: return setWindowLongPtrW(hWnd, nIndex, dwNewLong); $else diff --git a/lib/std/threads/os/thread_posix.c3 b/lib/std/threads/os/thread_posix.c3 index 676fc0752..ff442ec8c 100644 --- a/lib/std/threads/os/thread_posix.c3 +++ b/lib/std/threads/os/thread_posix.c3 @@ -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) diff --git a/lib/std/threads/os/thread_win32.c3 b/lib/std/threads/os/thread_win32.c3 index 75f473ffe..d9f3fe385 100644 --- a/lib/std/threads/os/thread_win32.c3 +++ b/lib/std/threads/os/thread_win32.c3 @@ -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) diff --git a/lib/std/threads/thread.c3 b/lib/std/threads/thread.c3 index d6f1c9f92..5138548ff 100644 --- a/lib/std/threads/thread.c3 +++ b/lib/std/threads/thread.c3 @@ -53,9 +53,9 @@ macro void! ConditionVariable.wait(&cond, Mutex* mutex) { return NativeConditionVariable.wait((NativeConditionVariable*)cond, (NativeMutex*)mutex); } -macro void! ConditionVariable.wait_timeout(&cond, Mutex* mutex, ulong timeout) +macro void! ConditionVariable.wait_timeout(&cond, Mutex* mutex, ulong ms) { - return NativeConditionVariable.wait_timeout((NativeConditionVariable*)cond, (NativeMutex*)mutex, timeout); + return NativeConditionVariable.wait_timeout((NativeConditionVariable*)cond, (NativeMutex*)mutex, ms); } diff --git a/lib/std/time/time.c3 b/lib/std/time/time.c3 index 26bac8bbf..66f3ede35 100644 --- a/lib/std/time/time.c3 +++ b/lib/std/time/time.c3 @@ -6,6 +6,7 @@ distinct Duration = long; distinct Clock = ulong; distinct NanoDuration (Printable) = long; +const Duration US = 1; const Duration MS = 1_000; const Duration SEC = 1_000_000; const Duration MIN = 60 * SEC; @@ -15,6 +16,7 @@ const Duration WEEK = 7 * DAY; const Duration MONTH = 30 * WEEK; const Duration YEAR = 36525 * DAY / 100; +fn Duration us(long l) @inline => (Duration)l * US; fn Duration ms(long l) @inline => (Duration)l * MS; fn Duration sec(long l) @inline => (Duration)l * SEC; fn Duration min(long l) @inline => (Duration)l * MIN; diff --git a/releasenotes.md b/releasenotes.md index 333848b12..f38271770 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -61,6 +61,9 @@ - Insertion sort and counting sort added. - Added missing `mem` and `mem::allocator` functions for aligned allocations. - Added `new_init_with_array` and `temp_init_with_array` for List. +- Fixed posix `NativeMutex.lock_timeout`. +- Fixed `env::ARCH_32_BIT` and `env::ARCH_64_BIT`. +- Added `time::us`. ## 0.6.0 Change list