X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=libcfs%2Finclude%2Flibcfs%2Flinux%2Flinux-lock.h;h=6f0b84d53bb1c9aa931e8407e91b33380cde3010;hb=f1a411bc79f8acc61bc1a18e42558513e44a2da6;hp=d78e2b5705c25d2e356b2baff7017f712aa01041;hpb=7c06e02cd77ab8359f48ecf6b5f83fa4d14c513a;p=fs%2Flustre-release.git diff --git a/libcfs/include/libcfs/linux/linux-lock.h b/libcfs/include/libcfs/linux/linux-lock.h index d78e2b5..6f0b84d 100644 --- a/libcfs/include/libcfs/linux/linux-lock.h +++ b/libcfs/include/libcfs/linux/linux-lock.h @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -26,8 +24,10 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2012, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -49,7 +49,7 @@ #error This include is only for kernel use. #endif -#include +#include /* * IMPORTANT !!!!!!!! @@ -59,22 +59,37 @@ * declared by CFS_DECL_* should be initialized explicitly. */ - /* - * spin_lock (use Linux kernel's primitives) + * spin_lock "implementation" (use Linux kernel's primitives) * * - spin_lock_init(x) * - spin_lock(x) + * - spin_lock_bh(x) + * - spin_lock_bh_init(x) * - spin_unlock(x) + * - spin_unlock_bh(x) * - spin_trylock(x) + * - assert_spin_locked(x) * + * - spin_lock_irq(x) * - spin_lock_irqsave(x, f) * - spin_unlock_irqrestore(x, f) + * - read_lock_irqsave(lock, f) + * - write_lock_irqsave(lock, f) + * - write_unlock_irqrestore(lock, f) + */ + +/* + * spinlock "implementation" */ + + + /* - * rw_semaphore (use Linux kernel's primitives) + * rw_semaphore "implementation" (use Linux kernel's primitives) * + * - sema_init(x) * - init_rwsem(x) * - down_read(x) * - up_read(x) @@ -82,39 +97,66 @@ * - up_write(x) */ + +#define fini_rwsem(s) do {} while (0) + + /* - * rwlock_t (use Linux kernel's primitives) + * rwlock_t "implementation" (use Linux kernel's primitives) * * - rwlock_init(x) * - read_lock(x) * - read_unlock(x) * - write_lock(x) * - write_unlock(x) - */ - -/* - * mutex: + * - write_lock_bh(x) + * - write_unlock_bh(x) * - * - init_mutex(x) - * - init_mutex_locked(x) - * - mutex_up(x) - * - mutex_down(x) + * - RW_LOCK_UNLOCKED */ -#define init_mutex(x) init_MUTEX(x) -#define init_mutex_locked(x) init_MUTEX_LOCKED(x) -#define mutex_up(x) up(x) -#define mutex_down(x) down(x) -#define mutex_down_trylock(x) down_trylock(x) + + +#ifndef DEFINE_RWLOCK +#define DEFINE_RWLOCK(lock) rwlock_t lock = __RW_LOCK_UNLOCKED(lock) +#endif /* - * completion (use Linux kernel's primitives) + * completion "implementation" (use Linux kernel's primitives) * - * - init_complition(c) + * - DECLARE_COMPLETION(work) + * - INIT_COMPLETION(c) + * - COMPLETION_INITIALIZER(work) + * - init_completion(c) * - complete(c) * - wait_for_completion(c) + * - wait_for_completion_interruptible(c) + * - fini_completion(c) + */ +#define fini_completion(c) do { } while (0) + +/* + * semaphore "implementation" (use Linux kernel's primitives) + * - DEFINE_SEMAPHORE(name) + * - sema_init(sem, val) + * - up(sem) + * - down(sem) + * - down_interruptible(sem) + * - down_trylock(sem) */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) +/* + * mutex "implementation" (use Linux kernel's primitives) + * + * - DEFINE_MUTEX(name) + * - mutex_init(x) + * - mutex_lock(x) + * - mutex_unlock(x) + * - mutex_trylock(x) + * - mutex_is_locked(x) + * - mutex_destroy(x) + */ + +#ifndef lockdep_set_class /************************************************************************** * @@ -123,46 +165,43 @@ **************************************************************************/ struct lock_class_key { - ; + ; }; -static inline void lockdep_set_class(void *lock, struct lock_class_key *key) -{ -} - -/************************************************************************** - * - * Mutex interface from newer Linux kernels. - * - * this augments compatibility interface from include/linux/mutex.h - * - **************************************************************************/ +#define lockdep_set_class(lock, key) \ + do { (void)sizeof(lock); (void)sizeof(key); } while (0) +/* This has to be a macro, so that `subclass' can be undefined in kernels + * that do not support lockdep. */ -#ifndef mutex -# define mutex semaphore -#endif -static inline void mutex_lock_nested(struct mutex *mutex, unsigned int subclass) +static inline void lockdep_off(void) { - return down(mutex); } -static inline void mutex_destroy(struct mutex *lock) +static inline void lockdep_on(void) { } +#else -/* - * This is for use in assertions _only_, i.e., this function should always - * return 1. - * - * \retval 1 mutex is locked. - * - * \retval 0 mutex is not locked. This should never happen. - */ -static inline int mutex_is_locked(struct mutex *lock) -{ - return !!down_trylock(lock); -} +#endif /* lockdep_set_class */ + +#ifndef CONFIG_DEBUG_LOCK_ALLOC +#ifndef mutex_lock_nested +#define mutex_lock_nested(mutex, subclass) mutex_lock(mutex) #endif +#ifndef spin_lock_nested +#define spin_lock_nested(lock, subclass) spin_lock(lock) #endif + +#ifndef down_read_nested +#define down_read_nested(lock, subclass) down_read(lock) +#endif + +#ifndef down_write_nested +#define down_write_nested(lock, subclass) down_write(lock) +#endif +#endif /* CONFIG_DEBUG_LOCK_ALLOC */ + + +#endif /* __LIBCFS_LINUX_CFS_LOCK_H__ */