+ support initialSize_ updates

+ move maxSize_/initialSize_ logic into pool.hpp
This commit is contained in:
artemp 2012-11-28 17:38:18 +00:00
parent a3fe851737
commit 99141fa5e5
2 changed files with 36 additions and 4 deletions

View file

@ -39,6 +39,7 @@
#include <map>
#include <deque>
#include <ctime>
#include <cassert>
namespace mapnik
{
@ -71,7 +72,7 @@ class Pool : private boost::noncopyable
typedef std::deque<HolderType> ContType;
Creator<T> creator_;
const unsigned initialSize_;
unsigned initialSize_;
unsigned maxSize_;
ContType usedPool_;
ContType unusedPool_;
@ -174,7 +175,38 @@ public:
#ifdef MAPNIK_THREADSAFE
mutex::scoped_lock lock(mutex_);
#endif
maxSize_ = size;
maxSize_ = std::max(maxSize_,size);
}
unsigned initial_size() const
{
#ifdef MAPNIK_THREADSAFE
mutex::scoped_lock lock(mutex_);
#endif
return initialSize_;
}
void set_initial_size(unsigned size)
{
#ifdef MAPNIK_THREADSAFE
mutex::scoped_lock lock(mutex_);
#endif
if (size > initialSize_)
{
initialSize_ = size;
unsigned total_size = usedPool_.size() + unusedPool_.size();
if (total_size < initialSize_)
{
unsigned grow_size = initialSize_ - total_size ;
for (unsigned i=0; i < grow_size; ++i)
{
HolderType conn(creator_());
if (conn->isOK())
unusedPool_.push_back(conn);
}
}
}
}
};

View file

@ -122,8 +122,8 @@ public:
if (itr != pools_.end())
{
unsigned cur_size = itr->second->max_size();
itr->second->set_max_size(std::max(maxSize, cur_size));
itr->second->set_max_size(initialSize);
itr->second->set_max_size(maxSize);
}
else
{