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 org.eclipse.swt.widgets.RunnableLock;
14 
15 import java.lang.all;
16 
17 import java.lang.Thread;
18 
19 import core.sync.condition;
20 import core.sync.mutex;
21 
22 /**
23  * Instances of this class are used to ensure that an
24  * application cannot interfere with the locking mechanism
25  * used to implement asynchronous and synchronous communication
26  * between widgets and background threads.
27  */
28 
29 class RunnableLock : Mutex {
30     Runnable runnable;
31     Thread thread;
32     Exception throwable;
33 
34     Condition cond;
35     bool syncExec;
36 
37 this (Runnable runnable, bool syncExec) {
38     this.runnable = runnable;
39     this.cond = new Condition(this);
40     this.syncExec = syncExec;
41 }
42 
43 ~this () {
44     // Release handle of Condition.
45     // If not released here, the handle will not be released until the next GC works.
46     destroy(this.cond);
47 }
48 
49 bool done () {
50     return runnable is null || throwable !is null;
51 }
52 
53 void run () {
54     if (runnable !is null) runnable.run ();
55     runnable = null;
56 }
57 
58 void notifyAll(){
59     cond.notifyAll();
60 }
61 void wait(){
62     cond.wait();
63 }
64 
65 }