7 .Nd atomic enqueue and dequeue on a singly linked list
11 .In libkern/OSAtomic.h
13 .Fn OSAtomicEnqueue "void ** inList, void * inNewLink, size_t inOffset"
15 .Fn OSAtomicDequeue "void ** inList, size_t inOffset"
20 operate on zero-terminated singly-linked lists of structures whose
21 link field need not be the first element.
22 They are thread safe and incorporate memory barriers as required to
23 synchronize access to the shared memory. The list is last in, first out.
25 If thread safety is not a requirement, then the queue(3) package is more
26 flexible and possibly more efficient.
29 is the pointer to the head of the list. It is not a structure, and should be
33 is the offset within the structure of the link field.
35 is a pointer to the structure to be queued on the list:
36 .Bd -literal -offset indent
47 /* put n1 on the list */
48 OSAtomicEnqueue( (void**) &head, &n1, offsetof(node,link));
50 /* then put n2 on the list */
51 OSAtomicEnqueue( (void**) &head, &n2, offsetof(node,link));
53 /* dequeue n2 (ie, the node most recently added) */
54 p = OSAtomicDequeue( (void**) &head, offsetof(node,link));
58 returns a pointer to the node removed from the list, or