Debian Codegraph @

doc/ck_tflock

raw
1 .\"
2 .\" Copyright 2014 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 April 22, 2014.
28 .Dt ck_tflock 3
29 .Sh NAME
30 .Nm ck_tflock_ticket_init ,
31 .Nm ck_tflock_ticket_write_lock ,
32 .Nm ck_tflock_ticket_write_unlock ,
33 .Nm ck_tflock_ticket_read_lock ,
34 .Nm ck_tflock_ticket_read_unlock ,
35 .Nd centralized task-fair reader-writer locks
36 .Sh LIBRARY
37 Concurrency Kit (libck, \-lck)
38 .Sh SYNOPSIS
39 .In ck_tflock.h
40 .Pp
41 .Dv ck_tflock_ticket_t lock = CK_TFLOCK_TICKET_INITIALIZER;
42 .Pp
43 .Ft void
44 .Fn ck_tflock_ticket_init "ck_tflock_ticket_t *lock"
45 .Ft void
46 .Fn ck_tflock_ticket_write_lock "ck_tflock_ticket_t *lock"
47 .Ft void
48 .Fn ck_tflock_ticket_write_unlock "ck_tflock_ticket_t *lock"
49 .Ft void
50 .Fn ck_tflock_ticket_read_lock "ck_tflock_ticket_t *lock"
51 .Ft void
52 .Fn ck_tflock_ticket_read_unlock "ck_tflock_ticket_t *lock"
53 .Sh DESCRIPTION
54 This is a centralized task-fair reader-writer lock. It
55 requires little space overhead and has a low latency
56 fast path.
57 .Sh EXAMPLE
58 .Bd -literal -offset indent
59 #include <ck_tflock.h>
60
61 static ck_tflock_ticket_t lock = CK_TFLOCK_INITIALIZER;
62
63 static void
64 reader(void)
65 {
66
67 for (;;) {
68 ck_tflock_ticket_read_lock(&lock);
69 /* Read-side critical section. */
70 ck_tflock_ticket_read_unlock(&lock);
71 }
72
73 return;
74 }
75
76 static void
77 writer(void)
78 {
79
80 for (;;) {
81 ck_tflock_ticket_write_lock(&lock);
82 /* Write-side critical section. */
83 ck_tflock_ticket_write_unlock(&lock);
84 }
85
86 return;
87 }
88 .Ed
89 .Sh SEE ALSO
90 .Xr ck_brlock 3 ,
91 .Xr ck_rwlock 3 ,
92 .Xr ck_pflock 3 ,
93 .Xr ck_swlock 3
94 .Pp
95 Additional information available at http://concurrencykit.org/