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.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * libcfs/include/libcfs/linux/linux-lock.h
36 * Basic library routines.
39 #ifndef __LIBCFS_LINUX_CFS_LOCK_H__
40 #define __LIBCFS_LINUX_CFS_LOCK_H__
42 #ifndef __LIBCFS_LIBCFS_H__
43 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
47 #error This include is only for kernel use.
50 #include <linux/mutex.h>
55 * All locks' declaration are not guaranteed to be initialized,
56 * Althought some of they are initialized in Linux. All locks
57 * declared by CFS_DECL_* should be initialized explicitly.
61 * spin_lock "implementation" (use Linux kernel's primitives)
66 * - spin_lock_bh_init(x)
73 * - spin_lock_irqsave(x, f)
74 * - spin_unlock_irqrestore(x, f)
75 * - read_lock_irqsave(lock, f)
76 * - write_lock_irqsave(lock, f)
77 * - write_unlock_irqrestore(lock, f)
81 * spinlock "implementation"
88 * rw_semaphore "implementation" (use Linux kernel's primitives)
99 #define fini_rwsem(s) do {} while (0)
103 * rwlock_t "implementation" (use Linux kernel's primitives)
111 * - write_unlock_bh(x)
117 #ifndef DEFINE_RWLOCK
118 #define DEFINE_RWLOCK(lock) rwlock_t lock = __RW_LOCK_UNLOCKED(lock)
122 * completion "implementation" (use Linux kernel's primitives)
124 * - DECLARE_COMPLETION(work)
125 * - INIT_COMPLETION(c)
126 * - COMPLETION_INITIALIZER(work)
127 * - init_completion(c)
129 * - wait_for_completion(c)
130 * - wait_for_completion_interruptible(c)
131 * - fini_completion(c)
133 #define fini_completion(c) do { } while (0)
136 * semaphore "implementation" (use Linux kernel's primitives)
137 * - DEFINE_SEMAPHORE(name)
138 * - sema_init(sem, val)
141 * - down_interruptible(sem)
142 * - down_trylock(sem)
146 * mutex "implementation" (use Linux kernel's primitives)
148 * - DEFINE_MUTEX(name)
153 * - mutex_is_locked(x)
157 #ifndef lockdep_set_class
159 /**************************************************************************
161 * Lockdep "implementation". Also see liblustre.h
163 **************************************************************************/
165 struct lock_class_key {
169 #define lockdep_set_class(lock, key) \
170 do { (void)sizeof(lock); (void)sizeof(key); } while (0)
171 /* This has to be a macro, so that `subclass' can be undefined in kernels
172 * that do not support lockdep. */
175 static inline void lockdep_off(void)
179 static inline void lockdep_on(void)
184 #endif /* lockdep_set_class */
186 #ifndef CONFIG_DEBUG_LOCK_ALLOC
187 #ifndef mutex_lock_nested
188 #define mutex_lock_nested(mutex, subclass) mutex_lock(mutex)
191 #ifndef spin_lock_nested
192 #define spin_lock_nested(lock, subclass) spin_lock(lock)
195 #ifndef down_read_nested
196 #define down_read_nested(lock, subclass) down_read(lock)
199 #ifndef down_write_nested
200 #define down_write_nested(lock, subclass) down_write(lock)
202 #endif /* CONFIG_DEBUG_LOCK_ALLOC */
205 #endif /* __LIBCFS_LINUX_CFS_LOCK_H__ */