4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/include/libcfs/linux/linux-lock.h
38 * Basic library routines.
41 #ifndef __LIBCFS_LINUX_CFS_LOCK_H__
42 #define __LIBCFS_LINUX_CFS_LOCK_H__
44 #ifndef __LIBCFS_LIBCFS_H__
45 #error Do not #include this file directly. #include <linux/libcfs/libcfs.h> instead
49 #include <linux/mutex.h>
54 * All locks' declaration are not guaranteed to be initialized,
55 * although some of them are initialized in Linux. All locks
56 * declared by CFS_DECL_* should be initialized explicitly.
60 * spin_lock "implementation" (use Linux kernel's primitives)
65 * - spin_lock_bh_init(x)
72 * - spin_lock_irqsave(x, f)
73 * - spin_unlock_irqrestore(x, f)
74 * - read_lock_irqsave(lock, f)
75 * - write_lock_irqsave(lock, f)
76 * - write_unlock_irqrestore(lock, f)
80 * spinlock "implementation"
87 * rw_semaphore "implementation" (use Linux kernel's primitives)
98 #define fini_rwsem(s) do {} while (0)
102 * rwlock_t "implementation" (use Linux kernel's primitives)
110 * - write_unlock_bh(x)
116 #ifndef DEFINE_RWLOCK
117 #define DEFINE_RWLOCK(lock) rwlock_t lock = __RW_LOCK_UNLOCKED(lock)
121 * completion "implementation" (use Linux kernel's primitives)
123 * - DECLARE_COMPLETION(work)
124 * - INIT_COMPLETION(c)
125 * - COMPLETION_INITIALIZER(work)
126 * - init_completion(c)
128 * - wait_for_completion(c)
129 * - wait_for_completion_interruptible(c)
130 * - fini_completion(c)
132 #define fini_completion(c) do { } while (0)
135 * semaphore "implementation" (use Linux kernel's primitives)
136 * - DEFINE_SEMAPHORE(name)
137 * - sema_init(sem, val)
140 * - down_interruptible(sem)
141 * - down_trylock(sem)
145 * mutex "implementation" (use Linux kernel's primitives)
147 * - DEFINE_MUTEX(name)
152 * - mutex_is_locked(x)
156 #ifndef lockdep_set_class
158 /**************************************************************************
160 * Lockdep "implementation". Also see liblustre.h
162 **************************************************************************/
164 struct lock_class_key {
168 #define lockdep_set_class(lock, key) \
169 do { (void)sizeof(lock); (void)sizeof(key); } while (0)
170 /* This has to be a macro, so that `subclass' can be undefined in kernels
171 * that do not support lockdep. */
174 static inline void lockdep_off(void)
178 static inline void lockdep_on(void)
183 #endif /* lockdep_set_class */
185 #ifndef CONFIG_DEBUG_LOCK_ALLOC
186 #ifndef mutex_lock_nested
187 #define mutex_lock_nested(mutex, subclass) mutex_lock(mutex)
190 #ifndef spin_lock_nested
191 #define spin_lock_nested(lock, subclass) spin_lock(lock)
194 #ifndef down_read_nested
195 #define down_read_nested(lock, subclass) down_read(lock)
198 #ifndef down_write_nested
199 #define down_write_nested(lock, subclass) down_write(lock)
201 #endif /* CONFIG_DEBUG_LOCK_ALLOC */
204 #endif /* __LIBCFS_LINUX_CFS_LOCK_H__ */