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

sync: channel implementation (#6074)

This commit is contained in:
Uwe Krüger
2020-08-06 15:28:19 +02:00
committed by GitHub
parent 09f1362305
commit 863cf8af60
15 changed files with 1532 additions and 51 deletions

View File

@ -128,9 +128,14 @@ pub fn (mut m Mutex) destroy() {
m.state = .destroyed // setting up reference to invalid state
}
[inline]
pub fn new_semaphore() Semaphore {
return new_semaphore_init(0)
}
pub fn new_semaphore_init(n u32) Semaphore {
return Semaphore{
sem: SHANDLE(C.CreateSemaphore(0, 0, C.INT32_MAX, 0))
sem: SHANDLE(C.CreateSemaphore(0, n, C.INT32_MAX, 0))
}
}
@ -149,3 +154,7 @@ pub fn (s Semaphore) try_wait() bool {
pub fn (s Semaphore) timed_wait(timeout time.Duration) bool {
return C.WaitForSingleObject(s.sem, timeout / time.millisecond) == 0
}
pub fn (s Semaphore) destroy() bool {
return C.CloseHandle(s.sem) != 0
}