Glossary
ipc_mqueue
The per-port message queue and wait set. Receives appended kmsgs, blocks threads in mach_msg_receive, wakes them when a message arrives.
An ipc_mqueue is the kernel structure embedded in every Mach port that holds the queue of in-flight messages and the set of threads waiting on it.
apple-oss-distributions/xnuosfmk/ipc/ipc_mqueue.hipc_mqueue structure — FIFO + wait set.View on GitHub(line —) apple-oss-distributions/xnuosfmk/ipc/ipc_mqueue.cpost / receive / wakeup — the mqueue operations.View on GitHub(line —)
Three operations matter:
- post — append a kmsg to the queue. If any thread is sleeping on the port's wait set, hand it the message directly without intermediate dequeue.
- receive — try to pull the head kmsg. If empty and the caller didn't pass
MACH_RCV_TIMEOUT=0, block on the wait set. - wakeup — used internally to nudge waiters when something changes (a send right was deallocated, the port was destroyed, etc.).
The mqueue also participates in Mach port sets — a single receive can block on a set of mqueues, the foundation of reactor-style IPC patterns.
When the last send right to a port is dropped and the queue is empty, the kernel can fire MACH_NOTIFY_NO_SENDERS to the receive-right holder, who knows no future messages can arrive.
See also: kmsg, Mach port, Mach IPC internals.