]>
git.proxmox.com Git - mirror_zfs.git/blob - include/sys/mutex.h
8 #include <linux/module.h>
11 /* See the "Big Theory Statement" in solaris mutex.c.
13 * Spin mutexes apparently aren't needed by zfs so we assert
16 * Our impementation of adaptive mutexes aren't really adaptive.
17 * They go to sleep every time.
20 #define MUTEX_DEFAULT 0
21 #define MUTEX_HELD(x) (mutex_owned(x))
23 #define KM_MAGIC 0x42424242
24 #define KM_POISON 0x84
29 struct task_struct
*km_owner
;
30 struct semaphore km_sem
;
34 static __inline__
void
35 mutex_init(kmutex_t
*mp
, char *name
, int type
, void *ibc
)
37 BUG_ON(ibc
!= NULL
); /* XXX - Spin mutexes not needed? */
38 BUG_ON(type
!= MUTEX_DEFAULT
); /* XXX - Only default type supported? */
40 mp
->km_magic
= KM_MAGIC
;
41 sema_init(&mp
->km_sem
, 1);
46 mp
->km_name
= kmalloc(strlen(name
) + 1, GFP_KERNEL
);
48 strcpy(mp
->km_name
, name
);
53 static __inline__
void
54 mutex_destroy(kmutex_t
*mp
)
56 BUG_ON(mp
->km_magic
!= KM_MAGIC
);
61 memset(mp
, KM_POISON
, sizeof(*mp
));
64 static __inline__
void
65 mutex_enter(kmutex_t
*mp
)
67 BUG_ON(mp
->km_magic
!= KM_MAGIC
);
68 down(&mp
->km_sem
); /* Will check in_atomic() for us */
69 BUG_ON(mp
->km_owner
!= NULL
);
70 mp
->km_owner
= current
;
73 /* Return 1 if we acquired the mutex, else zero.
76 mutex_tryenter(kmutex_t
*mp
)
80 BUG_ON(mp
->km_magic
!= KM_MAGIC
);
81 result
= down_trylock(&mp
->km_sem
); /* returns 0 if acquired */
83 BUG_ON(mp
->km_owner
!= NULL
);
84 mp
->km_owner
= current
;
90 static __inline__
void
91 mutex_exit(kmutex_t
*mp
)
93 BUG_ON(mp
->km_magic
!= KM_MAGIC
);
94 BUG_ON(mp
->km_owner
!= current
);
99 /* Return 1 if mutex is held by current process, else zero.
101 static __inline__
int
102 mutex_owned(kmutex_t
*mp
)
104 BUG_ON(mp
->km_magic
!= KM_MAGIC
);
105 return (mp
->km_owner
== current
);
108 /* Return owner if mutex is owned, else NULL.
110 static __inline__ kthread_t
*
111 mutex_owner(kmutex_t
*mp
)
113 BUG_ON(mp
->km_magic
!= KM_MAGIC
);
121 #endif /* _SPL_MUTEX_H */