1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| using System.Threading;
|
| namespace Top.Api.Util
| {
| public class CountDownLatch
| {
| private int count;
| private EventWaitHandle ewh;
|
| public CountDownLatch(int count)
| {
| this.count = count;
| this.ewh = new ManualResetEvent(false);
| }
|
| public void Signal()
| {
| // The last thread to signal also sets the event.
| if (Interlocked.Decrement(ref count) == 0)
| {
| this.ewh.Set();
| }
| }
|
| public void Wait()
| {
| this.ewh.WaitOne();
| }
| }
| }
|
|