Fix cstyle issue in mutex.h

This patch only addresses the issues identified by the style checker
in mutex.h.  It contains no functional changes.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tim Chase <tim@chase2k.com>
Issue #435
This commit is contained in:
Brian Behlendorf 2015-02-25 09:20:38 -08:00
parent c1bc8e610b
commit a900e28e71

View File

@ -1,4 +1,4 @@
/*****************************************************************************\ /*
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
* Copyright (C) 2007 The Regents of the University of California. * Copyright (C) 2007 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
@ -20,72 +20,68 @@
* *
* You should have received a copy of the GNU General Public License along * You should have received a copy of the GNU General Public License along
* with the SPL. If not, see <http://www.gnu.org/licenses/>. * with the SPL. If not, see <http://www.gnu.org/licenses/>.
\*****************************************************************************/ */
#ifndef _SPL_MUTEX_H #ifndef _SPL_MUTEX_H
#define _SPL_MUTEX_H #define _SPL_MUTEX_H
#include <sys/types.h> #include <sys/types.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/compiler_compat.h> #include <linux/compiler_compat.h>
typedef enum { typedef enum {
MUTEX_DEFAULT = 0, MUTEX_DEFAULT = 0,
MUTEX_SPIN = 1, MUTEX_SPIN = 1,
MUTEX_ADAPTIVE = 2 MUTEX_ADAPTIVE = 2
} kmutex_type_t; } kmutex_type_t;
#if defined(HAVE_MUTEX_OWNER) && defined(CONFIG_SMP) && \ #if defined(HAVE_MUTEX_OWNER) && defined(CONFIG_SMP) && \
!defined(CONFIG_DEBUG_MUTEXES) !defined(CONFIG_DEBUG_MUTEXES)
/*
* We define a 1-field struct rather than a straight typedef to enforce type
* safety.
*/
typedef struct { typedef struct {
struct mutex m; struct mutex m;
spinlock_t m_lock; /* used for serializing mutex_exit */ spinlock_t m_lock; /* used for serializing mutex_exit */
} kmutex_t; } kmutex_t;
static inline kthread_t * static inline kthread_t *
mutex_owner(kmutex_t *mp) mutex_owner(kmutex_t *mp)
{ {
#if defined(HAVE_MUTEX_OWNER_TASK_STRUCT) #if defined(HAVE_MUTEX_OWNER_TASK_STRUCT)
return ACCESS_ONCE(mp->m.owner); return (ACCESS_ONCE(mp->m.owner));
#else #else
struct thread_info *owner = ACCESS_ONCE(mp->m.owner); struct thread_info *owner = ACCESS_ONCE(mp->m.owner);
if (owner) if (owner)
return owner->task; return (owner->task);
return NULL; return (NULL);
#endif #endif
} }
#define mutex_owned(mp) (mutex_owner(mp) == current) #define mutex_owned(mp) (mutex_owner(mp) == current)
#define MUTEX_HELD(mp) mutex_owned(mp) #define MUTEX_HELD(mp) mutex_owned(mp)
#define MUTEX_NOT_HELD(mp) (!MUTEX_HELD(mp)) #define MUTEX_NOT_HELD(mp) (!MUTEX_HELD(mp))
#undef mutex_init #undef mutex_init
#define mutex_init(mp, name, type, ibc) \ #define mutex_init(mp, name, type, ibc) \
({ \ { \
static struct lock_class_key __key; \ static struct lock_class_key __key; \
ASSERT(type == MUTEX_DEFAULT); \ ASSERT(type == MUTEX_DEFAULT); \
\ \
__mutex_init(&(mp)->m, #mp, &__key); \ __mutex_init(&(mp)->m, #mp, &__key); \
spin_lock_init(&(mp)->m_lock); \ spin_lock_init(&(mp)->m_lock); \
}) }
#undef mutex_destroy #undef mutex_destroy
#define mutex_destroy(mp) \ #define mutex_destroy(mp) \
({ \ { \
VERIFY3P(mutex_owner(mp), ==, NULL); \ VERIFY3P(mutex_owner(mp), ==, NULL); \
}) }
#define mutex_tryenter(mp) mutex_trylock(&(mp)->m) #define mutex_tryenter(mp) mutex_trylock(&(mp)->m)
#define mutex_enter(mp) \ #define mutex_enter(mp) \
({ \ { \
ASSERT3P(mutex_owner(mp), !=, current); \ ASSERT3P(mutex_owner(mp), !=, current); \
mutex_lock(&(mp)->m); \ mutex_lock(&(mp)->m); \
}) }
/* /*
* The reason for the spinlock: * The reason for the spinlock:
* *
@ -105,39 +101,39 @@ mutex_owner(kmutex_t *mp)
* *
* See http://lwn.net/Articles/575477/ for the information about the race. * See http://lwn.net/Articles/575477/ for the information about the race.
*/ */
#define mutex_exit(mp) \ #define mutex_exit(mp) \
({ \ { \
spin_lock(&(mp)->m_lock); \ spin_lock(&(mp)->m_lock); \
mutex_unlock(&(mp)->m); \ mutex_unlock(&(mp)->m); \
spin_unlock(&(mp)->m_lock); \ spin_unlock(&(mp)->m_lock); \
}) }
#else /* HAVE_MUTEX_OWNER */ #else /* HAVE_MUTEX_OWNER */
typedef struct { typedef struct {
struct mutex m_mutex; struct mutex m_mutex;
spinlock_t m_lock; spinlock_t m_lock; /* used for serializing mutex_exit */
kthread_t *m_owner; kthread_t *m_owner;
} kmutex_t; } kmutex_t;
#define MUTEX(mp) (&((mp)->m_mutex)) #define MUTEX(mp) (&((mp)->m_mutex))
static inline void static inline void
spl_mutex_set_owner(kmutex_t *mp) spl_mutex_set_owner(kmutex_t *mp)
{ {
mp->m_owner = current; mp->m_owner = current;
} }
static inline void static inline void
spl_mutex_clear_owner(kmutex_t *mp) spl_mutex_clear_owner(kmutex_t *mp)
{ {
mp->m_owner = NULL; mp->m_owner = NULL;
} }
#define mutex_owner(mp) (ACCESS_ONCE((mp)->m_owner)) #define mutex_owner(mp) (ACCESS_ONCE((mp)->m_owner))
#define mutex_owned(mp) (mutex_owner(mp) == current) #define mutex_owned(mp) (mutex_owner(mp) == current)
#define MUTEX_HELD(mp) mutex_owned(mp) #define MUTEX_HELD(mp) mutex_owned(mp)
#define MUTEX_NOT_HELD(mp) (!MUTEX_HELD(mp)) #define MUTEX_NOT_HELD(mp) (!MUTEX_HELD(mp))
/* /*
* The following functions must be a #define and not static inline. * The following functions must be a #define and not static inline.
@ -146,46 +142,46 @@ spl_mutex_clear_owner(kmutex_t *mp)
* for the built in kernel lock analysis tools * for the built in kernel lock analysis tools
*/ */
#undef mutex_init #undef mutex_init
#define mutex_init(mp, name, type, ibc) \ #define mutex_init(mp, name, type, ibc) \
({ \ { \
static struct lock_class_key __key; \ static struct lock_class_key __key; \
ASSERT(type == MUTEX_DEFAULT); \ ASSERT(type == MUTEX_DEFAULT); \
\ \
__mutex_init(MUTEX(mp), #mp, &__key); \ __mutex_init(MUTEX(mp), #mp, &__key); \
spin_lock_init(&(mp)->m_lock); \ spin_lock_init(&(mp)->m_lock); \
spl_mutex_clear_owner(mp); \ spl_mutex_clear_owner(mp); \
}) }
#undef mutex_destroy #undef mutex_destroy
#define mutex_destroy(mp) \ #define mutex_destroy(mp) \
({ \ { \
VERIFY3P(mutex_owner(mp), ==, NULL); \ VERIFY3P(mutex_owner(mp), ==, NULL); \
}
#define mutex_tryenter(mp) \
({ \
int _rc_; \
\
if ((_rc_ = mutex_trylock(MUTEX(mp))) == 1) \
spl_mutex_set_owner(mp); \
\
_rc_; \
}) })
#define mutex_tryenter(mp) \ #define mutex_enter(mp) \
({ \ { \
int _rc_; \ ASSERT3P(mutex_owner(mp), !=, current); \
\ mutex_lock(MUTEX(mp)); \
if ((_rc_ = mutex_trylock(MUTEX(mp))) == 1) \ spl_mutex_set_owner(mp); \
spl_mutex_set_owner(mp); \ }
\
_rc_; \
})
#define mutex_enter(mp) \ #define mutex_exit(mp) \
({ \ { \
ASSERT3P(mutex_owner(mp), !=, current); \ spin_lock(&(mp)->m_lock); \
mutex_lock(MUTEX(mp)); \ spl_mutex_clear_owner(mp); \
spl_mutex_set_owner(mp); \ mutex_unlock(MUTEX(mp)); \
}) spin_unlock(&(mp)->m_lock); \
}
#define mutex_exit(mp) \
({ \
spin_lock(&(mp)->m_lock); \
spl_mutex_clear_owner(mp); \
mutex_unlock(MUTEX(mp)); \
spin_unlock(&(mp)->m_lock); \
})
#endif /* HAVE_MUTEX_OWNER */ #endif /* HAVE_MUTEX_OWNER */