repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / installer / SemaphoreLocker.h
bloba88a9feb3003317bfec8fdd9e0eaacc33d3e6f6a
1 /*
2 * Copyright 2008-2009, Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5 #ifndef _SEMAPHORE_LOCKER_H
6 #define _SEMAPHORE_LOCKER_H
9 #include "AutoLocker.h"
12 class SemaphoreLocking {
13 public:
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> {
27 public:
28 inline SemaphoreLocker(sem_id semaphore, bool alreadyLocked = false,
29 bool lockIfNotLocked = true)
31 AutoLocker<sem_id, SemaphoreLocking>(),
32 fSem(semaphore)
34 SetTo(&fSem, alreadyLocked, lockIfNotLocked);
37 private:
38 sem_id fSem;
41 #endif // _SEMAPHORE_LOCKER_H