diff options
| -rw-r--r-- | libadhocutil/resourcePool.h | 6 | ||||
| -rw-r--r-- | libadhocutil/resourcePool.impl.h | 26 | ||||
| -rw-r--r-- | libadhocutil/unittests/testResourcePool.cpp | 5 | 
3 files changed, 18 insertions, 19 deletions
diff --git a/libadhocutil/resourcePool.h b/libadhocutil/resourcePool.h index 791737a..f65bf0f 100644 --- a/libadhocutil/resourcePool.h +++ b/libadhocutil/resourcePool.h @@ -82,11 +82,11 @@ namespace AdHoc {  			/// Create a new resource instance to add to the pool.  			virtual std::shared_ptr<Resource> createResource() const = 0;  			/// Destroy an existing resource (defaults to delete). -			virtual void destroyResource(const std::shared_ptr<Resource> &) const throw(); +			virtual void destroyResource(Resource const *) const throw();  			/// Test a cached resource is still suitable for use before re-use (defaults to no-op). -			virtual void testResource(const std::shared_ptr<const Resource> &) const; +			virtual void testResource(Resource const *) const;  			/// Test a cached resource is still suitable for use on return (defaults to no-op). -			virtual void returnTestResource(const std::shared_ptr<const Resource> &) const; +			virtual void returnTestResource(Resource const *) const;  		private:  			typedef std::list<std::shared_ptr<Resource>> Available; diff --git a/libadhocutil/resourcePool.impl.h b/libadhocutil/resourcePool.impl.h index 8153ce0..3d2f089 100644 --- a/libadhocutil/resourcePool.impl.h +++ b/libadhocutil/resourcePool.impl.h @@ -123,29 +123,29 @@ namespace AdHoc {  	ResourcePool<R>::~ResourcePool()  	{  		for (auto & r : available) { -			destroyResource(r); +			destroyResource(r.get());  		}  		for (auto & r : inUse) { -			destroyResource(std::get<0>(*r.second)); +			destroyResource(std::get<0>(*r.second).get());  			std::get<1>(*r.second) = nullptr;  		}  	}  	template <typename R>  	void -	ResourcePool<R>::destroyResource(const std::shared_ptr<R> &) const throw() +	ResourcePool<R>::destroyResource(R const *) const throw()  	{  	}  	template <typename R>  	void -	ResourcePool<R>::testResource(const std::shared_ptr<const R> &) const +	ResourcePool<R>::testResource(R const *) const  	{  	}  	template <typename R>  	void -	ResourcePool<R>::returnTestResource(const std::shared_ptr<const R> &) const +	ResourcePool<R>::returnTestResource(R const *) const  	{  	} @@ -187,7 +187,7 @@ namespace AdHoc {  	{  		Lock(lock);  		for (auto & r : available) { -			destroyResource(r); +			destroyResource(r.get());  		}  		available.clear();  	} @@ -228,16 +228,16 @@ namespace AdHoc {  	{  		Lock(lock);  		while (!available.empty()) { -			auto r = available.front(); +			auto & r = available.front();  			try { -				testResource(r); +				testResource(r.get());  				auto ro = std::make_shared<typename ResourceHandle<R>::Object>(r, this, 0);  				available.pop_front();  				inUse.insert({ std::this_thread::get_id(), ro });  				return ro;  			}  			catch (...) { -				destroyResource(r); +				destroyResource(r.get());  				available.pop_front();  			}  		} @@ -253,16 +253,16 @@ namespace AdHoc {  		Lock(lock);  		removeFrom(r, inUse);  		try { -			returnTestResource(r); +			returnTestResource(r.get());  			if (available.size() < keep) {  				available.push_back(r);  			}  			else { -				destroyResource(r); +				destroyResource(r.get());  			}  		}  		catch (...) { -			destroyResource(r); +			destroyResource(r.get());  		}  		poolSize.notify();  	} @@ -273,7 +273,7 @@ namespace AdHoc {  	{  		Lock(lock);  		removeFrom(r, inUse); -		destroyResource(r); +		destroyResource(r.get());  		poolSize.notify();  	} diff --git a/libadhocutil/unittests/testResourcePool.cpp b/libadhocutil/unittests/testResourcePool.cpp index 875179d..216c40c 100644 --- a/libadhocutil/unittests/testResourcePool.cpp +++ b/libadhocutil/unittests/testResourcePool.cpp @@ -51,7 +51,7 @@ class TRPCreateFail : public TRPSmall {  class TRPReturnFail : public TRPSmall {  	protected: -		void returnTestResource(const std::shared_ptr<const MockResource> &) const override +		void returnTestResource(MockResource const *) const override  		{  			throw std::exception();  		} @@ -296,11 +296,10 @@ BOOST_AUTO_TEST_CASE( threading2 )  class TTRP : public TRP {  	public:  		TTRP() : n(0) { } -		void testResource(const std::shared_ptr<const MockResource> &) const override +		void testResource(MockResource const *) const override  		{  			n += 1;  			if (n % 2) { -				fprintf(stderr, "%d, so throwing\n", n);  				throw std::exception();  			}  		}  | 
