1 /* 2 Copyright 1999-2001, Be Incorporated. All Rights Reserved. 3 This file may be used under the terms of the Be Sample Code License. 4 */ 5 6 #ifndef _LOCK_H 7 #define _LOCK_H 8 9 #include <BeBuild.h> 10 11 #include <OS.h> 12 13 #ifdef __cplusplus 14 extern "C" { 15 #else 16 typedef struct lock lock; 17 typedef struct mlock mlock; 18 #endif 19 20 21 struct lock { 22 sem_id s; 23 long c; 24 }; 25 26 struct mlock { 27 sem_id s; 28 }; 29 30 extern _IMPEXP_KERNEL int new_lock(lock *l, const char *name); 31 extern _IMPEXP_KERNEL int free_lock(lock *l); 32 33 #define LOCK(l) if (atomic_add(&l.c, -1) <= 0) acquire_sem(l.s); 34 #define UNLOCK(l) if (atomic_add(&l.c, 1) < 0) release_sem(l.s); 35 36 extern _IMPEXP_KERNEL int new_mlock(mlock *l, long c, const char *name); 37 extern _IMPEXP_KERNEL int free_mlock(mlock *l); 38 39 #define LOCKM(l,cnt) acquire_sem_etc(l.s, cnt, 0, 0) 40 #define UNLOCKM(l,cnt) release_sem_etc(l.s, cnt, 0) 41 42 43 #ifdef __cplusplus 44 } // extern "C" 45 #endif 46 47 #endif 48