7 .Nd atomic lockless queues
11 .Fn OSAtomicEnqueue "OSQueueHead *list" "void *new" "size_t offset"
13 .Fn OSAtomicDequeue "OSQueueHead *list" "size_t offset"
19 operate on singly linked LIFO queues. Ie, a dequeue operation will return the
20 most recently enqueued element, or NULL if the list is empty. The operations
21 are lockless, and barriers are used as necessary to permit thread-safe access to
24 is the offset in bytes to the link field in the queue element.
27 Important: the memory backing the link field of a queue element must not be
30 returns until all concurrent calls to
32 for the same list on other threads have also returned, as they may still be
33 accessing that memory location.
36 .Bd -literal -offset indent
43 elem_t fred, mary, *p;
45 OSQueueHead q = OS_ATOMIC_QUEUE_INIT;
47 OSAtomicEnqueue( &q, &fred, offsetof(elem_t,link) );
48 OSAtomicEnqueue( &q, &mary, offsetof(elem_t,link) );
50 p = OSAtomicDequeue( &q, offsetof(elem_t,link) );
53 In this example, the call of
55 will return a ptr to mary.
57 The dequeue operation returns the most recently enqueued element, or NULL if the list in empty.
60 .Xr atomic_deprecated 3 ,
61 .Xr spinlock_deprecated 3
63 These functions first appeared in Mac OS 10.5 (Leopard).