#include <libkern/OSAtomicQueue.h>
libkern/OSAtomicQueue.h
@header Lockless atomic enqueue and dequeue
These routines manipulate singly-linked LIFO lists.
typedefOSQueueHead
| void * | opaque1 | |
| long | opaque2 |
macroOS_ATOMIC_QUEUE_INIT
@abstract The initialization vector for a queue head.
#define OS_ATOMIC_QUEUE_INIT { NULL, 0 }functionOSAtomicEnqueue
__OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_4_0) void OSAtomicEnqueue(OSQueueHead *__list, void *__new, size_t __offset)
@abstract Enqueue an element onto a list.
@discussion Memory barriers are incorporated as needed to permit thread-safe access
to the queue element.
@param __list
The list on which you want to enqueue the element.
@param __new
The element to add.
@param __offset
The "offset" parameter is the offset (in bytes) of the link field
from the beginning of the data structure being queued (<code>__new</code>).
The link field should be a pointer type.
The <code>__offset</code> value needs to be same for all enqueuing and
dequeuing operations on the same list, even if different structure types
are enqueued on that list. The use of <code>offsetset()</code>, defined in
<code>stddef.h</code> is the common way to specify the <code>__offset</code>
value.
man page · May 26, 2004
OSAtomicEnqueue(3) — atomic lockless queuesfunctionOSAtomicDequeue
__OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_4_0) void* OSAtomicDequeue(OSQueueHead *__list, size_t __offset)
@abstract Dequeue an element from a list.
@discussion Memory barriers are incorporated as needed to permit thread-safe access
to the queue element.
@param __list
The list from which you want to dequeue an element.
@param __offset
The "offset" parameter is the offset (in bytes) of the link field
from the beginning of the data structure being dequeued (<code>__new</code>).
The link field should be a pointer type.
The <code>__offset</code> value needs to be same for all enqueuing and
dequeuing operations on the same list, even if different structure types
are enqueued on that list. The use of <code>offsetset()</code>, defined in
<code>stddef.h</code> is the common way to specify the <code>__offset</code>
value.
IMPORTANT: the memory backing the link field of a queue element must not be
unmapped after OSAtomicDequeue() returns until all concurrent calls to
OSAtomicDequeue() for the same list on other threads have also returned,
as they may still be accessing that memory location.
@result Returns the most recently enqueued element, or <code>NULL</code> if the
list is empty.
man page · May 26, 2004
OSAtomicDequeue(3) — atomic lockless queues