Skip to content

Commit 89ca0d1

Browse files
committed
Add test of recursive mutex using libc FFI
1 parent ba2d952 commit 89ca0d1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/run-pass/sync.rs

+23
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fn main() {
88
test_mutex();
99
#[cfg(not(target_os = "windows"))] // TODO: implement RwLock on Windows
1010
{
11+
test_mutex_libc_recursive();
1112
test_rwlock_stdlib();
1213
test_rwlock_libc_init();
1314
test_rwlock_libc_static_initializer();
@@ -24,6 +25,28 @@ fn test_mutex() {
2425
drop(m);
2526
}
2627

28+
#[cfg(not(target_os = "windows"))]
29+
fn test_mutex_libc_recursive() {
30+
unsafe {
31+
let mut attr: libc::pthread_mutexattr_t = std::mem::zeroed();
32+
assert_eq!(libc::pthread_mutexattr_init(&mut attr as *mut _), 0);
33+
assert_eq!(libc::pthread_mutexattr_settype(&mut attr as *mut _, libc::PTHREAD_MUTEX_RECURSIVE), 0);
34+
let mut mutex: libc::pthread_mutex_t = std::mem::zeroed();
35+
assert_eq!(libc::pthread_mutex_init(&mut mutex as *mut _, &mut attr as *mut _), 0);
36+
assert_eq!(libc::pthread_mutex_lock(&mut mutex as *mut _), 0);
37+
assert_eq!(libc::pthread_mutex_trylock(&mut mutex as *mut _), 0);
38+
assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0);
39+
assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0);
40+
assert_eq!(libc::pthread_mutex_trylock(&mut mutex as *mut _), 0);
41+
assert_eq!(libc::pthread_mutex_lock(&mut mutex as *mut _), 0);
42+
assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0);
43+
assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0);
44+
assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), libc::EPERM);
45+
assert_eq!(libc::pthread_mutex_destroy(&mut mutex as *mut _), 0);
46+
assert_eq!(libc::pthread_mutexattr_destroy(&mut attr as *mut _), 0);
47+
}
48+
}
49+
2750
#[cfg(not(target_os = "windows"))]
2851
fn test_rwlock_stdlib() {
2952
let rw = RwLock::new(0);

0 commit comments

Comments
 (0)