2 * Copyright 2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Axel Dörfler, axeld@pinc-software.de
21 static inline status_t
22 init_lock(struct lock
*lock
, const char *name
)
24 lock
->sem
= create_sem(0, name
);
27 return lock
->sem
< B_OK
? lock
->sem
: B_OK
;
32 uninit_lock(struct lock
*lock
)
34 delete_sem(lock
->sem
);
38 static inline status_t
39 acquire_lock(struct lock
*lock
)
41 if (atomic_add(&lock
->count
, 1) > 0)
42 return acquire_sem(lock
->sem
);
48 static inline status_t
49 release_lock(struct lock
*lock
)
51 if (atomic_add(&lock
->count
, -1) > 1)
52 return release_sem(lock
->sem
);
60 Autolock(struct lock
&lock
)
64 fStatus
= acquire_lock(fLock
);
76 return fStatus
== B_OK
;