]> git.saurik.com Git - apple/libdispatch.git/blame - man/dispatch_object.3
libdispatch-84.5.5.tar.gz
[apple/libdispatch.git] / man / dispatch_object.3
CommitLineData
0ab74447
A
1.\" Copyright (c) 2008-2009 Apple Inc. All rights reserved.
2.Dd May 1, 2009
3.Dt dispatch_object 3
4.Os Darwin
5.Sh NAME
6.Nm dispatch_object
7.Nd General manipulation of dispatch objects
8.Sh SYNOPSIS
9.Fd #include <dispatch/dispatch.h>
10.Ft void
11.Fo dispatch_retain
12.Fa "dispatch_object_t object"
13.Fc
14.Ft void
15.Fo dispatch_release
16.Fa "dispatch_object_t object"
17.Fc
18.Ft void
19.Fo dispatch_suspend
20.Fa "dispatch_object_t object"
21.Fc
22.Ft void
23.Fo dispatch_resume
24.Fa "dispatch_object_t object"
25.Fc
26.Ft "void *"
27.Fo dispatch_get_context
28.Fa "dispatch_object_t object"
29.Fc
30.Ft void
31.Fo dispatch_set_context
32.Fa "dispatch_object_t object"
33.Fa "void *context"
34.Fc
35.Ft void
36.Fo dispatch_set_finalizer_f
37.Fa "dispatch_object_t object"
38.Fa "dispatch_function_t finalizer"
39.Fc
40.Sh DESCRIPTION
41Dispatch objects share functions for coordinating memory management, suspension,
42cancellation and context pointers. While all dispatch objects are retainable,
43not all objects support suspension, context pointers or finalizers (currently
44only queues and sources support these additional interfaces).
45.Sh MEMORY MANGEMENT
46Objects returned by creation functions in the dispatch framework may be
47uniformly retained and released with the functions
48.Fn dispatch_retain
49and
50.Fn dispatch_release
51respectively.
52.Pp
53The dispatch framework does not guarantee that any given client has the last or
54only reference to a given object. Objects may be retained internally by the
55system.
56.Sh SUSPENSION
57The invocation of blocks on dispatch queues or dispatch sources may be suspended
58or resumed with the functions
59.Fn dispatch_suspend
60and
61.Fn dispatch_resume
62respectively.
63The dispatch framework always checks the suspension status before executing a
64block, but such changes never affect a block during execution (non-preemptive).
65Therefore the suspension of an object is asynchronous, unless it is performed
66from the context of the target queue for the given object.
67The result of suspending or resuming an object that is not a dispatch queue or
68a dispatch source is undefined.
69.Pp
70.Em Important :
71suspension applies to all aspects of the dispatch object life cycle, including
72the finalizer function and cancellation handler. Therefore it is important to
73balance calls to
74.Fn dispatch_suspend
75and
76.Fn dispatch_resume
77such that the dispatch object is fully resumed when the last reference is
78released. The result of releasing all references to a dispatch object while in
79a suspended state is undefined.
80.Sh CONTEXT POINTERS
81Dispatch queues and sources support supplemental context pointers. The value of
82the context point may be retrieved and updated with
83.Fn dispatch_get_context
84and
85.Fn dispatch_set_context
86respectively.
87The
88.Fn dispatch_set_finalizer_f
89specifies an optional per-object finalizer function to that is invoked
90asynchronously when the last reference to the object is released. This gives the
91application an opportunity to free the context data associated with the object.
92.Pp
93The result of getting or setting the context of an object that is not a
94dispatch queue or a dispatch source is undefined.
95.Sh SEE ALSO
96.Xr dispatch_group_create 3 ,
97.Xr dispatch_queue_create 3 ,
98.Xr dispatch_semaphore_create 3 ,
99.Xr dispatch_source_create 3