typedef enum {
MUTEX_DEFAULT = 0,
MUTEX_SPIN = 1,
- MUTEX_ADAPTIVE = 2
+ MUTEX_ADAPTIVE = 2,
+ MUTEX_FSTRANS = 3,
} kmutex_type_t;
typedef struct {
struct mutex m_mutex;
+ kmutex_type_t m_type;
spinlock_t m_lock; /* used for serializing mutex_exit */
kthread_t *m_owner;
+ unsigned int m_saved_flags;
} kmutex_t;
#define MUTEX(mp) (&((mp)->m_mutex))
-
-static inline void
-spl_mutex_set_owner(kmutex_t *mp)
-{
- mp->m_owner = current;
-}
-
-static inline void
-spl_mutex_clear_owner(kmutex_t *mp)
-{
- mp->m_owner = NULL;
-}
-
#define mutex_owner(mp) (ACCESS_ONCE((mp)->m_owner))
#define mutex_owned(mp) (mutex_owner(mp) == current)
#define MUTEX_HELD(mp) mutex_owned(mp)
#define mutex_init(mp, name, type, ibc) \
{ \
static struct lock_class_key __key; \
- ASSERT(type == MUTEX_DEFAULT); \
+ \
+ ASSERT3P(mp, !=, NULL); \
+ ASSERT3P(ibc, ==, NULL); \
+ ASSERT((type == MUTEX_DEFAULT) || \
+ (type == MUTEX_ADAPTIVE) || \
+ (type == MUTEX_FSTRANS)); \
\
__mutex_init(MUTEX(mp), #mp, &__key); \
spin_lock_init(&(mp)->m_lock); \
- spl_mutex_clear_owner(mp); \
+ (mp)->m_type = type; \
+ (mp)->m_owner = NULL; \
+ (mp)->m_saved_flags = 0; \
}
#undef mutex_destroy
({ \
int _rc_; \
\
- if ((_rc_ = mutex_trylock(MUTEX(mp))) == 1) \
- spl_mutex_set_owner(mp); \
+ if ((_rc_ = mutex_trylock(MUTEX(mp))) == 1) { \
+ (mp)->m_owner = current; \
+ if ((mp)->m_type == MUTEX_FSTRANS) { \
+ (mp)->m_saved_flags = current->flags; \
+ current->flags |= PF_FSTRANS; \
+ } \
+ } \
\
_rc_; \
})
{ \
ASSERT3P(mutex_owner(mp), !=, current); \
mutex_lock(MUTEX(mp)); \
- spl_mutex_set_owner(mp); \
+ (mp)->m_owner = current; \
+ if ((mp)->m_type == MUTEX_FSTRANS) { \
+ (mp)->m_saved_flags = current->flags; \
+ current->flags |= PF_FSTRANS; \
+ } \
}
/*
#define mutex_exit(mp) \
{ \
spin_lock(&(mp)->m_lock); \
- spl_mutex_clear_owner(mp); \
+ if ((mp)->m_type == MUTEX_FSTRANS) { \
+ current->flags &= ~(PF_FSTRANS); \
+ current->flags |= (mp)->m_saved_flags; \
+ } \
+ (mp)->m_owner = NULL; \
mutex_unlock(MUTEX(mp)); \
spin_unlock(&(mp)->m_lock); \
}