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

sync: new_mutex() and new_waitgroup()

This commit is contained in:
Delyan Angelov
2019-10-25 17:24:40 +03:00
committed by Alexander Medvednikov
parent e04c4ad852
commit 32b3611026
4 changed files with 41 additions and 9 deletions

View File

@@ -4,12 +4,19 @@
module sync
//[init_with=new_waitgroup] // TODO: implement support for init_with struct attribute, and disallow WaitGroup{} from outside the sync.new_waitgroup() function.
pub struct WaitGroup {
mut:
mu Mutex
active int
}
pub fn new_waitgroup() WaitGroup {
mut w := WaitGroup{}
w.mu = sync.new_mutex()
return w
}
pub fn (wg mut WaitGroup) add(delta int) {
wg.mu.lock()
wg.active += delta