]>
git.proxmox.com Git - mirror_spl-debian.git/blob - include/linux-mutex.h
8 /* See the "Big Theory Statement" in solaris mutex.c.
10 * Spin mutexes apparently aren't needed by zfs so we assert
13 * Our impementation of adaptive mutexes aren't really adaptive.
14 * They go to sleep every time.
17 #define MUTEX_DEFAULT 0
18 #define MUTEX_HELD(x) (mutex_owned(x))
20 #define KM_MAGIC 0x42424242
21 #define KM_POISON 0x84
26 struct task_struct
*km_owner
;
27 struct semaphore km_sem
;
31 static __inline__
void
32 mutex_init(kmutex_t
*mp
, char *name
, int type
, void *ibc
)
34 BUG_ON(ibc
!= NULL
); /* XXX - Spin mutexes not needed? */
35 BUG_ON(type
!= MUTEX_DEFAULT
); /* XXX - Only default type supported? */
37 mp
->km_magic
= KM_MAGIC
;
38 sema_init(&mp
->km_sem
, 1);
43 mp
->km_name
= kmalloc(strlen(name
) + 1, GFP_KERNEL
);
45 strcpy(mp
->km_name
, name
);
50 static __inline__
void
51 mutex_destroy(kmutex_t
*mp
)
53 BUG_ON(mp
->km_magic
!= KM_MAGIC
);
58 memset(mp
, KM_POISON
, sizeof(*mp
));
61 static __inline__
void
62 mutex_enter(kmutex_t
*mp
)
64 BUG_ON(mp
->km_magic
!= KM_MAGIC
);
65 down(&mp
->km_sem
); /* Will check in_atomic() for us */
66 BUG_ON(mp
->km_owner
!= NULL
);
67 mp
->km_owner
= current
;
70 /* Return 1 if we acquired the mutex, else zero.
73 mutex_tryenter(kmutex_t
*mp
)
77 BUG_ON(mp
->km_magic
!= KM_MAGIC
);
78 result
= down_trylock(&mp
->km_sem
); /* returns 0 if acquired */
80 BUG_ON(mp
->km_owner
!= NULL
);
81 mp
->km_owner
= current
;
87 static __inline__
void
88 mutex_exit(kmutex_t
*mp
)
90 BUG_ON(mp
->km_magic
!= KM_MAGIC
);
91 BUG_ON(mp
->km_owner
!= current
);
96 /* Return 1 if mutex is held by current process, else zero.
99 mutex_owned(kmutex_t
*mp
)
101 BUG_ON(mp
->km_magic
!= KM_MAGIC
);
102 return (mp
->km_owner
== current
);
105 /* Return owner if mutex is owned, else NULL.
107 static __inline__ kthread_t
*
108 mutex_owner(kmutex_t
*mp
)
110 BUG_ON(mp
->km_magic
!= KM_MAGIC
);
118 #endif /* _LINUX_MUTEX_H */