4 #ifndef DMLITE_CPP_UTILS_POOLCONTAINER_H
5 #define DMLITE_CPP_UTILS_POOLCONTAINER_H
10 #include <semaphore.h>
13 #include "../exceptions.h"
45 pthread_mutex_init(&
mutex_, NULL);
53 while (
free_.size() > 0) {
60 if (
used_.size() > 0) {
61 syslog(LOG_USER | LOG_WARNING,
"%ld used elements from a pool not released on destruction!", (
long)
used_.size());
64 pthread_mutex_destroy(&
mutex_);
81 pthread_mutex_lock(&
mutex_);
83 if (
free_.size() > 0) {
97 used_.insert(std::pair<E, unsigned>(e, 1));
99 pthread_mutex_unlock(&
mutex_);
107 pthread_mutex_lock(&
mutex_);
110 typename std::map<E, unsigned>::const_iterator i =
used_.find(e);
111 if (i ==
used_.end())
118 pthread_mutex_unlock(&
mutex_);
128 pthread_mutex_lock(&
mutex_);
130 unsigned remaining = --
used_[e];
146 pthread_mutex_unlock(&
mutex_);
154 typename std::map<E, unsigned>::const_iterator i =
used_.find(e);
155 if (i ==
used_.end())
166 pthread_mutex_lock(&
mutex_);
177 total = sv +
used_.size();
178 while (total <
max_) {
183 pthread_mutex_unlock(&
mutex_);
200 #endif // DMLITE_CPP_UTILS_POOLCONTAINER_H