CountBarrier.cc 518 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "Thread/CountBarrier.h"
  2. namespace Egametang {
  3. CountBarrier::CountBarrier(int count):
  4. count_(count), mutex_(), condition_()
  5. {
  6. }
  7. void CountBarrier::Wait()
  8. {
  9. boost::mutex::scoped_lock lock(mutex_);
  10. while (count_ > 0)
  11. {
  12. condition_.wait(lock);
  13. }
  14. }
  15. void CountBarrier::Signal()
  16. {
  17. boost::mutex::scoped_lock lock(mutex_);
  18. --count_;
  19. if (count_ == 0)
  20. {
  21. condition_.notify_all();
  22. }
  23. }
  24. int CountBarrier::Count() const
  25. {
  26. boost::mutex::scoped_lock lock(mutex_);
  27. return count_;
  28. }
  29. } // namespace Egametang