1/*
2 * Copyright 2009, Colin G��nther, coling@gmx.de.
3 * Copyright 2007, Hugo Santos. All Rights Reserved.
4 * Distributed under the terms of the MIT License.
5 */
6#ifndef _FBSD_COMPAT_SYS_MUTEX_H_
7#define _FBSD_COMPAT_SYS_MUTEX_H_
8
9
10#include <sys/haiku-module.h>
11
12#include <sys/queue.h>
13#include <sys/_mutex.h>
14#include <sys/pcpu.h>
15#include <machine/atomic.h>
16#include <machine/cpufunc.h>
17
18
19#define MA_OWNED		0x1
20#define MA_NOTOWNED		0x2
21#define MA_RECURSED		0x4
22#define MA_NOTRECURSED	0x8
23
24#define mtx_assert(mtx, what)
25
26#define MTX_DEF				0x0000
27#define MTX_RECURSE			0x0004
28#define MTX_QUIET			0x40000
29#define MTX_DUPOK			0x400000
30
31
32#define MTX_NETWORK_LOCK	"network driver"
33
34#define NET_LOCK_GIANT()
35#define NET_UNLOCK_GIANT()
36
37
38extern struct mtx Giant;
39
40
41void mtx_init(struct mtx*, const char*, const char*, int);
42void mtx_destroy(struct mtx*);
43
44
45static inline void
46mtx_lock(struct mtx* mutex)
47{
48	if (mutex->type == MTX_DEF) {
49		mutex_lock(&mutex->u.mutex.lock);
50		mutex->u.mutex.owner = find_thread(NULL);
51	} else if (mutex->type == MTX_RECURSE)
52		recursive_lock_lock(&mutex->u.recursive);
53}
54
55
56static inline void
57mtx_unlock(struct mtx* mutex)
58{
59	if (mutex->type == MTX_DEF) {
60		mutex->u.mutex.owner = -1;
61		mutex_unlock(&mutex->u.mutex.lock);
62	} else if (mutex->type == MTX_RECURSE)
63		recursive_lock_unlock(&mutex->u.recursive);
64}
65
66
67static inline int
68mtx_initialized(struct mtx* mutex)
69{
70	/* TODO */
71	return 1;
72}
73
74
75static inline int
76mtx_owned(struct mtx* mutex)
77{
78	if (mutex->type == MTX_DEF)
79		return mutex->u.mutex.owner == find_thread(NULL);
80	if (mutex->type == MTX_RECURSE) {
81#if KDEBUG
82		return mutex->u.recursive.lock.holder == find_thread(NULL);
83#else
84		return mutex->u.recursive.holder == find_thread(NULL);
85#endif
86	}
87
88	return 0;
89}
90
91
92#endif	/* _FBSD_COMPAT_SYS_MUTEX_H_ */
93