sync: fix build on Windows
parent
0e6fe0a4f2
commit
5b6ec8996a
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue