mirror of
https://review.haiku-os.org/haiku
synced 2025-01-31 02:35:03 +01:00
8e3916f8ef
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32904 a95241bf-73f2-0310-859d-f6bbb57e9c96
42 lines
772 B
C++
42 lines
772 B
C++
/*
|
|
* Copyright 2008-2009, Stephan Aßmus <superstippi@gmx.de>
|
|
* All rights reserved. Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _SEMAPHORE_LOCKER_H
|
|
#define _SEMAPHORE_LOCKER_H
|
|
|
|
|
|
#include "AutoLocker.h"
|
|
|
|
|
|
class SemaphoreLocking {
|
|
public:
|
|
inline bool Lock(sem_id* lockable)
|
|
{
|
|
return acquire_sem(*lockable) == B_OK;
|
|
}
|
|
|
|
inline void Unlock(sem_id* lockable)
|
|
{
|
|
release_sem(*lockable);
|
|
}
|
|
};
|
|
|
|
|
|
class SemaphoreLocker : public AutoLocker<sem_id, SemaphoreLocking> {
|
|
public:
|
|
inline SemaphoreLocker(sem_id semaphore, bool alreadyLocked = false,
|
|
bool lockIfNotLocked = true)
|
|
:
|
|
AutoLocker<sem_id, SemaphoreLocking>(),
|
|
fSem(semaphore)
|
|
{
|
|
SetTo(&fSem, alreadyLocked, lockIfNotLocked);
|
|
}
|
|
|
|
private:
|
|
sem_id fSem;
|
|
};
|
|
|
|
#endif // _SEMAPHORE_LOCKER_H
|