use core::ffi::c_void;
#[derive(Debug, Clone, Copy)]
pub struct Executor {
pub identity: *const c_void,
pub implementation: *const c_void,
}
pub fn main_executor() -> Option<Executor> {
let result = unsafe { swift_runtime_sys::ConcurrencyThunks::swift_task_getMainExecutor() };
result.ok().map(|e| Executor {
identity: e.identity,
implementation: e.implementation,
})
}
pub fn current_executor() -> Option<Executor> {
let result = unsafe { swift_runtime_sys::ConcurrencyThunks::swift_task_getCurrentExecutor() };
result.ok().map(|e| Executor {
identity: e.identity,
implementation: e.implementation,
})
}
pub fn is_main_executor(executor: &Executor) -> Option<bool> {
let raw = swift_runtime_sys::ConcurrencyThunks::SerialExecutorRef {
identity: executor.identity,
implementation: executor.implementation,
};
unsafe { swift_runtime_sys::ConcurrencyThunks::swift_task_isMainExecutor(raw) }.ok()
}
#[derive(Debug, Clone, Copy)]
pub struct SwiftTime {
pub seconds: i64,
pub nanoseconds: i64,
}
pub fn continuous_time() -> Option<SwiftTime> {
let mut sec: i64 = 0;
let mut nsec: i64 = 0;
let result =
unsafe { swift_runtime_sys::ConcurrencyThunks::swift_get_time(&mut sec, &mut nsec, 1) };
result.ok().map(|_| SwiftTime {
seconds: sec,
nanoseconds: nsec,
})
}
pub fn suspending_time() -> Option<SwiftTime> {
let mut sec: i64 = 0;
let mut nsec: i64 = 0;
let result =
unsafe { swift_runtime_sys::ConcurrencyThunks::swift_get_time(&mut sec, &mut nsec, 2) };
result.ok().map(|_| SwiftTime {
seconds: sec,
nanoseconds: nsec,
})
}