XenevaOS
Loading...
Searching...
No Matches
rwsem.h
Go to the documentation of this file.
1#ifndef __LINUX_RWSEM_H__
2#define __LINUX_RWSEM_H__
3
4/*
5 * DCL <linux/rwsem.h> -- the reader/writer semaphore n_tty and tty_io share
6 * termios through.
7 *
8 * The surface is bigger than it first looks: 30-odd calls across the four
9 * files, in two forms. Plain down_read/up_read/down_write/up_write guard the
10 * termios_rwsem around each read and write, and the scoped form --
11 * `scoped_guard(rwsem_read, &tty->termios_rwsem)`, `guard(rwsem_write)(...)`
12 * -- appears wherever mainline recently converted to guards (26 calls in
13 * n_tty.c alone, at 1037, 1560, 1678, 1872, 2349, 2489, 2611).
14 *
15 * As with <linux/spinlock.h>, the operations are no-ops and that is DCL's
16 * existing locking contract rather than a decision made here: nobody else can
17 * be holding the semaphore, so there is never a writer to wait behind and
18 * never a reader to exclude. What matters is that the *acquire/release pairs
19 * stay balanced* -- which is precisely what the guards buy, and why
20 * rwsem_read/rwsem_write exist as classes rather than as bare calls: a
21 * down_read() at the top of a function and its up_read() at the bottom are
22 * separated by every early return in between.
23 *
24 * The one behaviour a reader could notice: with no writer exclusion, a
25 * tcsetattr() landing mid-read is not excluded from that read. That is the
26 * same recorded gap as <linux/mutex.h> notes, and it closes with it.
27 *
28 * `init_rwsem(s)` is called at uart/port construction (serial_core.c:3115,
29 * tty_io.c:586 region) -- harmless either way, kept so the construction code
30 * reads as it does upstream.
31 */
32
33#include <linux/kernel.h>
34#include <linux/cleanup.h>
35
37 int count;
38};
39
40#define init_rwsem(s) do { (void)(s); } while (0)
41#define down_read(s) do { (void)(s); } while (0)
42#define up_read(s) do { (void)(s); } while (0)
43#define down_write(s) do { (void)(s); } while (0)
44#define up_write(s) do { (void)(s); } while (0)
45#define down_read_trylock(s) (1)
46#define down_write_trylock(s) (1)
47#define down_read_killable(s) (0)
48#define down_write_killable(s) (0)
49#define rwsem_is_locked(s) (1)
50
51DCL_LOCK_GUARD(rwsem_read, struct rw_semaphore, down_read(_T), up_read(_T))
52DCL_LOCK_GUARD(rwsem_write, struct rw_semaphore, down_write(_T), up_write(_T))
53
54#endif /* __LINUX_RWSEM_H__ */
#define DCL_LOCK_GUARD(name, type, acquire, release)
Definition cleanup.h:168
#define up_write(s)
Definition rwsem.h:44
#define down_write(s)
Definition rwsem.h:43
#define down_read(s)
Definition rwsem.h:41
#define up_read(s)
Definition rwsem.h:42
Definition rwsem.h:36
int count
Definition rwsem.h:37