plat/apple_thread.rs (Apple)#
Source: lib/plat/apple_thread.rs
apple_thread -- threads (pthreads), semaphores (libdispatch), the wake-up of the UI thread, system
information and the date on macOS and iOS (the same functions as linux_thread.rs)
A dispatch semaphore is created at 0 and posted to its initial count: libdispatch ends the process
when a semaphore is freed with a count below the one it was created with. The wake-up is a
non-blocking pipe: wait_events polls it (headless), a window backend will watch it next to its
own events (AP4).
struct Thread(usize)a thread started by thread_spawn; join it to wait for its endfn thread_spawn(stack: usize, f: Start) -> Option<Thread>run f on a new thread with stack bytes of stack (0 = 1 MB) [plat_thread_create]
impl Thread
fn join(self)wait until the thread has ended [plat_thread_join]fn thread_yield()give the rest of the time slice away [plat_thread_yield]struct Sem(*mut c_void)a counting semaphore
impl Sem
fn new(initial: u32) -> Option<Sem>fn post(&self, n: u32)add n units, wake sleepers (0: nothing)fn wait(&self, ms: i32) -> booltake one unit: true taken, false timeout (ms -1 = forever, 0 = only try)fn wake()any thread: make the UI thread's wait return with E_WAKE (coalesced) [plat_wake]fn wait_events(deadline_us: u64, on_event: &mut dyn FnMut(&Event)) -> u32headless wait (no display): until a wake-up (E_WAKE to on_event, returns 1) or the deadline in time_us() (0 = only poll, u64::MAX = forever; returns 0)fn cpu_count() -> u32CPUs online, >= 1 [plat_cpu_count]fn mem_total() -> u64physical memory in bytes (hw.memsize), 0 unknown [plat_mem_total]fn date() -> (Date, bool)the date and time in UTC (as linux_thread.rs: no time zone database); the flag is true (UTC) [plat_date]