本文整理汇总了C++中ContType类的典型用法代码示例。如果您正苦于以下问题:C++ ContType类的具体用法?C++ ContType怎么用?C++ ContType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: borrowObject
HolderType borrowObject()
{
#ifdef MAPNIK_THREADSAFE
mapnik::scoped_lock lock(mutex_);
#endif
typename ContType::iterator itr=pool_.begin();
while ( itr!=pool_.end())
{
if (!itr->unique())
{
++itr;
}
else if ((*itr)->isOK())
{
return *itr;
}
else
{
itr=pool_.erase(itr);
}
}
// all connection have been taken, check if we allowed to grow pool
if (pool_.size() < maxSize_)
{
HolderType conn(creator_());
if (conn->isOK())
{
pool_.push_back(conn);
return conn;
}
}
return HolderType();
}
示例2: getPool
boost::shared_ptr<PoolType> getPool(std::string const& key) {
ContType::const_iterator itr = pools_.find(key);
if (itr != pools_.end())
return itr->second;
static const boost::shared_ptr<PoolType> emptyPool;
return emptyPool;
}
示例3: getPool
const boost::shared_ptr<PoolType>& getPool(const std::string& key)
{
mutex::scoped_lock lock(mutex_);
ContType::const_iterator itr=pools_.find(key);
if (itr!=pools_.end())
{
return itr->second;
}
static const boost::shared_ptr<PoolType> emptyPool;
return emptyPool;
}
示例4: get
const HolderType& get(const std::string& key)
{
mutex::scoped_lock lock(mutex_);
ContType::const_iterator itr=pools_.find(key);
if (itr!=pools_.end())
{
boost::shared_ptr<PoolType> pool=itr->second;
return pool->borrowObject();
}
static const HolderType EmptyConn;
return EmptyConn;
}
示例5: getPool
std::shared_ptr<PoolType> getPool(std::string const& key)
{
#ifdef MAPNIK_THREADSAFE
std::lock_guard<std::mutex> lock(mutex_);
#endif
ContType::const_iterator itr=pools_.find(key);
if (itr!=pools_.end())
{
return itr->second;
}
static const std::shared_ptr<PoolType> emptyPool;
return emptyPool;
}
示例6: registerPool
bool registerPool(const ConnectionCreator<Connection> &creator, size_t initialSize, size_t maxSize) {
ContType::const_iterator itr = pools_.find(creator.id());
if (itr != pools_.end()) {
itr->second->set_initial_size(initialSize);
itr->second->set_max_size(maxSize);
} else
return pools_.insert(
std::make_pair(creator.id(), boost::make_shared<PoolType>(creator, initialSize,maxSize))).second;
return false;
}
示例7: borrowObject
HolderType borrowObject()
{
#ifdef MAPNIK_THREADSAFE
mutex::scoped_lock lock(mutex_);
#endif
typename ContType::iterator itr=unusedPool_.begin();
if (itr!=unusedPool_.end())
{
#ifdef MAPNIK_DEBUG
std::clog<<"borrow "<<(*itr).get()<<"\n";
#endif
usedPool_.push_back(*itr);
itr=unusedPool_.erase(itr);
return usedPool_[usedPool_.size()-1];
}
else if (unusedPool_.size() < maxSize_)
{
HolderType conn(creator_());
if (conn->isOK())
{
usedPool_.push_back(conn);
#ifdef MAPNIK_DEBUG
std::clog << "create << " << conn.get() << "\n";
#endif
return conn;
}
}
return HolderType();
}
示例8: registerPool
bool registerPool(ConnectionCreator<Connection> const& creator,unsigned initialSize,unsigned maxSize)
{
ContType::const_iterator itr = pools_.find(creator.id());
if (itr != pools_.end())
{
itr->second->set_initial_size(initialSize);
itr->second->set_max_size(maxSize);
}
else
{
return pools_.insert(
std::make_pair(creator.id(),
std::make_shared<PoolType>(creator,initialSize,maxSize))).second;
}
return false;
}
示例9: returnObject
void returnObject(HolderType obj)
{
#ifdef MAPNIK_THREADSAFE
mutex::scoped_lock lock(mutex_);
#endif
typename ContType::iterator itr=usedPool_.begin();
while (itr != usedPool_.end())
{
if (obj.get()==(*itr).get())
{
#ifdef MAPNIK_DEBUG
std::clog<<"return "<<(*itr).get()<<"\n";
#endif
unusedPool_.push_back(*itr);
usedPool_.erase(itr);
return;
}
++itr;
}
}
示例10: registerPool
bool registerPool(ConnectionCreator<Connection> const& creator,unsigned initialSize,unsigned maxSize)
{
#ifdef MAPNIK_THREADSAFE
std::lock_guard<std::mutex> lock(mutex_);
#endif
ContType::const_iterator itr = pools_.find(creator.id());
if (itr != pools_.end())
{
itr->second->set_initial_size(initialSize);
itr->second->set_max_size(maxSize);
}
else
{
return pools_.insert(
std::make_pair(creator.id(),
std::make_shared<PoolType>(creator,initialSize,maxSize))).second;
}
return false;
}
示例11: lock
std::pair<unsigned,unsigned> size() const
{
#ifdef MAPNIK_THREADSAFE
mutex::scoped_lock lock(mutex_);
#endif
std::pair<unsigned,unsigned> size(unusedPool_.size(),usedPool_.size());
return size;
}
示例12: registerPool
bool registerPool(const ConnectionCreator<Connection>& creator,int initialSize,int maxSize)
{
mutex::scoped_lock lock(mutex_);
if (pools_.find(creator.id())==pools_.end())
{
return pools_.insert(std::make_pair(creator.id(),
boost::shared_ptr<PoolType>(new PoolType(creator,initialSize,maxSize)))).second;
}
return false;
}
示例13: size
unsigned size() const
{
#ifdef MAPNIK_THREADSAFE
mapnik::scoped_lock lock(mutex_);
#endif
return pool_.size();
}
示例14: conn
Pool(const Creator<T>& creator,unsigned initialSize=1, unsigned maxSize=10)
:creator_(creator),
initialSize_(initialSize),
maxSize_(maxSize)
{
for (unsigned i=0; i < initialSize_; ++i)
{
HolderType conn(creator_());
if (conn->isOK())
unusedPool_.push_back(conn);
}
}
示例15: set_initial_size
void set_initial_size(unsigned size)
{
#ifdef MAPNIK_THREADSAFE
mapnik::scoped_lock lock(mutex_);
#endif
if (size > initialSize_)
{
initialSize_ = size;
unsigned total_size = pool_.size();
// ensure we don't have ghost obj's in the pool.
if (total_size < initialSize_)
{
unsigned grow_size = initialSize_ - total_size ;
for (unsigned i=0; i < grow_size; ++i)
{
HolderType conn(creator_());
if (conn->isOK())
pool_.push_back(conn);
}
}
}
}