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 19class BList; 20class BLooper; 21 22 23namespace BPrivate { 24 25 26class BLooperList { 27public: 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 46private: 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 typedef std::vector<BLooperList::LooperData>::iterator LooperDataIterator; 56 struct FindLooperPred { 57 FindLooperPred(const BLooper* loop) : looper(loop) {} 58 bool operator()(LooperData& Data); 59 const BLooper* looper; 60 }; 61 struct FindThreadPred { 62 FindThreadPred(thread_id tid) : thread(tid) {} 63 bool operator()(LooperData& Data); 64 thread_id thread; 65 }; 66 struct FindNamePred { 67 FindNamePred(const char* n) : name(n) {} 68 bool operator()(LooperData& Data); 69 const char* name; 70 }; 71 struct FindPortPred { 72 FindPortPred(port_id pid) : port(pid) {} 73 bool operator()(LooperData& Data); 74 port_id port; 75 }; 76 77 static bool EmptySlotPred(LooperData& Data); 78 void AssertLocked(); 79 80private: 81 BLocker fLock; 82 std::vector<LooperData> fData; 83}; 84 85 86extern BLooperList gLooperList; 87 88 89} // namespace BPrivate 90 91 92#endif // LOOPER_LIST_H 93