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