mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
sync: channel implementation (#6074)
This commit is contained in:
parent
09f1362305
commit
863cf8af60
15 changed files with 1532 additions and 51 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue