mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
sync: make new_mutex() and new_waitgroup() return &Mutex and &Waitgroup
This commit is contained in:

committed by
Alexander Medvednikov

parent
bc64263dd8
commit
0d52cc97e4
@@ -16,9 +16,8 @@ pub struct Mutex {
|
||||
mutex C.pthread_mutex_t
|
||||
}
|
||||
|
||||
pub fn new_mutex() Mutex {
|
||||
m := Mutex{
|
||||
}
|
||||
pub fn new_mutex() &Mutex {
|
||||
m := &Mutex{}
|
||||
C.pthread_mutex_init(&m.mutex, C.NULL)
|
||||
return m
|
||||
}
|
||||
|
@@ -39,8 +39,8 @@ const (
|
||||
WAIT_FAILED = 0xFFFFFFFF
|
||||
)
|
||||
|
||||
pub fn new_mutex() Mutex {
|
||||
sm := Mutex{}
|
||||
pub fn new_mutex() &Mutex {
|
||||
sm := &Mutex{}
|
||||
unsafe {
|
||||
mut m := sm
|
||||
m.mx = C.CreateMutex(0, false, 0)
|
||||
@@ -48,8 +48,8 @@ pub fn new_mutex() Mutex {
|
||||
m.state = .broken // handle broken and mutex state are broken
|
||||
return sm
|
||||
}
|
||||
return sm
|
||||
}
|
||||
return sm
|
||||
}
|
||||
|
||||
pub fn (m mut Mutex) lock() {
|
||||
|
@@ -5,15 +5,12 @@ 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
|
||||
mu &Mutex = &Mutex(0)
|
||||
active int
|
||||
}
|
||||
|
||||
pub fn new_waitgroup() WaitGroup {
|
||||
mut w := WaitGroup{
|
||||
}
|
||||
w.mu = sync.new_mutex()
|
||||
return w
|
||||
pub fn new_waitgroup() &WaitGroup {
|
||||
return &WaitGroup{mu: sync.new_mutex() }
|
||||
}
|
||||
|
||||
pub fn (wg mut WaitGroup) add(delta int) {
|
||||
|
Reference in New Issue
Block a user