PageRenderTime 59ms CodeModel.GetById 51ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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
11module synch.barrier;
12
13class Barrier {
14	this(uint reportsRequired) {
15		_reportsNeeded = reportsRequired;
16	}
17
18	// Description: This function will report one task, and if the barrier has received as many reports as the threshold it will return.
19	void report() {
20		synchronized(this) {
21			_reportsIn++;
22			if (_reportsIn >= _reportsNeeded) {
23				return;
24			}
25		}
26
27		// XXX: Reimplement with a conditional wait
28		while(_reportsIn >= _reportsNeeded) {
29		}
30	}
31
32protected:
33
34	uint _reportsIn;
35	uint _reportsNeeded;
36}