| 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_CALL 3 |
| 29 |
.Sh NAME |
| 30 |
.Nm ck_epoch_call |
| 31 |
.Nd defer function execution until a grace period |
| 32 |
.Sh LIBRARY |
| 33 |
Concurrency Kit (libck, \-lck) |
| 34 |
.Sh SYNOPSIS |
| 35 |
.In ck_epoch.h |
| 36 |
typedef struct ck_epoch_entry ck_epoch_entry_t; |
| 37 |
.br |
| 38 |
typedef void ck_epoch_cb_t(ck_epoch_entry_t *); |
| 39 |
.Ft void |
| 40 |
.Fn ck_epoch_call "ck_epoch_record_t *record" "ck_epoch_entry_t *entry" "ck_epoch_cb_t *function" |
| 41 |
.Sh DESCRIPTION |
| 42 |
The |
| 43 |
.Fn ck_epoch_call 3 |
| 44 |
function will defer the execution of the function pointed to by |
| 45 |
.Fa function |
| 46 |
until a grace-period has been detected in |
| 47 |
.Fa epoch . |
| 48 |
The function will be provided |
| 49 |
the pointer specified by |
| 50 |
.Fa entry . |
| 51 |
The function will execute at some time in the future via calls to |
| 52 |
.Fn ck_epoch_reclaim 3 , |
| 53 |
.Fn ck_epoch_barrier 3 |
| 54 |
or |
| 55 |
.Fn ck_epoch_poll 3 . |
| 56 |
.Sh EXAMPLE |
| 57 |
.Bd -literal -offset indent |
| 58 |
|
| 59 |
#include <ck_epoch.h> |
| 60 |
#include <ck_stack.h> |
| 61 |
#include <stdlib.h> |
| 62 |
|
| 63 |
/* |
| 64 |
* epoch was previously initialized with ck_epoch_init. |
| 65 |
*/ |
| 66 |
ck_epoch_t *epoch; |
| 67 |
|
| 68 |
struct object { |
| 69 |
int value; |
| 70 |
ck_epoch_entry_t epoch_entry; |
| 71 |
}; |
| 72 |
static struct object *global; |
| 73 |
|
| 74 |
CK_EPOCH_CONTAINER(struct object, epoch_entry, object_container) |
| 75 |
|
| 76 |
void |
| 77 |
destroy_object(ck_epoch_entry_t *e) |
| 78 |
{ |
| 79 |
struct object *o = object_container(e); |
| 80 |
|
| 81 |
free(o); |
| 82 |
return; |
| 83 |
} |
| 84 |
|
| 85 |
void |
| 86 |
function(void) |
| 87 |
{ |
| 88 |
ck_epoch_record_t *record; |
| 89 |
struct object *n; |
| 90 |
|
| 91 |
record = malloc(sizeof *record); |
| 92 |
ck_epoch_register(&epoch, record, NULL); |
| 93 |
|
| 94 |
n = malloc(sizeof *n); |
| 95 |
if (n == NULL) |
| 96 |
return; |
| 97 |
|
| 98 |
n->value = 1; |
| 99 |
|
| 100 |
/* |
| 101 |
* We are using an epoch section here because there are multiple |
| 102 |
* writers. It is also an option to use other forms of blocking |
| 103 |
* write-side synchronization such as mutexes. |
| 104 |
*/ |
| 105 |
ck_epoch_begin(record); |
| 106 |
n = ck_pr_fas_ptr(&global, n); |
| 107 |
ck_epoch_end(record); |
| 108 |
|
| 109 |
/* Defer destruction of previous object. */ |
| 110 |
ck_epoch_call(record, &n->epoch_entry, destroy_object); |
| 111 |
|
| 112 |
/* Poll epoch sub-system in non-blocking manner. */ |
| 113 |
ck_epoch_poll(record); |
| 114 |
return; |
| 115 |
} |
| 116 |
.Ed |
| 117 |
.Sh RETURN VALUES |
| 118 |
This function has no return value. |
| 119 |
.Sh ERRORS |
| 120 |
The object pointed to by |
| 121 |
.Fa record |
| 122 |
must have been previously registered via |
| 123 |
.Fn ck_epoch_register 3 . |
| 124 |
.Sh SEE ALSO |
| 125 |
.Xr ck_epoch_init 3 , |
| 126 |
.Xr ck_epoch_register 3 , |
| 127 |
.Xr ck_epoch_unregister 3 , |
| 128 |
.Xr ck_epoch_recycle 3 , |
| 129 |
.Xr ck_epoch_poll 3 , |
| 130 |
.Xr ck_epoch_synchronize 3 , |
| 131 |
.Xr ck_epoch_reclaim 3 , |
| 132 |
.Xr ck_epoch_barrier 3 , |
| 133 |
.Xr ck_epoch_begin 3 , |
| 134 |
.Xr ck_epoch_end 3 |
| 135 |
.Pp |
| 136 |
Additional information available at http://concurrencykit.org/ |