xref: /haiku/headers/os/support/Locker.h (revision 4e3137c085bae361922078f123dceb92da700640)
1 /*
2  * Copyright 2001-2010 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 			status_t			InitCheck() const;
21 
22 			bool				Lock();
23 			status_t			LockWithTimeout(bigtime_t timeout);
24 			void				Unlock();
25 
26 			thread_id			LockingThread() const;
27 			bool				IsLocked() const;
28 			int32				CountLocks() const;
29 			int32				CountLockRequests() const;
30 			sem_id				Sem() const;
31 
32 private:
33 								BLocker(const char* name, bool benaphoreStyle,
34 									bool _ignored);
35 			void				InitLocker(const char* name,
36 									bool benaphoreStyle);
37 			bool				AcquireLock(bigtime_t timeout, status_t* error);
38 
39 			int32				fBenaphoreCount;
40 			sem_id				fSemaphoreID;
41 			thread_id			fLockOwner;
42 			int32				fRecursiveCount;
43 
44 			int32				_reserved[4];
45 };
46 
47 
48 #endif	// _LOCKER_H
49