7#include <aws/core/utils/memory/stl/AWSVector.h>
9#include <condition_variable>
25 template<
typename RESOURCE_TYPE>
39 std::unique_lock<std::mutex> locker(m_queueLock);
40 while(!m_shutdown.load() && m_resources.size() == 0)
42 m_semaphore.wait(locker, [&](){
return m_shutdown.load() || m_resources.size() > 0; });
47 RESOURCE_TYPE resource = m_resources.back();
48 m_resources.pop_back();
59 RESOURCE_TYPE
TryAcquire(
typename std::enable_if<std::is_pointer<RESOURCE_TYPE>::value >::type* = 0)
61 std::unique_lock<std::mutex> locker(m_queueLock);
62 while(!m_shutdown.load() && m_resources.size() == 0)
64 m_semaphore.wait(locker, [&](){
return m_shutdown.load() || m_resources.size() > 0; });
71 RESOURCE_TYPE resource = m_resources.back();
72 m_resources.pop_back();
85 std::lock_guard<std::mutex> locker(m_queueLock);
86 return m_resources.size() > 0 && !m_shutdown.load();
96 std::unique_lock<std::mutex> locker(m_queueLock);
97 m_resources.push_back(resource);
99 m_semaphore.notify_one();
109 m_resources.push_back(resource);
123 std::unique_lock<std::mutex> locker(m_queueLock);
127 while (m_resources.size() < resourceCount)
129 m_semaphore.wait(locker, [&]() {
return m_resources.size() == resourceCount; });
133 m_semaphore.notify_one();
139 std::mutex m_queueLock;
140 std::condition_variable m_semaphore;
141 std::atomic<bool> m_shutdown;
Aws::Vector< RESOURCE_TYPE > ShutdownAndWait(size_t resourceCount)
ExclusiveOwnershipResourceManager()
void Release(RESOURCE_TYPE resource)
void PutResource(RESOURCE_TYPE resource)
RESOURCE_TYPE TryAcquire(typename std::enable_if< std::is_pointer< RESOURCE_TYPE >::value >::type *=0)
bool HasResourcesAvailable()
std::vector< T, Aws::Allocator< T > > Vector