Skip to content

Commit eed9335

Browse files
madsmtmDetegr
authored andcommitted
Use dispatch2
1 parent 7977854 commit eed9335

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ rust-version = "1.69.0"
1818
nix = { version = "0.30", default-features = false, features = ["signal"]}
1919

2020
[target.'cfg(target_vendor = "apple")'.dependencies]
21-
dispatch = "0.2"
21+
dispatch2 = "0.3"
2222

2323
[target.'cfg(windows)'.dependencies]
2424
windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_System_Threading", "Win32_Security", "Win32_System_Console"] }

src/platform/unix/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,22 @@ mod implementation {
3232

3333
#[cfg(target_vendor = "apple")]
3434
mod implementation {
35-
static mut SEMAPHORE: dispatch::ffi::dispatch_semaphore_t = std::ptr::null_mut();
35+
use dispatch2::{DispatchRetained, DispatchSemaphore, DispatchTime};
36+
37+
static mut SEMAPHORE: Option<DispatchRetained<DispatchSemaphore>> = None;
3638

3739
pub unsafe fn sem_init() {
38-
SEMAPHORE = dispatch::ffi::dispatch_semaphore_create(0);
40+
SEMAPHORE = Some(DispatchSemaphore::new(0));
3941
}
4042

43+
#[allow(static_mut_refs)]
4144
pub unsafe fn sem_post() {
42-
dispatch::ffi::dispatch_semaphore_signal(SEMAPHORE);
45+
SEMAPHORE.as_deref().unwrap().signal();
4346
}
4447

48+
#[allow(static_mut_refs)]
4549
pub unsafe fn sem_wait_forever() {
46-
dispatch::ffi::dispatch_semaphore_wait(SEMAPHORE, dispatch::ffi::DISPATCH_TIME_FOREVER);
50+
SEMAPHORE.as_deref().unwrap().wait(DispatchTime::FOREVER);
4751
}
4852
}
4953

0 commit comments

Comments
 (0)