xref: /haiku/headers/os/support/Locker.h (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
1 /*
2  * Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef	_LOCKER_H
6 #define	_LOCKER_H
7 
8 
9 #include <OS.h>
10 
11 
12 class BLocker {
13 	public:
14 		BLocker();
15 		BLocker(const char* name);
16 		BLocker(bool benaphoreStyle);
17 		BLocker(const char* name, bool benaphoreStyle);
18 		virtual ~BLocker();
19 
20 		bool Lock(void);
21 		status_t LockWithTimeout(bigtime_t timeout);
22 		void Unlock(void);
23 
24 		thread_id LockingThread(void) const;
25 		bool IsLocked(void) const;
26 		int32 CountLocks(void) const;
27 		int32 CountLockRequests(void) const;
28 		sem_id Sem(void) const;
29 
30 	private:
31 		BLocker(const char *name, bool benaphoreStyle, bool);
32 		void InitLocker(const char *name, bool benaphore_style);
33 		bool AcquireLock(bigtime_t timeout, status_t *error);
34 
35 		int32	fBenaphoreCount;
36 		sem_id	fSemaphoreID;
37 		thread_id fLockOwner;
38 		int32	fRecursiveCount;
39 
40 		int32 _reserved[4];
41 };
42 
43 #endif // _LOCKER_H
44