]> git.saurik.com Git - apple/libplatform.git/blame - man/atomic.3
libplatform-254.40.4.tar.gz
[apple/libplatform.git] / man / atomic.3
CommitLineData
ada7c492
A
1.Dd May 26, 2004
2.Dt ATOMIC 3
3.Os Darwin
4.Sh NAME
5.Nm OSAtomicEnqueue ,
6.Nm OSAtomicDequeue
7.Nd atomic lockless queues
8.Sh SYNOPSIS
9.In libkern/OSAtomic.h
10.Ft void
11.Fn OSAtomicEnqueue "OSQueueHead *list" "void *new" "size_t offset"
12.Ft void*
13.Fn OSAtomicDequeue "OSQueueHead *list" "size_t offset"
14.Sh DESCRIPTION
15The routines
16.Fn OSAtomicEnqueue
17and
18.Fn OSAtomicDequeue
19operate on singly linked LIFO queues. Ie, a dequeue operation will return the
20most recently enqueued element, or NULL if the list is empty. The operations
21are lockless, and barriers are used as necessary to permit thread-safe access to
22the queue element.
23.Fa offset
24is the offset in bytes to the link field in the queue element.
25.Pp
26.Bf -symbolic
27Important: the memory backing the link field of a queue element must not be
28unmapped after
29.Fn OSAtomicDequeue
30returns until all concurrent calls to
31.Fn OSAtomicDequeue
32for the same list on other threads have also returned, as they may still be
33accessing that memory location.
34.Ef
35.Sh EXAMPLES
36.Bd -literal -offset indent
37 typedef struct elem {
38 long data1;
39 struct elem *link;
40 int data2;
41 } elem_t;
42
43 elem_t fred, mary, *p;
44
45 OSQueueHead q = OS_ATOMIC_QUEUE_INIT;
46
47 OSAtomicEnqueue( &q, &fred, offsetof(elem_t,link) );
48 OSAtomicEnqueue( &q, &mary, offsetof(elem_t,link) );
49
50 p = OSAtomicDequeue( &q, offsetof(elem_t,link) );
51
52.Ed
53In this example, the call of
54.Fn OSAtomicDequeue
55will return a ptr to mary.
56.Sh RETURN VALUES
57The dequeue operation returns the most recently enqueued element, or NULL if the list in empty.
58.Sh SEE ALSO
e45b4692 59.Xr stdatomic 3 ,
ada7c492
A
60.Xr atomic_deprecated 3 ,
61.Xr spinlock_deprecated 3
62.Sh HISTORY
63These functions first appeared in Mac OS 10.5 (Leopard).