25
|
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 tango.core.Thread;
|
|
18 import tango.core.Exception;
|
|
19 import tango.core.sync.Condition;
|
|
20 import tango.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
|
|
36 this (Runnable runnable) {
|
|
37 this.runnable = runnable;
|
|
38 this.cond = new Condition(this);
|
|
39 }
|
|
40
|
|
41 bool done () {
|
|
42 return runnable is null || throwable !is null;
|
|
43 }
|
|
44
|
|
45 void run () {
|
|
46 if (runnable !is null) runnable.run ();
|
|
47 runnable = null;
|
|
48 }
|
|
49
|
|
50 void notifyAll(){
|
|
51 cond.notifyAll();
|
|
52 }
|
|
53 void wait(){
|
|
54 cond.wait();
|
|
55 }
|
|
56
|
|
57 }
|