root/dwt/widgets/RunnableLock.d

Revision 101:58014b95afb5, 1.4 kB (checked in by Frank Benoit <benoit@tionex.de>, 10 months ago)

Implemented RunnableLock?. Thanks torhu for the testcase.

Line 
1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  * Port to the D programming language:
11  *     Frank Benoit <benoit@tionex.de>
12  *******************************************************************************/
13 module dwt.widgets.RunnableLock;
14
15 import tango.core.Thread;
16 import dwt.dwthelper.Runnable;
17 import tango.core.Exception;
18 import tango.core.sync.Condition;
19 import tango.core.sync.Mutex;
20
21 /**
22  * Instances of this class are used to ensure that an
23  * application cannot interfere with the locking mechanism
24  * used to implement asynchronous and synchronous communication
25  * between widgets and background threads.
26  */
27
28 class RunnableLock : Mutex {
29     Runnable runnable;
30     Thread thread;
31     Exception throwable;
32     Condition cond;
33
34 this (Runnable runnable) {
35     this.runnable = runnable;
36     this.cond = new Condition(this);
37 }
38
39 bool done () {
40     return runnable is null || throwable !is null;
41 }
42
43 void run () {
44     if (runnable !is null) runnable.run ();
45     runnable = null;
46 }
47
48 void notifyAll(){
49     cond.notifyAll();
50 }
51 void wait(){
52     cond.wait();
53 }
54
55 }
Note: See TracBrowser for help on using the browser.