rwsem.h 2.77 KB
Newer Older
J. R. Okajima's avatar
J. R. Okajima committed
1
2
/* SPDX-License-Identifier: GPL-2.0 */
/*
3
 * Copyright (C) 2005-2020 Junjiro R. Okajima
4
5
6
7
8
9
10
11
12
13
14
15
16
 *
 * This program, aufs is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
J. R. Okajima's avatar
J. R. Okajima committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 */

/*
 * simple read-write semaphore wrappers
 */

#ifndef __AUFS_RWSEM_H__
#define __AUFS_RWSEM_H__

#ifdef __KERNEL__

#include "debug.h"

/* in the future, the name 'au_rwsem' will be totally gone */
#define au_rwsem	rw_semaphore

/* to debug easier, do not make them inlined functions */
#define AuRwMustNoWaiters(rw)	AuDebugOn(rwsem_is_contended(rw))
35
36

#ifdef CONFIG_LOCKDEP
J. R. Okajima's avatar
J. R. Okajima committed
37
/* rwsem_is_locked() is unusable */
38
39
40
#define AuRwMustReadLock(rw)	AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP)	\
					  && !lockdep_recursing(current) \
					  && debug_locks		\
J. R. Okajima's avatar
J. R. Okajima committed
41
					  && !lockdep_is_held_type(rw, 1))
42
43
44
#define AuRwMustWriteLock(rw)	AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP)	\
					  && !lockdep_recursing(current) \
					  && debug_locks		\
J. R. Okajima's avatar
J. R. Okajima committed
45
					  && !lockdep_is_held_type(rw, 0))
46
47
48
#define AuRwMustAnyLock(rw)	AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP)	\
					  && !lockdep_recursing(current) \
					  && debug_locks		\
J. R. Okajima's avatar
J. R. Okajima committed
49
					  && !lockdep_is_held(rw))
50
51
52
#define AuRwDestroy(rw)		AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP)	\
					  && !lockdep_recursing(current) \
					  && debug_locks		\
J. R. Okajima's avatar
J. R. Okajima committed
53
					  && lockdep_is_held(rw))
54
55
56
57
58
59
#else
#define AuRwMustReadLock(rw)	do {} while (0)
#define AuRwMustWriteLock(rw)	do {} while (0)
#define AuRwMustAnyLock(rw)	do {} while (0)
#define AuRwDestroy(rw)		do {} while (0)
#endif
J. R. Okajima's avatar
J. R. Okajima committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

#define au_rw_init(rw)	init_rwsem(rw)

#define au_rw_init_wlock(rw) do {		\
		au_rw_init(rw);			\
		down_write(rw);			\
	} while (0)

#define au_rw_init_wlock_nested(rw, lsc) do {	\
		au_rw_init(rw);			\
		down_write_nested(rw, lsc);	\
	} while (0)

#define au_rw_read_lock(rw)		down_read(rw)
#define au_rw_read_lock_nested(rw, lsc)	down_read_nested(rw, lsc)
#define au_rw_read_unlock(rw)		up_read(rw)
#define au_rw_dgrade_lock(rw)		downgrade_write(rw)
#define au_rw_write_lock(rw)		down_write(rw)
#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
#define au_rw_write_unlock(rw)		up_write(rw)
/* why is not _nested version defined? */
#define au_rw_read_trylock(rw)		down_read_trylock(rw)
#define au_rw_write_trylock(rw)		down_write_trylock(rw)

#endif /* __KERNEL__ */
#endif /* __AUFS_RWSEM_H__ */