1ck_rwlock(3)             BSD Library Functions Manual             ck_rwlock(3)
2

NAME

4     ck_rwlock_init, ck_rwlock_write_lock, ck_rwlock_write_unlock,
5     ck_rwlock_write_trylock, ck_rwlock_write_downgrade,
6     ck_rwlock_locked_writer, ck_rwlock_read_lock, ck_rwlock_read_trylock,
7     ck_rwlock_read_unlock, ck_rwlock_locked_reader,
8     ck_rwlock_recursive_write_lock, ck_rwlock_recursive_write_trylock,
9     ck_rwlock_recurisve_write_unlock, ck_rwlock_recursive_read_lock,
10     ck_rwlock_recursive_read_trylock, ck_rwlock_recursive_read_unlock — cen‐
11     tralized write-biased reader-writer locks
12

LIBRARY

14     Concurrency Kit (libck, -lck)
15

SYNOPSIS

17     #include <ck_rwlock.h>
18
19     ck_rwlock_t lock = CK_RWLOCK_INITIALIZER;
20
21     void
22     ck_rwlock_init(ck_rwlock_t *lock);
23
24     void
25     ck_rwlock_write_lock(ck_rwlock_t *lock);
26
27     void
28     ck_rwlock_write_unlock(ck_rwlock_t *lock);
29
30     bool
31     ck_rwlock_write_trylock(ck_rwlock_t *lock);
32
33     bool
34     ck_rwlock_write_downgrade(ck_rwlock_t *lock);
35
36     bool
37     ck_rwlock_locked_writer(ck_rwlock_t *lock);
38
39     void
40     ck_rwlock_read_lock(ck_rwlock_t *lock);
41
42     bool
43     ck_rwlock_read_trylock(ck_rwlock_t *lock);
44
45     void
46     ck_rwlock_read_unlock(ck_rwlock_t *lock);
47
48     bool
49     ck_rwlock_locked_reader(ck_rwlock_t *lock);
50
51     ck_rwlock_recursive_t lock = CK_RWLOCK_RECURSIVE_INITIALIZER;
52
53     void
54     ck_rwlock_recursive_write_lock(ck_rwlock_recursive_t *lock,
55         unsigned int tid);
56
57     bool
58     ck_rwlock_recursive_write_trylock(ck_rwlock_recursive_t *lock,
59         unsigned int tid);
60
61     void
62     ck_rwlock_recurisve_write_unlock(ck_rwlock_recursive_t *lock);
63
64     void
65     ck_rwlock_recursive_read_lock(ck_rwlock_recursive_t *lock);
66
67     bool
68     ck_rwlock_recursive_read_trylock(ck_rwlock_recursive_t *lock);
69
70     void
71     ck_rwlock_recursive_read_unlock(ck_rwlock_recursive_t *lock);
72

DESCRIPTION

74     This is a centralized write-biased reader-writer lock. It requires very
75     little space overhead and has a low latency fast path. Write-side recur‐
76     sion requires usage of ck_rwlock_recursive.  Read-side recursion is dis‐
77     allowed. The ck_rwlock_write_downgrade() function degrades the caller's
78     write-side acquisition to a read-side acquisition without forfeit of cur‐
79     rent critical section.
80

EXAMPLE

82           #include <ck_rwlock.h>
83
84           static ck_rwlock_t lock = CK_RWLOCK_INITIALIZER;
85
86           static void
87           reader(void)
88           {
89
90                   for (;;) {
91                           ck_rwlock_read_lock(&lock);
92                           /* Read-side critical section. */
93                           ck_rwlock_read_unlock(&lock);
94
95                           if (ck_rwlock_read_trylock(&lock) == true) {
96                                   /* Read-side critical section. */
97                                   ck_rwlock_read_unlock(&lock);
98                           }
99                   }
100
101                   return;
102           }
103
104           static void
105           writer(void)
106           {
107
108                   for (;;) {
109                           ck_rwlock_write_lock(&lock);
110                           /* Write-side critical section. */
111                           ck_rwlock_write_unlock(&lock);
112
113                           if (ck_rwlock_write_trylock(&lock, 1) == true) {
114                                   /* Write-side critical section. */
115                                   ck_rwlock_write_unlock(&lock);
116                           }
117                   }
118
119                   return;
120           }
121

SEE ALSO

123     ck_brlock(3), ck_elide(3)
124
125     Additional information available at http://concurrencykit.org/
126
127                                July 26, 2013.
Impressum