]>
Commit | Line | Data |
---|---|---|
a3a49a17 SF |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | /* | |
e4a3f096 | 3 | * Copyright (C) 2005-2020 Junjiro R. Okajima |
a3a49a17 SF |
4 | * |
5 | * This program, aufs is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | /* | |
20 | * simple read-write semaphore wrappers | |
21 | */ | |
22 | ||
23 | #ifndef __AUFS_RWSEM_H__ | |
24 | #define __AUFS_RWSEM_H__ | |
25 | ||
26 | #ifdef __KERNEL__ | |
27 | ||
28 | #include "debug.h" | |
29 | ||
30 | /* in the future, the name 'au_rwsem' will be totally gone */ | |
31 | #define au_rwsem rw_semaphore | |
32 | ||
33 | /* to debug easier, do not make them inlined functions */ | |
34 | #define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw)) | |
35 | /* rwsem_is_locked() is unusable */ | |
36 | #define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \ | |
37 | && debug_locks \ | |
38 | && !lockdep_is_held_type(rw, 1)) | |
39 | #define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \ | |
40 | && debug_locks \ | |
41 | && !lockdep_is_held_type(rw, 0)) | |
42 | #define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \ | |
43 | && debug_locks \ | |
44 | && !lockdep_is_held(rw)) | |
45 | #define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \ | |
46 | && debug_locks \ | |
47 | && lockdep_is_held(rw)) | |
48 | ||
49 | #define au_rw_init(rw) init_rwsem(rw) | |
50 | ||
51 | #define au_rw_init_wlock(rw) do { \ | |
52 | au_rw_init(rw); \ | |
53 | down_write(rw); \ | |
54 | } while (0) | |
55 | ||
56 | #define au_rw_init_wlock_nested(rw, lsc) do { \ | |
57 | au_rw_init(rw); \ | |
58 | down_write_nested(rw, lsc); \ | |
59 | } while (0) | |
60 | ||
61 | #define au_rw_read_lock(rw) down_read(rw) | |
62 | #define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc) | |
63 | #define au_rw_read_unlock(rw) up_read(rw) | |
64 | #define au_rw_dgrade_lock(rw) downgrade_write(rw) | |
65 | #define au_rw_write_lock(rw) down_write(rw) | |
66 | #define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc) | |
67 | #define au_rw_write_unlock(rw) up_write(rw) | |
68 | /* why is not _nested version defined? */ | |
69 | #define au_rw_read_trylock(rw) down_read_trylock(rw) | |
70 | #define au_rw_write_trylock(rw) down_write_trylock(rw) | |
71 | ||
72 | #endif /* __KERNEL__ */ | |
73 | #endif /* __AUFS_RWSEM_H__ */ |