Skip to content

Commit 927af48

Browse files
committed
Rename some Dispatch types to match Swift
DispatchTime, DispatchQoS, DispatchAutoReleaseFrequency, DispatchBlock, and a few DispatchIO* types. At the same time, remove the `dispatch2::ffi` module, it is now mostly redundant, and it's a bad idea to split the API in two like this: we should instead work towards mapping everything, so that there isn't a need! Part of #77.
1 parent 48936df commit 927af48

File tree

17 files changed

+488
-465
lines changed

17 files changed

+488
-465
lines changed

crates/dispatch2/TODO.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,14 @@
99
- Safe wrapper for ``dispatch_get_context/dispatch_set_context`` (quite impossible without big overhead => wrap dispatch object destructor to release the boxed value)
1010
- All blocks related bindings and ``dispatch_block_*`` functions with compat with ``block2`` on Apple platforms.
1111
- Integrate conversion from SystemTime to dispatch_time_t via dispatch_walltime and safe APIs using that.
12+
- `dispatch/introspection.h`
13+
14+
15+
NOTES:
16+
- suspended object must not be released
17+
- Closure?
18+
- Resume drop guard (that holds a reference count, ensuring not releasing even if leaked)
19+
- Activation: "Releasing the last reference count on an inactive object is undefined."
20+
- Rename `DispatchQoS` etc. to fit Swift naming
21+
22+
- Dispatch blocks

crates/dispatch2/src/ffi.rs

Lines changed: 0 additions & 228 deletions
This file was deleted.

crates/dispatch2/src/group.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use alloc::boxed::Box;
22
use core::ffi::c_void;
3-
use core::time::Duration;
43

5-
use crate::{DispatchObject, DispatchQueue, DispatchRetained};
4+
use crate::generated::{dispatch_group_enter, dispatch_group_wait};
5+
use crate::{DispatchObject, DispatchQueue, DispatchRetained, DispatchTime};
66

77
use super::utils::function_wrapper;
8-
use super::{ffi::*, WaitError};
8+
use super::WaitError;
99

1010
dispatch_object!(
1111
/// Dispatch group.
@@ -34,16 +34,8 @@ impl DispatchGroup {
3434
///
3535
/// # Errors
3636
///
37-
/// Return [WaitError::TimeOverflow] if the passed ``timeout`` is too big.
38-
///
3937
/// Return [WaitError::Timeout] in case of timeout.
40-
pub fn wait(&self, timeout: Option<Duration>) -> Result<(), WaitError> {
41-
let timeout = if let Some(timeout) = timeout {
42-
dispatch_time_t::try_from(timeout).map_err(|_| WaitError::TimeOverflow)?
43-
} else {
44-
DISPATCH_TIME_FOREVER
45-
};
46-
38+
pub fn wait(&self, timeout: DispatchTime) -> Result<(), WaitError> {
4739
let result = dispatch_group_wait(self, timeout);
4840

4941
match result {

crates/dispatch2/src/io.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![allow(missing_docs)] // TODO
2+
use core::ffi::{c_long, c_ulong};
3+
14
dispatch_object!(
25
/// Dispatch IO.
36
#[doc(alias = "dispatch_io_t")]
@@ -6,3 +9,28 @@ dispatch_object!(
69
);
710

811
dispatch_object_not_data!(unsafe DispatchIO);
12+
13+
enum_with_val! {
14+
#[doc(alias = "dispatch_io_type_t")]
15+
#[derive(PartialEq, Eq, Clone, Copy)]
16+
pub struct DispatchIOStreamType(pub c_ulong) {
17+
DISPATCH_IO_STREAM = 0,
18+
DISPATCH_IO_RANDOM = 1,
19+
}
20+
}
21+
22+
enum_with_val! {
23+
#[doc(alias = "dispatch_io_close_flags_t")]
24+
#[derive(PartialEq, Eq, Clone, Copy)]
25+
pub struct DispatchIOCloseFlags(pub c_ulong) {
26+
DISPATCH_IO_STOP = 0x1,
27+
}
28+
}
29+
30+
enum_with_val! {
31+
#[doc(alias = "dispatch_io_interval_flags_t")]
32+
#[derive(PartialEq, Eq, Clone, Copy)]
33+
pub struct DispatchIOIntervalFlags(pub c_long) {
34+
DISPATCH_IO_STRICT_INTERVAL = 0x1,
35+
}
36+
}

0 commit comments

Comments
 (0)