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 <libcfs/libcfs.h> instead
49 #error This include is only for kernel use.
52 #include <linux/mutex.h>
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.
63 * spin_lock "implementation" (use Linux kernel's primitives)
68 * - spin_lock_bh_init(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)
83 * spinlock "implementation"
90 * rw_semaphore "implementation" (use Linux kernel's primitives)
101 #define fini_rwsem(s) do {} while (0)
105 * rwlock_t "implementation" (use Linux kernel's primitives)
113 * - write_unlock_bh(x)
119 #ifndef DEFINE_RWLOCK
120 #define DEFINE_RWLOCK(lock) rwlock_t lock = __RW_LOCK_UNLOCKED(lock)
124 * completion "implementation" (use Linux kernel's primitives)
126 * - DECLARE_COMPLETION(work)
127 * - INIT_COMPLETION(c)
128 * - COMPLETION_INITIALIZER(work)
129 * - init_completion(c)
131 * - wait_for_completion(c)
132 * - wait_for_completion_interruptible(c)
133 * - fini_completion(c)
135 #define fini_completion(c) do { } while (0)
138 * semaphore "implementation" (use Linux kernel's primitives)
139 * - DEFINE_SEMAPHORE(name)
140 * - sema_init(sem, val)
143 * - down_interruptible(sem)
144 * - down_trylock(sem)
148 * mutex "implementation" (use Linux kernel's primitives)
150 * - DEFINE_MUTEX(name)
155 * - mutex_is_locked(x)
159 #ifndef lockdep_set_class
161 /**************************************************************************
163 * Lockdep "implementation". Also see liblustre.h
165 **************************************************************************/
167 struct lock_class_key {
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. */
177 static inline void lockdep_off(void)
181 static inline void lockdep_on(void)
186 #endif /* lockdep_set_class */
188 #ifndef CONFIG_DEBUG_LOCK_ALLOC
189 #ifndef mutex_lock_nested
190 #define mutex_lock_nested(mutex, subclass) mutex_lock(mutex)
193 #ifndef spin_lock_nested
194 #define spin_lock_nested(lock, subclass) spin_lock(lock)
197 #ifndef down_read_nested
198 #define down_read_nested(lock, subclass) down_read(lock)
201 #ifndef down_write_nested
202 #define down_write_nested(lock, subclass) down_write(lock)
204 #endif /* CONFIG_DEBUG_LOCK_ALLOC */
207 #endif /* __LIBCFS_LINUX_CFS_LOCK_H__ */