Mercurial > projects > dwt-mac
comparison dwt/widgets/RunnableLock.d @ 37:642f460a0908
Fixed a lot of compile errors, a "hello world" app compiles now
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Fri, 10 Oct 2008 12:29:48 +0200 |
parents | 5b53d338c709 |
children | 07399639c0c8 |
comparison
equal
deleted
inserted
replaced
36:db5a898b2119 | 37:642f460a0908 |
---|---|
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | 10 * |
11 * Port to the D programming language: | 11 * Port to the D programming language: |
12 * Frank Benoit <benoit@tionex.de> | |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | 13 * Jacob Carlborg <jacob.carlborg@gmail.com> |
13 *******************************************************************************/ | 14 *******************************************************************************/ |
14 module dwt.widgets.RunnableLock; | 15 module dwt.widgets.RunnableLock; |
15 | 16 |
17 import tango.core.Exception; | |
18 import tango.core.sync.Condition; | |
19 import tango.core.sync.Mutex; | |
16 import tango.core.Thread; | 20 import tango.core.Thread; |
17 | 21 |
18 import dwt.dwthelper.Runnable; | 22 import dwt.dwthelper.Runnable; |
19 import dwt.dwthelper.utils; | 23 import dwt.dwthelper.utils; |
20 | |
21 | 24 |
22 /** | 25 /** |
23 * Instances of this class are used to ensure that an | 26 * Instances of this class are used to ensure that an |
24 * application cannot interfere with the locking mechanism | 27 * application cannot interfere with the locking mechanism |
25 * used to implement asynchronous and synchronous communication | 28 * used to implement asynchronous and synchronous communication |
26 * between widgets and background threads. | 29 * between widgets and background threads. |
27 */ | 30 */ |
28 | 31 |
29 class RunnableLock { | 32 class RunnableLock : Mutex { |
30 Runnable runnable; | 33 Runnable runnable; |
31 Thread thread; | 34 Thread thread; |
32 Throwable throwable; | 35 Throwable throwable; |
33 | 36 |
37 Condition cond; | |
38 | |
34 this (Runnable runnable) { | 39 this (Runnable runnable) { |
35 this.runnable = runnable; | 40 this.runnable = runnable; |
41 this.cond = new Condition(this); | |
36 } | 42 } |
37 | 43 |
38 bool done () { | 44 bool done () { |
39 return runnable is null || throwable !is null; | 45 return runnable is null || throwable !is null; |
40 } | 46 } |
41 | 47 |
42 void run () { | 48 void run () { |
43 if (runnable !is null) runnable.run (); | 49 if (runnable !is null) runnable.run (); |
44 runnable = null; | 50 runnable = null; |
45 } | 51 } |
52 | |
53 void notifyAll(){ | |
54 cond.notifyAll(); | |
55 } | |
56 void wait(){ | |
57 cond.wait(); | |
58 } | |
46 | 59 |
47 } | 60 } |