sync: fix build on Windows

pull/4210/head
Alexey 2020-04-02 21:58:07 +03:00 committed by GitHub
parent 0e6fe0a4f2
commit 5b6ec8996a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 23 deletions

View File

@ -26,19 +26,6 @@ enum MutexState {
destroyed destroyed
} }
const (
INFINITE = 0xffffffff
)
// Ref - https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitforsingleobject#return-value
const (
WAIT_ABANDONED = 0x00000080
WAIT_IO_COMPLETION = 0x000000C0
WAIT_OBJECT_0 = 0x00000000
WAIT_TIMEOUT = 0x00000102
WAIT_FAILED = 0xFFFFFFFF
)
pub fn new_mutex() &Mutex { pub fn new_mutex() &Mutex {
sm := &Mutex{} sm := &Mutex{}
unsafe { unsafe {
@ -61,23 +48,27 @@ pub fn (m mut Mutex) lock() {
return return
} }
} }
state := C.WaitForSingleObject(m.mx, INFINITE) // infinite wait state := C.WaitForSingleObject(m.mx, C.INFINITE) // infinite wait
/* TODO fix match/enum combo /* TODO fix match/enum combo
m.state = match state { m.state = match state {
WAIT_ABANDONED { .abandoned } C.WAIT_ABANDONED { .abandoned }
WAIT_OBJECT_0 { .waiting } C.WAIT_OBJECT_0 { .waiting }
else { .broken } else { .broken }
} }
*/ */
mut s := MutexState.broken if state == C.WAIT_ABANDONED {
if state == WAIT_ABANDONED { s = .abandoned } m.state = .abandoned
else if state == WAIT_OBJECT_0 { s = .waiting } // FIXME Use C constant instead
m.state = s } else if state == 0 /* C.WAIT_OBJECT_0 */ {
m.state = .waiting
} else {
m.state = .broken
}
} }
pub fn (m mut Mutex) unlock() { pub fn (m mut Mutex) unlock() {
if m.state == .waiting { if m.state == .waiting {
if ReleaseMutex(m.mx) { if C.ReleaseMutex(m.mx) {
m.state = .broken m.state = .broken
return return
} }