2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
5 #ifndef _USERLAND_FS_RECURSIVE_LOCK_H
6 #define _USERLAND_FS_RECURSIVE_LOCK_H
8 #include <lock.h> // private/kernel
11 namespace UserlandFSUtil
{
16 RecursiveLock(bool benaphore_style
= true)
18 recursive_lock_init(&fLock
, "anonymous locker");
21 RecursiveLock(const char *name
, bool benaphore_style
= true)
23 recursive_lock_init_etc(&fLock
, name
, MUTEX_FLAG_CLONE_NAME
);
28 recursive_lock_destroy(&fLock
);
31 status_t
InitCheck() const
38 return recursive_lock_lock(&fLock
) == B_OK
;
43 recursive_lock_unlock(&fLock
);
46 thread_id
LockingThread(void) const
48 return RECURSIVE_LOCK_HOLDER(&fLock
);
51 bool IsLocked(void) const
53 return RECURSIVE_LOCK_HOLDER(&fLock
) == find_thread(NULL
);
56 int32
CountLocks(void) const
58 int32 count
= recursive_lock_get_recursion(
59 const_cast<recursive_lock
*>(&fLock
));
60 return count
>= 0 ? count
: 0;
68 }; // namespace UserlandFSUtil
70 using UserlandFSUtil::RecursiveLock
;
72 #endif // _USERLAND_FS_RECURSIVE_LOCK_H