1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

sync: make Semaphore.*wait() robust against interrupts by signals (#10491)

This commit is contained in:
Uwe Krüger
2021-06-18 11:44:18 +02:00
committed by GitHub
parent a98d644637
commit 3f5aa5e634
5 changed files with 223 additions and 10 deletions

View File

@ -220,6 +220,13 @@ pub fn (mut sem Semaphore) timed_wait(timeout time.Duration) bool {
return res == 0
}
pub fn (mut sem Semaphore) destroy() bool {
return C.pthread_cond_destroy(&sem.cond) == 0 && C.pthread_mutex_destroy(&sem.mtx) == 0
pub fn (mut sem Semaphore) destroy() {
mut res := C.pthread_cond_destroy(&sem.cond)
if res == 0 {
res = C.pthread_mutex_destroy(&sem.mtx)
if res == 0 {
return
}
}
panic(unsafe { tos_clone(&byte(C.strerror(res))) })
}