1CK_EPOCH_CALL(3) BSD Library Functions Manual CK_EPOCH_CALL(3)
2
4 ck_epoch_call — defer function execution until a grace period
5
7 Concurrency Kit (libck, -lck)
8
10 #include <ck_epoch.h>
11 typedef struct ck_epoch_entry ck_epoch_entry_t;
12 typedef void ck_epoch_cb_t(ck_epoch_entry_t *);
13
14 void
15 ck_epoch_call(ck_epoch_record_t *record, ck_epoch_entry_t *entry,
16 ck_epoch_cb_t *function);
17
19 The ck_epoch_call(3) function will defer the execution of the function
20 pointed to by function until a grace-period has been detected in epoch.
21 The function will be provided the pointer specified by entry. The func‐
22 tion will execute at some time in the future via calls to
23 ck_epoch_reclaim(3), ck_epoch_barrier(3) or ck_epoch_poll(3).
24
26 #include <ck_epoch.h>
27 #include <ck_stack.h>
28 #include <stdlib.h>
29
30 /*
31 * epoch was previously initialized with ck_epoch_init.
32 */
33 ck_epoch_t *epoch;
34
35 struct object {
36 int value;
37 ck_epoch_entry_t epoch_entry;
38 };
39 static struct object *global;
40
41 CK_EPOCH_CONTAINER(struct object, epoch_entry, object_container)
42
43 void
44 destroy_object(ck_epoch_entry_t *e)
45 {
46 struct object *o = object_container(e);
47
48 free(o);
49 return;
50 }
51
52 void
53 function(void)
54 {
55 ck_epoch_record_t *record;
56 struct object *n;
57
58 record = malloc(sizeof *record);
59 ck_epoch_register(&epoch, record);
60
61 n = malloc(sizeof *n);
62 if (n == NULL)
63 return;
64
65 n->value = 1;
66
67 /*
68 * We are using an epoch section here because there are multiple
69 * writers. It is also an option to use other forms of blocking
70 * write-side synchronization such as mutexes.
71 */
72 ck_epoch_begin(record);
73 n = ck_pr_fas_ptr(&global, n);
74 ck_epoch_end(record);
75
76 /* Defer destruction of previous object. */
77 ck_epoch_call(record, &n->epoch_entry, destroy_object);
78
79 /* Poll epoch sub-system in non-blocking manner. */
80 ck_epoch_poll(record);
81 return;
82 }
83
85 This function has no return value.
86
88 The object pointed to by record must have been previously registered via
89 ck_epoch_register(3).
90
92 ck_epoch_init(3), ck_epoch_register(3), ck_epoch_unregister(3),
93 ck_epoch_recycle(3), ck_epoch_poll(3), ck_epoch_synchronize(3),
94 ck_epoch_reclaim(3), ck_epoch_barrier(3), ck_epoch_begin(3),
95 ck_epoch_end(3)
96
97 Additional information available at http://concurrencykit.org/
98
99 September 2, 2012