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