]> git.proxmox.com Git - mirror_spl-debian.git/blame - include/sys/mutex.h
Remaining issues fixed after reenabled mutex debugging.
[mirror_spl-debian.git] / include / sys / mutex.h
CommitLineData
09b414e8 1#ifndef _SPL_MUTEX_H
2#define _SPL_MUTEX_H
f1ca4da6 3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
f1b59d26 8#include <linux/module.h>
115aed0d 9#include <linux/hardirq.h>
f4b37741 10#include <sys/types.h>
9ab1ac14 11#include <sys/kmem.h>
f1b59d26 12
4f86a887 13#define DEBUG_MUTEX
f1ca4da6 14
15#define MUTEX_DEFAULT 0
9ab1ac14 16#define MUTEX_SPIN 1
17#define MUTEX_ADAPTIVE 2
18
19#define MUTEX_ENTER_TOTAL 0
20#define MUTEX_ENTER_NOT_HELD 1
21#define MUTEX_ENTER_SPIN 2
22#define MUTEX_ENTER_SLEEP 3
23#define MUTEX_TRYENTER_TOTAL 4
24#define MUTEX_TRYENTER_NOT_HELD 5
25#define MUTEX_STATS_SIZE 6
f1ca4da6 26
27#define KM_MAGIC 0x42424242
28#define KM_POISON 0x84
f1b59d26 29
f1ca4da6 30typedef struct {
9ab1ac14 31 int32_t km_magic;
32 int16_t km_type;
33 int16_t km_name_size;
f1ca4da6 34 char *km_name;
35 struct task_struct *km_owner;
9ab1ac14 36 struct semaphore *km_sem;
37#ifdef DEBUG_MUTEX
38 int *km_stats;
39 struct list_head km_list;
40#endif
f1ca4da6 41} kmutex_t;
42
9ab1ac14 43extern int mutex_spin_max;
f1ca4da6 44
9ab1ac14 45#ifdef DEBUG_MUTEX
46extern int mutex_stats[MUTEX_STATS_SIZE];
4f86a887 47extern struct rw_semaphore mutex_stats_sem;
9ab1ac14 48extern struct list_head mutex_stats_list;
49#define MUTEX_STAT_INC(stats, stat) ((stats)[stat]++)
50#else
51#define MUTEX_STAT_INC(stats, stat)
52#endif
d61e12af 53
9ab1ac14 54int spl_mutex_init(void);
55void spl_mutex_fini(void);
d61e12af 56
9ab1ac14 57extern void __spl_mutex_init(kmutex_t *mp, char *name, int type, void *ibc);
58extern void __spl_mutex_destroy(kmutex_t *mp);
59extern int __mutex_tryenter(kmutex_t *mp);
60extern void __mutex_enter(kmutex_t *mp);
61extern void __mutex_exit(kmutex_t *mp);
62extern int __mutex_owned(kmutex_t *mp);
63extern kthread_t *__spl_mutex_owner(kmutex_t *mp);
f1ca4da6 64
9ab1ac14 65#undef mutex_init
66#undef mutex_destroy
d61e12af 67
9ab1ac14 68#define mutex_init(mp, name, type, ibc) \
69({ \
9ab1ac14 70 if ((name) == NULL) \
71 __spl_mutex_init(mp, #mp, type, ibc); \
72 else \
73 __spl_mutex_init(mp, name, type, ibc); \
9ab1ac14 74})
e8b31e84 75#define mutex_destroy(mp) __spl_mutex_destroy(mp)
9ab1ac14 76#define mutex_tryenter(mp) __mutex_tryenter(mp)
77#define mutex_enter(mp) __mutex_enter(mp)
78#define mutex_exit(mp) __mutex_exit(mp)
79#define mutex_owned(mp) __mutex_owned(mp)
80#define mutex_owner(mp) __spl_mutex_owner(mp)
81#define MUTEX_HELD(mp) mutex_owned(mp)
f1ca4da6 82
83#ifdef __cplusplus
84}
85#endif
86
09b414e8 87#endif /* _SPL_MUTEX_H */