Skip to content

Commit 341e79f

Browse files
authored
sync: fix FreeBSD implementation of sync functions (#20483)
1 parent 9109b23 commit 341e79f

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

vlib/sync/mutex_test.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ fn test_try_lock_mutex() {
3535
try_fail := mx.try_lock()
3636
assert try_fail == false
3737
mx.unlock()
38-
try_sucess := mx.try_lock()
39-
assert try_sucess == true
40-
mx.unlock() // you must unlock it, after try_lock sucess
38+
try_success := mx.try_lock()
39+
assert try_success == true
40+
mx.unlock() // you must unlock it, after try_lock success
4141
mx.destroy()
4242
}

vlib/sync/rwmutex_test.v

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ fn test_try_lock_rwmutex() {
5151

5252
mx.unlock()
5353

54-
// try_rlock will always sucess when mx unlocked,
54+
// try_rlock will always succeed when mx unlocked,
5555
// multiple try_rlock can apply to the same mx
56-
try_sucess_reading2 := mx.try_rlock()
57-
try_sucess_reading3 := mx.try_rlock()
58-
assert try_sucess_reading2 == true
59-
assert try_sucess_reading3 == true
56+
try_success_reading2 := mx.try_rlock()
57+
try_success_reading3 := mx.try_rlock()
58+
assert try_success_reading2 == true
59+
assert try_success_reading3 == true
6060

6161
// if mx is rlocked, then the try_wlock will fail
6262
try_fail_writing2 := mx.try_wlock()
@@ -65,10 +65,10 @@ fn test_try_lock_rwmutex() {
6565
mx.runlock()
6666
mx.runlock() // you must release rlock mutiple times, as it was rlocked multiple times
6767

68-
// after mx release all rlock, try_wlock will sucess
69-
try_sucess_writing3 := mx.try_wlock()
70-
assert try_sucess_writing3 == true
68+
// after mx release all rlock, try_wlock will succeed
69+
try_success_writing3 := mx.try_wlock()
70+
assert try_success_writing3 == true
7171

72-
mx.unlock() // you must unlock it, after try_wlock sucess
72+
mx.unlock() // you must unlock it, after try_wlock success
7373
mx.destroy()
7474
}

vlib/sync/sync_freebsd.c.v

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,25 @@ pub struct C.pthread_mutex {}
4141

4242
pub struct C.pthread_rwlock {}
4343

44-
pub struct C.pthread_rwlockattr {}
44+
@[typedef]
45+
pub struct C.pthread_rwlockattr_t {}
4546

4647
@[typedef]
4748
pub struct C.sem_t {}
4849

4950
// [init_with=new_mutex] // TODO: implement support for this struct attribute, and disallow Mutex{} from outside the sync.new_mutex() function.
51+
@[heap]
5052
pub struct Mutex {
5153
mutex &C.pthread_mutex = unsafe { nil }
5254
}
5355

56+
@[heap]
5457
pub struct RwMutex {
5558
mutex &C.pthread_rwlock = unsafe { nil }
5659
}
5760

5861
struct RwMutexAttr {
59-
attr &C.pthread_rwlockattr = unsafe { nil }
62+
attr C.pthread_rwlockattr_t
6063
}
6164

6265
@[heap]

0 commit comments

Comments
 (0)