/synch/barrier.d

http://github.com/wilkie/djehuty · D · 36 lines · 19 code · 6 blank · 11 comment · 1 complexity · 8b86f63a21e6ee52ba5008930de87e4f MD5 · raw file

  1. /*
  2. * barrier.d
  3. *
  4. * This module implements a barrier synchronization object.
  5. *
  6. * Author: Dave Wilkinson
  7. * Originated: December 4th, 2009
  8. *
  9. */
  10. module synch.barrier;
  11. class Barrier {
  12. this(uint reportsRequired) {
  13. _reportsNeeded = reportsRequired;
  14. }
  15. // Description: This function will report one task, and if the barrier has received as many reports as the threshold it will return.
  16. void report() {
  17. synchronized(this) {
  18. _reportsIn++;
  19. if (_reportsIn >= _reportsNeeded) {
  20. return;
  21. }
  22. }
  23. // XXX: Reimplement with a conditional wait
  24. while(_reportsIn >= _reportsNeeded) {
  25. }
  26. }
  27. protected:
  28. uint _reportsIn;
  29. uint _reportsNeeded;
  30. }