Debian Codegraph @

doc/ck_epoch_barrier

raw
1 .\"
2 .\" Copyright 2012-2013 Samy Al Bahra.
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\"
27 .Dd September 2, 2012
28 .Dt CK_EPOCH_BARRIER 3
29 .Sh NAME
30 .Nm ck_epoch_barrier
31 .Nd block until a grace period and all callbacks have been dispatched
32 .Sh LIBRARY
33 Concurrency Kit (libck, \-lck)
34 .Sh SYNOPSIS
35 .In ck_epoch.h
36 .Ft void
37 .Fn ck_epoch_barrier "ck_epoch_record_t *record"
38 .Sh DESCRIPTION
39 The
40 .Fn ck_epoch_barrier 3
41 function will block the caller until a grace period has been
42 detected, according to the semantics of epoch reclamation.
43 Any objects requiring safe memory reclamation which are logically
44 deleted are safe for physical deletion following a call to
45 .Fn ck_epoch_barrier 3 . This function will also dispatch all callbacks
46 associated with
47 .Fa epoch
48 that were previously scheduled via
49 .Fn ck_epoch_call 3 .
50 .Sh EXAMPLE
51 .Bd -literal -offset indent
52
53 #include <ck_epoch.h>
54 #include <ck_stack.h>
55 #include <stdlib.h>
56
57 /*
58 * epoch was previously initialized with ck_epoch_init.
59 * stack was previously initialized with ck_stack_init.
60 */
61 ck_epoch_t *epoch;
62 ck_stack_t *stack;
63
64 void
65 function(void)
66 {
67 ck_epoch_record_t *record;
68 ck_stack_entry_t *s;
69
70 record = malloc(sizeof *record);
71 ck_epoch_register(&epoch, record, NULL);
72
73 /*
74 * We are using an epoch section here to guarantee no
75 * nodes in the stack are deleted while we are dereferencing
76 * them. This is needed here because there are multiple writers.
77 * If there was only one thread popping from the this stack,
78 * then there is no need to ck_epoch_begin/ck_epoch_end.
79 */
80 ck_epoch_begin(record);
81
82 /* Logically delete an object. */
83 s = ck_stack_pop_upmc(stack);
84
85 ck_epoch_end(record);
86
87 /*
88 * Wait until no threads could possibly have a reference to the
89 * object we just popped (assume all threads are simply executing
90 * ck_stack_pop_upmc).
91 */
92 ck_epoch_barrier(record);
93
94 /* It is now safe to physically delete the object. */
95 free(s);
96 return;
97 }
98 .Ed
99 .Sh RETURN VALUES
100 This function has no return value.
101 .Sh ERRORS
102 Behavior is undefined if the object pointed to by
103 .Fa epoch
104 is not a valid epoch object. The object pointed to by
105 .Fa record
106 must have been previously registered via
107 .Fn ck_epoch_register 3 .
108 .Sh SEE ALSO
109 .Xr ck_epoch_init 3 ,
110 .Xr ck_epoch_register 3 ,
111 .Xr ck_epoch_unregister 3 ,
112 .Xr ck_epoch_recycle 3 ,
113 .Xr ck_epoch_poll 3 ,
114 .Xr ck_epoch_synchronize 3 ,
115 .Xr ck_epoch_reclaim 3 ,
116 .Xr ck_epoch_call 3 ,
117 .Xr ck_epoch_begin 3 ,
118 .Xr ck_epoch_end 3
119 .Pp
120 Additional information available at http://concurrencykit.org/