]> git.saurik.com Git - apple/libdispatch.git/blob - man/dispatch_object.3
libdispatch-187.5.tar.gz
[apple/libdispatch.git] / man / dispatch_object.3
1 .\" Copyright (c) 2008-2010 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
41 Dispatch objects share functions for coordinating memory management, suspension,
42 cancellation and context pointers. While all dispatch objects are retainable,
43 not all objects support suspension, context pointers or finalizers (currently
44 only queues and sources support these additional interfaces).
45 .Sh MEMORY MANGEMENT
46 Objects returned by creation functions in the dispatch framework may be
47 uniformly retained and released with the functions
48 .Fn dispatch_retain
49 and
50 .Fn dispatch_release
51 respectively.
52 .Pp
53 The dispatch framework does not guarantee that any given client has the last or
54 only reference to a given object. Objects may be retained internally by the
55 system.
56 .Sh SUSPENSION
57 The invocation of blocks on dispatch queues or dispatch sources may be suspended
58 or resumed with the functions
59 .Fn dispatch_suspend
60 and
61 .Fn dispatch_resume
62 respectively.
63 The dispatch framework always checks the suspension status before executing a
64 block, but such changes never affect a block during execution (non-preemptive).
65 Therefore the suspension of an object is asynchronous, unless it is performed
66 from the context of the target queue for the given object.
67 The result of suspending or resuming an object that is not a dispatch queue or
68 a dispatch source is undefined.
69 .Pp
70 .Em Important :
71 suspension applies to all aspects of the dispatch object life cycle, including
72 the finalizer function and cancellation handler. Suspending an object causes it
73 to be retained and resuming an object causes it to be released. Therefore it is
74 important to balance calls to
75 .Fn dispatch_suspend
76 and
77 .Fn dispatch_resume
78 such that the dispatch object is fully resumed when the last reference is
79 released. The result of releasing all references to a dispatch object while in
80 a suspended state is undefined.
81 .Sh CONTEXT POINTERS
82 Dispatch queues and sources support supplemental context pointers. The value of
83 the context pointer may be retrieved and updated with
84 .Fn dispatch_get_context
85 and
86 .Fn dispatch_set_context
87 respectively.
88 The
89 .Fn dispatch_set_finalizer_f
90 specifies an optional per-object finalizer function that is invoked
91 asynchronously if the context pointer is not NULL when the last
92 reference to the object is released.
93 This gives the
94 application an opportunity to free the context data associated with the object.
95 The finalizer will be run on the object's target queue.
96 .Pp
97 The result of getting or setting the context of an object that is not a
98 dispatch queue or a dispatch source is undefined.
99 .Sh SEE ALSO
100 .Xr dispatch 3 ,
101 .Xr dispatch_group_create 3 ,
102 .Xr dispatch_queue_create 3 ,
103 .Xr dispatch_semaphore_create 3 ,
104 .Xr dispatch_source_create 3 ,
105 .Xr dispatch_set_target_queue 3