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
12class BLocker {
13public:
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
32private:
33								BLocker(const char* name, bool benaphoreStyle,
34									bool _ignored);
35								BLocker(const BLocker&);
36								BLocker& operator=(const BLocker&);
37			void				InitLocker(const char* name,
38									bool benaphoreStyle);
39			bool				AcquireLock(bigtime_t timeout, status_t* error);
40
41			int32				fBenaphoreCount;
42			sem_id				fSemaphoreID;
43			thread_id			fLockOwner;
44			int32				fRecursiveCount;
45
46			int32				_reserved[4];
47};
48
49
50#endif	// _LOCKER_H
51