mirror_zfs/include/sys/mutex.h
behlendo 9ab1ac14ad Commit adaptive mutexes. This seems to have introduced some new
crashes but it's not clear to me yet if these are a problem with
the mutex implementation or ZFSs usage of it.

Minor taskq fixes to add new tasks to the end of the pending list.

Minor enhansements to the debug infrastructure.



git-svn-id: https://outreach.scidac.gov/svn/spl/trunk@94 7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c
2008-05-05 20:18:49 +00:00

97 lines
2.4 KiB
C

#ifndef _SPL_MUTEX_H
#define _SPL_MUTEX_H
#ifdef __cplusplus
extern "C" {
#endif
#include <linux/module.h>
#include <linux/hardirq.h>
#include <sys/types.h>
#include <sys/kmem.h>
//#define DEBUG_MUTEX
#undef DEBUG_MUTEX
#define MUTEX_DEFAULT 0
#define MUTEX_SPIN 1
#define MUTEX_ADAPTIVE 2
#define MUTEX_ENTER_TOTAL 0
#define MUTEX_ENTER_NOT_HELD 1
#define MUTEX_ENTER_SPIN 2
#define MUTEX_ENTER_SLEEP 3
#define MUTEX_TRYENTER_TOTAL 4
#define MUTEX_TRYENTER_NOT_HELD 5
#define MUTEX_STATS_SIZE 6
#define KM_MAGIC 0x42424242
#define KM_POISON 0x84
typedef struct {
int32_t km_magic;
int16_t km_type;
int16_t km_name_size;
char *km_name;
struct task_struct *km_owner;
struct semaphore *km_sem;
#ifdef DEBUG_MUTEX
int *km_stats;
struct list_head km_list;
#endif
} kmutex_t;
extern int mutex_spin_max;
#ifdef DEBUG_MUTEX
extern int mutex_stats[MUTEX_STATS_SIZE];
extern struct mutex mutex_stats_lock;
extern struct list_head mutex_stats_list;
#define MUTEX_STAT_INC(stats, stat) ((stats)[stat]++)
#else
#define MUTEX_STAT_INC(stats, stat)
#endif
int spl_mutex_init(void);
void spl_mutex_fini(void);
extern void __spl_mutex_init(kmutex_t *mp, char *name, int type, void *ibc);
extern void __spl_mutex_destroy(kmutex_t *mp);
extern int __mutex_tryenter(kmutex_t *mp);
extern void __mutex_enter(kmutex_t *mp);
extern void __mutex_exit(kmutex_t *mp);
extern int __mutex_owned(kmutex_t *mp);
extern kthread_t *__spl_mutex_owner(kmutex_t *mp);
#undef mutex_init
#undef mutex_destroy
#define mutex_init(mp, name, type, ibc) \
({ \
__ENTRY(S_MUTEX); \
if ((name) == NULL) \
__spl_mutex_init(mp, #mp, type, ibc); \
else \
__spl_mutex_init(mp, name, type, ibc); \
__EXIT(S_MUTEX); \
})
#define mutex_destroy(mp) \
({ \
__ENTRY(S_MUTEX); \
__spl_mutex_destroy(mp); \
__EXIT(S_MUTEX); \
})
#define mutex_tryenter(mp) __mutex_tryenter(mp)
#define mutex_enter(mp) __mutex_enter(mp)
#define mutex_exit(mp) __mutex_exit(mp)
#define mutex_owned(mp) __mutex_owned(mp)
#define mutex_owner(mp) __spl_mutex_owner(mp)
#define MUTEX_HELD(mp) mutex_owned(mp)
#ifdef __cplusplus
}
#endif
#endif /* _SPL_MUTEX_H */