mirror of
https://github.com/vlang/v.git
synced 2025-08-03 17:57:59 -04:00
sync: fix FreeBSD implementation of sync functions (#20483)
This commit is contained in:
parent
9109b23c76
commit
341e79fc63
@ -35,8 +35,8 @@ fn test_try_lock_mutex() {
|
|||||||
try_fail := mx.try_lock()
|
try_fail := mx.try_lock()
|
||||||
assert try_fail == false
|
assert try_fail == false
|
||||||
mx.unlock()
|
mx.unlock()
|
||||||
try_sucess := mx.try_lock()
|
try_success := mx.try_lock()
|
||||||
assert try_sucess == true
|
assert try_success == true
|
||||||
mx.unlock() // you must unlock it, after try_lock sucess
|
mx.unlock() // you must unlock it, after try_lock success
|
||||||
mx.destroy()
|
mx.destroy()
|
||||||
}
|
}
|
||||||
|
@ -51,12 +51,12 @@ fn test_try_lock_rwmutex() {
|
|||||||
|
|
||||||
mx.unlock()
|
mx.unlock()
|
||||||
|
|
||||||
// try_rlock will always sucess when mx unlocked,
|
// try_rlock will always succeed when mx unlocked,
|
||||||
// multiple try_rlock can apply to the same mx
|
// multiple try_rlock can apply to the same mx
|
||||||
try_sucess_reading2 := mx.try_rlock()
|
try_success_reading2 := mx.try_rlock()
|
||||||
try_sucess_reading3 := mx.try_rlock()
|
try_success_reading3 := mx.try_rlock()
|
||||||
assert try_sucess_reading2 == true
|
assert try_success_reading2 == true
|
||||||
assert try_sucess_reading3 == true
|
assert try_success_reading3 == true
|
||||||
|
|
||||||
// if mx is rlocked, then the try_wlock will fail
|
// if mx is rlocked, then the try_wlock will fail
|
||||||
try_fail_writing2 := mx.try_wlock()
|
try_fail_writing2 := mx.try_wlock()
|
||||||
@ -65,10 +65,10 @@ fn test_try_lock_rwmutex() {
|
|||||||
mx.runlock()
|
mx.runlock()
|
||||||
mx.runlock() // you must release rlock mutiple times, as it was rlocked multiple times
|
mx.runlock() // you must release rlock mutiple times, as it was rlocked multiple times
|
||||||
|
|
||||||
// after mx release all rlock, try_wlock will sucess
|
// after mx release all rlock, try_wlock will succeed
|
||||||
try_sucess_writing3 := mx.try_wlock()
|
try_success_writing3 := mx.try_wlock()
|
||||||
assert try_sucess_writing3 == true
|
assert try_success_writing3 == true
|
||||||
|
|
||||||
mx.unlock() // you must unlock it, after try_wlock sucess
|
mx.unlock() // you must unlock it, after try_wlock success
|
||||||
mx.destroy()
|
mx.destroy()
|
||||||
}
|
}
|
||||||
|
@ -41,22 +41,25 @@ pub struct C.pthread_mutex {}
|
|||||||
|
|
||||||
pub struct C.pthread_rwlock {}
|
pub struct C.pthread_rwlock {}
|
||||||
|
|
||||||
pub struct C.pthread_rwlockattr {}
|
@[typedef]
|
||||||
|
pub struct C.pthread_rwlockattr_t {}
|
||||||
|
|
||||||
@[typedef]
|
@[typedef]
|
||||||
pub struct C.sem_t {}
|
pub struct C.sem_t {}
|
||||||
|
|
||||||
// [init_with=new_mutex] // TODO: implement support for this struct attribute, and disallow Mutex{} from outside the sync.new_mutex() function.
|
// [init_with=new_mutex] // TODO: implement support for this struct attribute, and disallow Mutex{} from outside the sync.new_mutex() function.
|
||||||
|
@[heap]
|
||||||
pub struct Mutex {
|
pub struct Mutex {
|
||||||
mutex &C.pthread_mutex = unsafe { nil }
|
mutex &C.pthread_mutex = unsafe { nil }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@[heap]
|
||||||
pub struct RwMutex {
|
pub struct RwMutex {
|
||||||
mutex &C.pthread_rwlock = unsafe { nil }
|
mutex &C.pthread_rwlock = unsafe { nil }
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RwMutexAttr {
|
struct RwMutexAttr {
|
||||||
attr &C.pthread_rwlockattr = unsafe { nil }
|
attr C.pthread_rwlockattr_t
|
||||||
}
|
}
|
||||||
|
|
||||||
@[heap]
|
@[heap]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user