cmake build system: visiblity support for clang
[supercollider.git] / SCClassLibrary / Common / Core / Condition.sc
blob1c7a60f101d7ff4b96ba768f4b40fe3c7a07a47d
1 Condition {
2         var <>test, waitingThreads;
4         *new { arg test=false;
5                 ^super.newCopyArgs(test, Array(8))
6         }
7         wait {
8                 if (test.value.not, {
9                         waitingThreads = waitingThreads.add(thisThread);
10                         nil.yield;
11                 });
12         }
13         hang { arg value;
14                 // ignore the test, just wait
15                 waitingThreads = waitingThreads.add(thisThread);
16                 value.yield;
17         }
19         signal {
20                 var tempWaitingThreads, time;
21                 if (test.value, {
22                         time = thisThread.seconds;
23                         tempWaitingThreads = waitingThreads;
24                         waitingThreads = nil;
25                         tempWaitingThreads.do({ arg thread;
26                                 thread.clock.sched(0, thread);
27                         });
28                 });
29         }
30         unhang {
31                 var tempWaitingThreads, time;
32                 // ignore the test, just resume all waiting threads
33                 time = thisThread.seconds;
34                 tempWaitingThreads = waitingThreads;
35                 waitingThreads = nil;
36                 tempWaitingThreads.do({ arg thread;
37                         thread.clock.sched(0, thread);
38                 });
39         }
42 FlowVar {
43         var value = \unbound;
44         var condition;
46         *new { arg inVal = \unbound;
47                 ^super.init(inVal)
48         }
49         init { arg inVal;
50                 value = inVal;
51                 condition = Condition { value != \unbound };
52         }
53         value_ { arg inVal;
54                 if (value ==  \unbound) {
55                         Error("cannot rebind a FlowVar").throw
56                 };
57                 value = inVal;
58                 condition.signal;
59         }
60         value {
61                 condition.wait
62                 ^value
63         }