btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / src / add-ons / kernel / file_systems / googlefs / lock.h
blobd407a27fd7ffe3807bea0ac54e2f74a66b9814b1
1 /*
2 Copyright 1999, Be Incorporated. All Rights Reserved.
3 This file may be used under the terms of the Be Sample Code License.
4 */
6 #ifndef _LOCK_H
7 #define _LOCK_H
9 #include <BeBuild.h>
11 #include <OS.h>
13 typedef struct lock lock;
14 typedef struct mlock mlock;
16 struct lock {
17 sem_id s;
18 long c;
21 struct mlock {
22 sem_id s;
25 extern _IMPEXP_KERNEL int new_lock(lock *l, const char *name);
26 extern _IMPEXP_KERNEL int free_lock(lock *l);
28 static inline status_t LOCK(lock *l)
30 if (atomic_add(&(l->c), -1) <= 0)
31 return acquire_sem(l->s);
32 return B_OK;
35 static inline status_t UNLOCK(lock *l)
37 if (atomic_add(&(l->c), 1) < 0)
38 return release_sem(l->s);
39 return B_OK;
43 //#define LOCK(l) if (atomic_add(&l.c, -1) <= 0) acquire_sem(l.s);
44 //#define UNLOCK(l) if (atomic_add(&l.c, 1) < 0) release_sem(l.s);
46 extern _IMPEXP_KERNEL int new_mlock(mlock *l, long c, const char *name);
47 extern _IMPEXP_KERNEL int free_mlock(mlock *l);
49 #define LOCKM(l,cnt) acquire_sem_etc(l.s, cnt, 0, 0)
50 #define UNLOCKM(l,cnt) release_sem_etc(l.s, cnt, 0)
52 #endif