Whamcloud - gitweb
LU-3570 libcfs: accelerate crc32c with pclmulqdq
[fs/lustre-release.git] / libcfs / include / libcfs / linux / linux-lock.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * libcfs/include/libcfs/linux/linux-lock.h
37  *
38  * Basic library routines.
39  */
40
41 #ifndef __LIBCFS_LINUX_CFS_LOCK_H__
42 #define __LIBCFS_LINUX_CFS_LOCK_H__
43
44 #ifndef __LIBCFS_LIBCFS_H__
45 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
46 #endif
47
48 #ifndef __KERNEL__
49 #error This include is only for kernel use.
50 #endif
51
52 #include <linux/mutex.h>
53
54 /*
55  * IMPORTANT !!!!!!!!
56  *
57  * All locks' declaration are not guaranteed to be initialized,
58  * Althought some of they are initialized in Linux. All locks
59  * declared by CFS_DECL_* should be initialized explicitly.
60  */
61
62 /*
63  * spin_lock "implementation" (use Linux kernel's primitives)
64  *
65  * - spin_lock_init(x)
66  * - spin_lock(x)
67  * - spin_lock_bh(x)
68  * - spin_lock_bh_init(x)
69  * - spin_unlock(x)
70  * - spin_unlock_bh(x)
71  * - spin_trylock(x)
72  * - spin_is_locked(x)
73  *
74  * - spin_lock_irq(x)
75  * - spin_lock_irqsave(x, f)
76  * - spin_unlock_irqrestore(x, f)
77  * - read_lock_irqsave(lock, f)
78  * - write_lock_irqsave(lock, f)
79  * - write_unlock_irqrestore(lock, f)
80  */
81
82 /*
83  * spinlock "implementation"
84  */
85
86
87
88
89 /*
90  * rw_semaphore "implementation" (use Linux kernel's primitives)
91  *
92  * - sema_init(x)
93  * - init_rwsem(x)
94  * - down_read(x)
95  * - up_read(x)
96  * - down_write(x)
97  * - up_write(x)
98  */
99
100
101 #define fini_rwsem(s)           do {} while (0)
102
103
104 /*
105  * rwlock_t "implementation" (use Linux kernel's primitives)
106  *
107  * - rwlock_init(x)
108  * - read_lock(x)
109  * - read_unlock(x)
110  * - write_lock(x)
111  * - write_unlock(x)
112  * - write_lock_bh(x)
113  * - write_unlock_bh(x)
114  *
115  * - RW_LOCK_UNLOCKED
116  */
117
118
119 #ifndef DEFINE_RWLOCK
120 #define DEFINE_RWLOCK(lock)     rwlock_t lock = __RW_LOCK_UNLOCKED(lock)
121 #endif
122
123 /*
124  * completion "implementation" (use Linux kernel's primitives)
125  *
126  * - DECLARE_COMPLETION(work)
127  * - INIT_COMPLETION(c)
128  * - COMPLETION_INITIALIZER(work)
129  * - init_completion(c)
130  * - complete(c)
131  * - wait_for_completion(c)
132  * - wait_for_completion_interruptible(c)
133  * - fini_completion(c)
134  */
135 #define fini_completion(c) do { } while (0)
136
137 /*
138  * semaphore "implementation" (use Linux kernel's primitives)
139  * - DEFINE_SEMAPHORE(name)
140  * - sema_init(sem, val)
141  * - up(sem)
142  * - down(sem)
143  * - down_interruptible(sem)
144  * - down_trylock(sem)
145  */
146
147 /*
148  * mutex "implementation" (use Linux kernel's primitives)
149  *
150  * - DEFINE_MUTEX(name)
151  * - mutex_init(x)
152  * - mutex_lock(x)
153  * - mutex_unlock(x)
154  * - mutex_trylock(x)
155  * - mutex_is_locked(x)
156  * - mutex_destroy(x)
157  */
158
159 #ifndef lockdep_set_class
160
161 /**************************************************************************
162  *
163  * Lockdep "implementation". Also see liblustre.h
164  *
165  **************************************************************************/
166
167 struct lock_class_key {
168         ;
169 };
170
171 #define lockdep_set_class(lock, key) \
172         do { (void)sizeof(lock); (void)sizeof(key); } while (0)
173 /* This has to be a macro, so that `subclass' can be undefined in kernels
174  * that do not support lockdep. */
175
176
177 static inline void lockdep_off(void)
178 {
179 }
180
181 static inline void lockdep_on(void)
182 {
183 }
184 #else
185
186 #endif /* lockdep_set_class */
187
188 #ifndef CONFIG_DEBUG_LOCK_ALLOC
189 #ifndef mutex_lock_nested
190 #define mutex_lock_nested(mutex, subclass) mutex_lock(mutex)
191 #endif
192
193 #ifndef spin_lock_nested
194 #define spin_lock_nested(lock, subclass) spin_lock(lock)
195 #endif
196
197 #ifndef down_read_nested
198 #define down_read_nested(lock, subclass) down_read(lock)
199 #endif
200
201 #ifndef down_write_nested
202 #define down_write_nested(lock, subclass) down_write(lock)
203 #endif
204 #endif /* CONFIG_DEBUG_LOCK_ALLOC */
205
206
207 #endif /* __LIBCFS_LINUX_CFS_LOCK_H__ */