-
-
Notifications
You must be signed in to change notification settings - Fork 338
/
mutex.c
63 lines (47 loc) · 1.14 KB
/
mutex.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright 2009, Colin Günther, coling@gmx.de.
* Copyright 2007, Hugo Santos. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#include "device.h"
#include <compat/sys/mutex.h>
// these methods are bit unfriendly, a bit too much panic() around
struct mtx Giant;
struct rw_lock ifnet_rwlock;
struct mtx gIdStoreLock;
void
mtx_init(struct mtx *mutex, const char *name, const char *type,
int options)
{
if (options & MTX_RECURSE) {
recursive_lock_init_etc(&mutex->u.recursive, name,
MUTEX_FLAG_CLONE_NAME);
} else {
mutex_init_etc(&mutex->u.mutex.lock, name, MUTEX_FLAG_CLONE_NAME);
mutex->u.mutex.owner = -1;
}
mutex->type = options;
}
void
mtx_destroy(struct mtx *mutex)
{
if (mutex->type & MTX_RECURSE)
recursive_lock_destroy(&mutex->u.recursive);
else
mutex_destroy(&mutex->u.mutex.lock);
}
status_t
init_mutexes()
{
mtx_init(&Giant, "Banana Giant", NULL, MTX_DEF);
rw_lock_init(&ifnet_rwlock, "gDevices");
mtx_init(&gIdStoreLock, "Identity Store", NULL, MTX_DEF);
return B_OK;
}
void
uninit_mutexes()
{
mtx_destroy(&Giant);
rw_lock_destroy(&ifnet_rwlock);
mtx_destroy(&gIdStoreLock);
}