1 // BlockerPool.h 2 3 #ifndef BLOCKER_POOL_H 4 #define BLOCKER_POOL_H 5 6 #include "Blocker.h" 7 #include "Locker.h" 8 9 class BlockerPool : public Locker { 10 public: 11 BlockerPool(int32 count = 10); 12 ~BlockerPool(); 13 14 status_t InitCheck() const; 15 16 Blocker GetBlocker(); 17 status_t PutBlocker(Blocker blocker); 18 19 private: 20 status_t _Init(int32 count); 21 void _Unset(); 22 23 private: 24 struct BlockerVector; 25 26 sem_id fFreeBlockersSemaphore; 27 BlockerVector* fBlockers; 28 status_t fInitStatus; 29 30 }; 31 32 // BlockerPutter 33 class BlockerPutter { 34 public: 35 BlockerPutter(BlockerPool& pool, Blocker blocker) 36 : fPool(pool), 37 fBlocker(blocker) 38 { 39 } 40 41 ~BlockerPutter() 42 { 43 fPool.PutBlocker(fBlocker); 44 } 45 46 private: 47 BlockerPool& fPool; 48 Blocker fBlocker; 49 }; 50 51 #endif // BLOCKER_POOL_H 52