Inline class with BLocker interface wrapping a recursive_lock. Could probably

moved to headers/private/kernel/util.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29409 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2009-03-05 23:23:01 +00:00
parent 8dcef9a6ad
commit 2b0eb640d4
1 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,72 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _USERLAND_FS_RECURSIVE_LOCK_H
#define _USERLAND_FS_RECURSIVE_LOCK_H
#include <lock.h> // private/kernel
namespace UserlandFSUtil {
class RecursiveLock {
public:
RecursiveLock(bool benaphore_style = true)
{
recursive_lock_init(&fLock, "anonymous locker");
}
RecursiveLock(const char *name, bool benaphore_style = true)
{
recursive_lock_init_etc(&fLock, name, MUTEX_FLAG_CLONE_NAME);
}
~RecursiveLock()
{
recursive_lock_destroy(&fLock);
}
status_t InitCheck() const
{
return B_OK;
}
bool Lock(void)
{
return recursive_lock_lock(&fLock) == B_OK;
}
void Unlock(void)
{
recursive_lock_unlock(&fLock);
}
thread_id LockingThread(void) const
{
return RECURSIVE_LOCK_HOLDER(&fLock);
}
bool IsLocked(void) const
{
return RECURSIVE_LOCK_HOLDER(&fLock) == find_thread(NULL);
}
int32 CountLocks(void) const
{
int32 count = recursive_lock_get_recursion(
const_cast<recursive_lock*>(&fLock));
return count >= 0 ? count : 0;
}
private:
recursive_lock fLock;
};
}; // namespace UserlandFSUtil
using UserlandFSUtil::RecursiveLock;
#endif // _USERLAND_FS_RECURSIVE_LOCK_H