xref: /haiku/src/add-ons/kernel/file_systems/userlandfs/server/beos/lock.h (revision 99d027cd0238c1d86da86d7c3f4200509ccc61a6)
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 USERLAND_FS_BEOS_LOCK_H
7 #define USERLAND_FS_BEOS_LOCK_H
8 
9 #include <BeBuild.h>
10 
11 #include <OS.h>
12 
13 #ifndef _IMPEXP_KERNEL
14 #define _IMPEXP_KERNEL
15 #endif
16 
17 #ifdef __cplusplus
18 	extern "C" {
19 #else
20 	typedef struct beos_lock beos_lock;
21 	typedef struct beos_mlock beos_mlock;
22 #endif
23 
24 
25 struct beos_lock {
26 	sem_id		s;
27 	long		c;
28 };
29 
30 struct beos_mlock {
31 	sem_id		s;
32 };
33 
34 extern _IMPEXP_KERNEL int	beos_new_lock(beos_lock *l, const char *name);
35 extern _IMPEXP_KERNEL int	beos_free_lock(beos_lock *l);
36 
37 #ifdef LOCK
38 #undef LOCK
39 #endif
40 
41 #define	LOCK(l)		if (atomic_add(&l.c, -1) <= 0) acquire_sem(l.s);
42 #define	UNLOCK(l)	if (atomic_add(&l.c, 1) < 0) release_sem(l.s);
43 
44 extern _IMPEXP_KERNEL int	beos_new_mlock(beos_mlock *l, long c, const char *name);
45 extern _IMPEXP_KERNEL int	beos_free_mlock(beos_mlock *l);
46 
47 #define		LOCKM(l,cnt)	acquire_sem_etc(l.s, cnt, 0, 0)
48 #define		UNLOCKM(l,cnt)	release_sem_etc(l.s, cnt, 0)
49 
50 
51 #ifdef __cplusplus
52   } // extern "C"
53 #endif
54 
55 #endif
56