mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Use WaitOnAddress instead of RtlWaitOnAddress
This commit is contained in:
@@ -5,40 +5,32 @@ package sync2
|
|||||||
import "core:time"
|
import "core:time"
|
||||||
|
|
||||||
foreign import Synchronization "system:Synchronization.lib"
|
foreign import Synchronization "system:Synchronization.lib"
|
||||||
foreign import NtDll "system:NtDll.lib"
|
|
||||||
|
|
||||||
@(default_calling_convention="stdcall")
|
|
||||||
foreign NtDll {
|
|
||||||
RtlWaitOnAddress :: proc(Address: rawptr, CompareAddress: rawptr, AddressSize: uint, Timeout: ^i64) -> b32 ---
|
|
||||||
}
|
|
||||||
|
|
||||||
@(default_calling_convention="stdcall")
|
@(default_calling_convention="stdcall")
|
||||||
foreign Synchronization {
|
foreign Synchronization {
|
||||||
|
WaitOnAddress :: proc(Address: rawptr, CompareAddress: rawptr, AddressSize: uint, Timeout: u32) -> b32 ---
|
||||||
WakeByAddressSingle :: proc(Address: rawptr) ---
|
WakeByAddressSingle :: proc(Address: rawptr) ---
|
||||||
WakeByAddressAll :: proc(Address: rawptr) ---
|
WakeByAddressAll :: proc(Address: rawptr) ---
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_futex_wait :: proc(f: ^Futex, expect: u32) -> bool {
|
_futex_wait :: proc(f: ^Futex, expect: u32) -> bool {
|
||||||
expect := expect
|
expect := expect
|
||||||
ok := RtlWaitOnAddress(f, &expect, size_of(expect), nil)
|
return bool(WaitOnAddress(f, &expect, size_of(expect), ~u32(0)))
|
||||||
return bool(ok)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_futex_wait_with_timeout :: proc(f: ^Futex, expect: u32, duration: time.Duration) -> bool {
|
_futex_wait_with_timeout :: proc(f: ^Futex, expect: u32, duration: time.Duration) -> bool {
|
||||||
expect := expect
|
expect := expect
|
||||||
|
if duration <= 0 {
|
||||||
timeout: i64
|
return bool(WaitOnAddress(f, &expect, size_of(expect), ~u32(0)))
|
||||||
timeout_ptr: ^i64
|
|
||||||
if duration > 0 {
|
|
||||||
// In 100 ns units
|
|
||||||
timeout = i64(timeout)/100
|
|
||||||
timeout_ptr = &timeout
|
|
||||||
}
|
}
|
||||||
\
|
|
||||||
ok := RtlWaitOnAddress(f, &expect, size_of(expect), timeout_ptr)
|
timeout := ~u32(0)
|
||||||
return bool(ok)
|
if duration > 0 {
|
||||||
|
timeout = u32(timeout/1e6)
|
||||||
|
}
|
||||||
|
return bool(WaitOnAddress(f, &expect, size_of(expect), timeout))
|
||||||
}
|
}
|
||||||
|
|
||||||
_futex_wake_single :: proc(f: ^Futex) {
|
_futex_wake_single :: proc(f: ^Futex) {
|
||||||
|
|||||||
@@ -154,6 +154,9 @@ cond_wait :: proc(c: ^Cond, m: ^Mutex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cond_wait_with_timeout :: proc(c: ^Cond, m: ^Mutex, duration: time.Duration) -> bool {
|
cond_wait_with_timeout :: proc(c: ^Cond, m: ^Mutex, duration: time.Duration) -> bool {
|
||||||
|
if duration <= 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return _cond_wait_with_timeout(c, m, duration)
|
return _cond_wait_with_timeout(c, m, duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,7 +218,7 @@ futex_wait_with_timeout :: proc(f: ^Futex, expected: u32, duration: time.Duratio
|
|||||||
if u32(atomic_load(f)) != expected {
|
if u32(atomic_load(f)) != expected {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if duration == 0 {
|
if duration <= 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user