]> git.saurik.com Git - apple/libdispatch.git/blob - man/dispatch_object.3
libdispatch-84.5.tar.gz
[apple/libdispatch.git] / man / dispatch_object.3
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
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. Therefore it is important to
73 balance calls to
74 .Fn dispatch_suspend
75 and
76 .Fn dispatch_resume
77 such that the dispatch object is fully resumed when the last reference is
78 released. The result of releasing all references to a dispatch object while in
79 a suspended state is undefined.
80 .Sh CONTEXT POINTERS
81 Dispatch queues and sources support supplemental context pointers. The value of
82 the context point may be retrieved and updated with
83 .Fn dispatch_get_context
84 and
85 .Fn dispatch_set_context
86 respectively.
87 The
88 .Fn dispatch_set_finalizer_f
89 specifies an optional per-object finalizer function to that is invoked
90 asynchronously when the last reference to the object is released. This gives the
91 application an opportunity to free the context data associated with the object.
92 .Pp
93 The result of getting or setting the context of an object that is not a
94 dispatch 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