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:
committed by
Alexander Medvednikov
parent
e04c4ad852
commit
32b3611026
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user