btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / userlandfs / shared / RecursiveLock.h
blob4626a922e09fa84ae45484b20fbb5c9d3343118d
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _USERLAND_FS_RECURSIVE_LOCK_H
6 #define _USERLAND_FS_RECURSIVE_LOCK_H
8 #include <lock.h> // private/kernel
11 namespace UserlandFSUtil {
14 class RecursiveLock {
15 public:
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);
26 ~RecursiveLock()
28 recursive_lock_destroy(&fLock);
31 status_t InitCheck() const
33 return B_OK;
36 bool Lock(void)
38 return recursive_lock_lock(&fLock) == B_OK;
41 void Unlock(void)
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;
63 private:
64 recursive_lock fLock;
68 }; // namespace UserlandFSUtil
70 using UserlandFSUtil::RecursiveLock;
72 #endif // _USERLAND_FS_RECURSIVE_LOCK_H