1 /* 2 * Copyright 2001-2007, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Erik Jaesler (erik@cgsoftware.com) 7 */ 8 #ifndef LOOPERLIST_H 9 #define LOOPERLIST_H 10 11 12 #include <Locker.h> 13 #include <OS.h> 14 #include <SupportDefs.h> 15 16 #include <vector> 17 18 class BList; 19 class BLooper; 20 21 22 namespace BPrivate { 23 24 class BLooperList { 25 public: 26 BLooperList(); 27 28 bool Lock(); 29 void Unlock(); 30 bool IsLocked(); 31 32 void AddLooper(BLooper* l); 33 bool IsLooperValid(const BLooper* l); 34 bool RemoveLooper(BLooper* l); 35 void GetLooperList(BList* list); 36 int32 CountLoopers(); 37 BLooper* LooperAt(int32 index); 38 BLooper* LooperForThread(thread_id tid); 39 BLooper* LooperForName(const char* name); 40 BLooper* LooperForPort(port_id port); 41 42 private: 43 struct LooperData { 44 LooperData(); 45 LooperData(BLooper* looper); 46 LooperData(const LooperData& rhs); 47 LooperData& operator=(const LooperData& rhs); 48 49 BLooper* looper; 50 }; 51 52 static bool EmptySlotPred(LooperData& Data); 53 struct FindLooperPred { 54 FindLooperPred(const BLooper* loop) : looper(loop) {;} 55 bool operator()(LooperData& Data); 56 const BLooper* looper; 57 }; 58 struct FindThreadPred { 59 FindThreadPred(thread_id tid) : thread(tid) {;} 60 bool operator()(LooperData& Data); 61 thread_id thread; 62 }; 63 struct FindNamePred { 64 FindNamePred(const char* n) : name(n) {;} 65 bool operator()(LooperData& Data); 66 const char* name; 67 }; 68 struct FindPortPred { 69 FindPortPred(port_id pid) : port(pid) {;} 70 bool operator()(LooperData& Data); 71 port_id port; 72 }; 73 74 void AssertLocked(); 75 76 BLocker fLock; 77 std::vector<LooperData> fData; 78 }; 79 80 extern BLooperList gLooperList; 81 82 } // namespace BPrivate 83 84 #endif // LOOPERLIST_H 85