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 version(Tango){
19     import tango.core.sync.Condition;
20     import tango.core.sync.Mutex;
21 } else { // Phobos
22     import java.nonstandard.sync.condition;
23     import java.nonstandard.sync.mutex;
24 }
25 
26 /**
27  * Instances of this class are used to ensure that an
28  * application cannot interfere with the locking mechanism
29  * used to implement asynchronous and synchronous communication
30  * between widgets and background threads.
31  */
32 
33 class RunnableLock : Mutex {
34     Runnable runnable;
35     Thread thread;
36     Exception throwable;
37 
38     Condition cond;
39 
40 this (Runnable runnable) {
41     this.runnable = runnable;
42     this.cond = new Condition(this);
43 }
44 
45 bool done () {
46     return runnable is null || throwable !is null;
47 }
48 
49 void run () {
50     if (runnable !is null) runnable.run ();
51     runnable = null;
52 }
53 
54 void notifyAll(){
55     cond.notifyAll();
56 }
57 void wait(){
58     cond.wait();
59 }
60 
61 }