58 typedef std::shared_ptr<Barrier> shared_ptr;
60 Barrier(drizzled::session_id_t owner_arg) :
67 Barrier(drizzled::session_id_t owner_arg, int64_t limit_arg) :
83 boost::mutex::scoped_lock scopedBarrier(sleeper_mutex);
87 drizzled::session_id_t getOwner()
const
94 boost::mutex::scoped_lock scopedLock(sleeper_mutex);
95 int64_t my_generation= generation;
100 if (not current_wait)
114 while (my_generation == generation)
116 sleep_threshhold.wait(sleeper_mutex);
119 catch(boost::thread_interrupted
const& error)
127 void wait_until(int64_t wait_until_arg)
129 Observer::shared_ptr observer;
131 boost::mutex::scoped_lock scopedLock(sleeper_mutex);
133 if (wait_until_arg <= count())
136 observer.reset(
new Observer(wait_until_arg));
137 observers.push_back(observer);
143 catch(boost::thread_interrupted
const& error)
145 boost::mutex::scoped_lock scopedLock(sleeper_mutex);
149 observers.remove(observer);
155 void wait(int64_t generation_arg)
157 boost::mutex::scoped_lock scopedLock(sleeper_mutex);
158 int64_t my_generation= generation;
161 if (my_generation > generation_arg)
168 if (not current_wait)
176 while (my_generation == generation)
178 sleep_threshhold.wait(sleeper_mutex);
182 int64_t getGeneration()
184 boost::mutex::scoped_lock scopedLock(sleeper_mutex);
188 int64_t sizeObservers()
190 boost::mutex::scoped_lock scopedLock(sleeper_mutex);
191 return static_cast<int64_t
>(observers.size());
194 int64_t sizeWaiters()
196 boost::mutex::scoped_lock scopedLock(sleeper_mutex);
200 int64_t getLimit()
const
210 sleep_threshhold.notify_all();
219 isReady(int64_t arg) :
223 bool operator() (Observer::list::const_reference observer)
225 if (observer->getLimit() <= count or count == 0)
235 void checkObservers()
237 observers.remove_if(
isReady(count()));
240 int64_t count()
const
244 return limit - current_wait;
246 return std::abs(
static_cast<long int>(current_wait));
250 drizzled::session_id_t owner;
253 int64_t current_wait;
256 Observer::list observers;
258 boost::mutex sleeper_mutex;
259 boost::condition_variable_any sleep_threshhold;