1#ifndef _BEOS_COMPATIBILITY_H_
2#define _BEOS_COMPATIBILITY_H_
3#ifndef HAIKU_TARGET_PLATFORM_HAIKU
4
5typedef struct mutex {
6	sem_id	sem;
7	int32	count;
8} mutex;
9
10
11static inline status_t
12mutex_init(mutex *ben, const char *name)
13{
14	if (ben == NULL || name == NULL)
15		return B_BAD_VALUE;
16
17	ben->count = 1;
18	ben->sem = create_sem(0, name);
19	if (ben->sem >= B_OK)
20		return B_OK;
21
22	return ben->sem;
23}
24
25
26static inline void
27mutex_destroy(mutex *ben)
28{
29	delete_sem(ben->sem);
30	ben->sem = -1;
31}
32
33
34static inline status_t
35mutex_lock(mutex *ben)
36{
37	if (atomic_add(&ben->count, -1) <= 0)
38		return acquire_sem(ben->sem);
39
40	return B_OK;
41}
42
43
44static inline status_t
45mutex_unlock(mutex *ben)
46{
47	if (atomic_add(&ben->count, 1) < 0)
48		return release_sem(ben->sem);
49
50	return B_OK;
51}
52
53#endif // HAIKU_TARGET_PLATFORM_HAIKU
54#endif // _BEOS_COMPATIBILITY_H_
55