00001 #ifndef CountingSem_H 00002 #define CountingSem_H 00003 00004 #include "Exceptions.h" 00005 #include "PtMutex.h" 00006 00007 BOREALIS_NAMESPACE_BEGIN; 00008 00009 class CountingSem 00010 { 00011 public: 00012 CountingSem(int maxConcurrentHoldings) 00013 throw (std::exception); 00014 00015 virtual ~CountingSem(); 00016 00017 /* 00018 Changes the number of resource intances in this semaphore. If the new 00019 value is < the number currently held, then no change is made and an exception 00020 is thrown. 00021 */ 00022 void setMaxConcurrentHoldings(int maxConcurrentHoldings) 00023 throw (std::exception); 00024 00025 /* 00026 Acquires an instance of the specified resource. If successful, returns 'true'. 00027 If failed because of a resource shortage, returns 'false'. 00028 */ 00029 bool acquireNonBlocking() 00030 throw (std::exception); 00031 00032 void release() 00033 throw (std::exception); 00034 00035 private: 00036 PtMutex _mtx; 00037 int _maxConcurrentHoldings; 00038 int _currentHoldings; 00039 }; 00040 00041 BOREALIS_NAMESPACE_END; 00042 00043 #endif