/* * Copyright 2008-2009, Stephan Aßmus * 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 { public: inline SemaphoreLocker(sem_id semaphore, bool alreadyLocked = false, bool lockIfNotLocked = true) : AutoLocker(), fSem(semaphore) { SetTo(&fSem, alreadyLocked, lockIfNotLocked); } private: sem_id fSem; }; #endif // _SEMAPHORE_LOCKER_H