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 7 8 #include "device.h" 9 10 #include <compat/sys/mutex.h> 11 12 13 // these methods are bit unfriendly, a bit too much panic() around 14 15 struct mtx Giant; 16 struct rw_lock ifnet_rwlock; 17 struct mtx gIdStoreLock; 18 19 20 void 21 mtx_init(struct mtx *mutex, const char *name, const char *type, 22 int options) 23 { 24 if ((options & MTX_RECURSE) != 0) { 25 recursive_lock_init_etc(&mutex->u.recursive, name, 26 MUTEX_FLAG_CLONE_NAME); 27 } else { 28 mutex_init_etc(&mutex->u.mutex.lock, name, MUTEX_FLAG_CLONE_NAME); 29 mutex->u.mutex.owner = -1; 30 } 31 32 mutex->type = options; 33 } 34 35 36 void 37 mtx_destroy(struct mtx *mutex) 38 { 39 if ((mutex->type & MTX_RECURSE) != 0) 40 recursive_lock_destroy(&mutex->u.recursive); 41 else 42 mutex_destroy(&mutex->u.mutex.lock); 43 } 44 45 46 status_t 47 init_mutexes() 48 { 49 mtx_init(&Giant, "Banana Giant", NULL, MTX_DEF); 50 rw_lock_init(&ifnet_rwlock, "gDevices"); 51 mtx_init(&gIdStoreLock, "Identity Store", NULL, MTX_DEF); 52 53 return B_OK; 54 } 55 56 57 void 58 uninit_mutexes() 59 { 60 mtx_destroy(&Giant); 61 rw_lock_destroy(&ifnet_rwlock); 62 mtx_destroy(&gIdStoreLock); 63 } 64