1// Lockable.h
2
3#ifndef NET_FS_LOCKABLE_H
4#define NET_FS_LOCKABLE_H
5
6#include "Blocker.h"
7#include "DLList.h"
8
9// LockerCandidate
10class LockerCandidate : public DLListLinkImpl<LockerCandidate> {
11public:
12								LockerCandidate(Blocker blocker);
13
14			thread_id			GetThread() const;
15
16			status_t			Block();
17			status_t			Unblock(bool success);
18
19private:
20			Blocker				fBlocker;
21			thread_id			fThread;
22};
23
24typedef DLList<LockerCandidate> LockerCandidateList;
25
26// Lockable
27class Lockable {
28public:
29								Lockable();
30								~Lockable();
31
32			bool				Lock();		// non-blocking
33			void				Unlock();
34			bool				IsLocked() const;
35
36			void				QueueLockerCandidate(
37									LockerCandidate* candidate);
38
39private:
40			LockerCandidateList	fLockerCandidates;
41			thread_id			fLockOwner;
42			int32				fLockCounter;
43};
44
45#endif	// NET_FS_LOCKABLE_H
46