2 * Copyright 2008-2009, Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT License.
5 #ifndef _SEMAPHORE_LOCKER_H
6 #define _SEMAPHORE_LOCKER_H
9 #include "AutoLocker.h"
12 class SemaphoreLocking
{
14 inline bool Lock(sem_id
* lockable
)
16 return acquire_sem(*lockable
) == B_OK
;
19 inline void Unlock(sem_id
* lockable
)
21 release_sem(*lockable
);
26 class SemaphoreLocker
: public AutoLocker
<sem_id
, SemaphoreLocking
> {
28 inline SemaphoreLocker(sem_id semaphore
, bool alreadyLocked
= false,
29 bool lockIfNotLocked
= true)
31 AutoLocker
<sem_id
, SemaphoreLocking
>(),
34 SetTo(&fSem
, alreadyLocked
, lockIfNotLocked
);
41 #endif // _SEMAPHORE_LOCKER_H