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