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"
51 while (
free_.size() > 0) {
58 if (
used_.size() > 0) {
59 syslog(LOG_USER | LOG_WARNING,
"%ld used elements from a pool not released on destruction!", (
long)
used_.size());
70 std::string(
"No resources available"));
74 boost::system_time
const timeout = boost::get_system_time() + boost::posix_time::seconds(60);
75 boost::mutex::scoped_lock lock(
mutex_);
77 if (boost::get_system_time() >= timeout) {
78 syslog(LOG_USER | LOG_WARNING,
"Timeout...%d seconds", 60);
85 if (
free_.size() > 0) {
99 used_.insert(std::pair<E, unsigned>(e, 1));
110 boost::mutex::scoped_lock lock(
mutex_);
113 typename std::map<E, unsigned>::const_iterator i =
used_.find(e);
114 if (i ==
used_.end()) {
130 boost::mutex::scoped_lock lock(
mutex_);
132 unsigned remaining = --
used_[e];
155 typename std::map<E, unsigned>::const_iterator i =
used_.find(e);
156 if (i ==
used_.end())
166 boost::mutex::scoped_lock lock(
mutex_);
215 #endif // DMLITE_CPP_UTILS_POOLCONTAINER_H