4 #ifndef DMLITE_CPP_UTILS_POOLCONTAINER_H
5 #define DMLITE_CPP_UTILS_POOLCONTAINER_H
7 #include <boost/thread/mutex.hpp>
8 #include <boost/thread/condition.hpp>
9 #include <boost/date_time/posix_time/posix_time.hpp>
13 #include "../exceptions.h"
50 boost::mutex::scoped_lock lock(
mutex_);
52 while (
free_.size() > 0) {
59 if (
used_.size() > 0) {
60 syslog(LOG_USER | LOG_WARNING,
"%ld used elements from a pool not released on destruction!", (
long)
used_.size());
69 boost::mutex::scoped_lock lock(
mutex_);
74 std::string(
"No resources available"));
78 boost::system_time
const timeout = boost::get_system_time() + boost::posix_time::seconds(60);
81 if (boost::get_system_time() >= timeout) {
82 syslog(LOG_USER | LOG_WARNING,
"Timeout...%d seconds", 60);
89 if (
free_.size() > 0) {
103 used_.insert(std::pair<E, unsigned>(e, 1));
114 boost::mutex::scoped_lock lock(
mutex_);
117 typename std::map<E, unsigned>::const_iterator i =
used_.find(e);
118 if (i ==
used_.end()) {
134 boost::mutex::scoped_lock lock(
mutex_);
136 unsigned remaining = --
used_[e];
159 typename std::map<E, unsigned>::const_iterator i =
used_.find(e);
160 if (i ==
used_.end())
170 boost::mutex::scoped_lock lock(
mutex_);
219 #endif // DMLITE_CPP_UTILS_POOLCONTAINER_H