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