1 /* 2 * Copyright 2007, Hugo Santos. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Hugo Santos, hugosantos@gmail.com 7 */ 8 9 #include "device.h" 10 11 #include <compat/sys/mutex.h> 12 13 14 // these methods are bit unfriendly, a bit too much panic() around 15 16 struct mtx Giant; 17 18 19 void 20 mtx_init(struct mtx *m, const char *name, const char *type, int opts) 21 { 22 if (opts == MTX_DEF) { 23 if (mutex_init(&m->u.mutex, name) < B_OK) 24 panic("Panic! Dance like it's 1979, we ran out of semaphores"); 25 } else if (opts == MTX_RECURSE) { 26 if (recursive_lock_init(&m->u.recursive, name) < B_OK) 27 panic("Hell just froze as someone was trying to init a recursive mutex."); 28 } else 29 panic("Uh-oh, someone is pressing the wrong buttons"); 30 31 m->type = opts; 32 } 33 34 35 void 36 mtx_destroy(struct mtx *m) 37 { 38 if (m->type == MTX_DEF) { 39 mutex_destroy(&m->u.mutex); 40 } else if (m->type == MTX_RECURSE) { 41 recursive_lock_destroy(&m->u.recursive); 42 } else 43 panic("Uh-oh, someone is pressing the wrong buttons"); 44 } 45 46 47 status_t 48 init_mutexes() 49 { 50 mtx_init(&Giant, "Banana Giant", NULL, MTX_DEF); 51 52 return B_OK; 53 } 54 55 56 void 57 uninit_mutexes() 58 { 59 mtx_destroy(&Giant); 60 } 61 62