changeset 46:8015c460f713

Synchronizer
author Frank Benoit <benoit@tionex.de>
date Fri, 11 Jan 2008 07:11:08 +0100
parents 2618d7245bce
children f646579f309c
files dwt/internal/Compatibility.d dwt/widgets/Control.d dwt/widgets/Display.d dwt/widgets/RunnableLock.d dwt/widgets/Synchronizer.d dwt/widgets/Widget.d todo.txt
diffstat 7 files changed, 90 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/internal/Compatibility.d	Fri Jan 11 06:46:36 2008 +0100
+++ b/dwt/internal/Compatibility.d	Fri Jan 11 07:11:08 2008 +0100
@@ -317,6 +317,8 @@
 	}
 	return answer;
 }
+++/
+
 
 /**
  * Interrupt the current thread.
@@ -325,9 +327,10 @@
  * </p>
  */
 public static void interrupt() {
-	Thread.currentThread().interrupt();
+    //PORTING_FIXME: how to implement??
+	//Thread.currentThread().interrupt();
 }
-++/
+
 /**
  * Compares two instances of class String ignoring the case of the
  * characters and answers if they are equal.
--- a/dwt/widgets/Control.d	Fri Jan 11 06:46:36 2008 +0100
+++ b/dwt/widgets/Control.d	Fri Jan 11 07:11:08 2008 +0100
@@ -54,6 +54,7 @@
 import Math = tango.math.Math;
 import tango.stdc.string;
 import tango.stdc.stringz;
+import tango.core.Thread;
 
 /+
 class Control : Widget {
--- a/dwt/widgets/Display.d	Fri Jan 11 06:46:36 2008 +0100
+++ b/dwt/widgets/Display.d	Fri Jan 11 07:11:08 2008 +0100
@@ -46,7 +46,7 @@
 import dwt.dwthelper.utils;
 import dwt.dwthelper.Runnable;
 
-import tango.core.Thread : Thread;
+import tango.core.Thread;
 
 /**
  * Instances of this class are responsible for managing the
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwt/widgets/RunnableLock.d	Fri Jan 11 07:11:08 2008 +0100
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+module dwt.widgets.RunnableLock;
+
+import tango.core.Thread;
+import dwt.dwthelper.Runnable;
+import tango.core.Exception;
+
+/**
+ * Instances of this class are used to ensure that an
+ * application cannot interfere with the locking mechanism
+ * used to implement asynchronous and synchronous communication
+ * between widgets and background threads.
+ */
+
+class RunnableLock  {
+	Runnable runnable;
+	Thread thread;
+	TracedException throwable;
+
+this (Runnable runnable) {
+	this.runnable = runnable;
+}
+
+bool done () {
+	return runnable == null || throwable != null;
+}
+
+void run () {
+	if (runnable != null) runnable.run ();
+	runnable = null;
+}
+
+//PORTING_FIXME: How to emulate Java locking?
+void notifyAll(){
+}
+//PORTING_FIXME: How to emulate Java locking?
+void wait(){
+}
+
+}
--- a/dwt/widgets/Synchronizer.d	Fri Jan 11 06:46:36 2008 +0100
+++ b/dwt/widgets/Synchronizer.d	Fri Jan 11 07:11:08 2008 +0100
@@ -11,21 +11,13 @@
 module dwt.widgets.Synchronizer;
 
 import dwt.widgets.Display;
+import dwt.widgets.RunnableLock;
 import dwt.dwthelper.Runnable;
+import dwt.internal.Compatibility;
 
-class Synchronizer{
-    public this (Display display) {
-    }
-    package void asyncExec (Runnable runnable) {}
-    package void syncExec (Runnable runnable) {}
-    int getMessageCount ();
-    package Thread syncThread;
-    bool runAsyncMessages (bool all);
-    void releaseSynchronizer ();
-}
-/++
-import dwt.*;
-import dwt.internal.Compatibility;
+import dwt.SWT;
+import tango.core.Thread;
+import tango.core.Exception;
 
 /**
  * Instances of this class provide synchronization support
@@ -48,7 +40,7 @@
 	Display display;
 	int messageCount;
 	RunnableLock [] messages;
-	Object messageLock = new Object ();
+	Object messageLock;
 	Thread syncThread;
 
 /**
@@ -58,19 +50,20 @@
  */
 public this (Display display) {
 	this.display = display;
+    messageLock = new Object ();
 }
 
 void addLast (RunnableLock lock) {
-	boolean wake = false;
+	bool wake = false;
 	synchronized (messageLock) {
-		if (messages == null) messages = new RunnableLock [4];
-		if (messageCount == messages.length) {
+		if (messages is null) messages = new RunnableLock [4];
+		if (messageCount is messages.length) {
 			RunnableLock[] newMessages = new RunnableLock [messageCount + 4];
 			System.arraycopy (messages, 0, newMessages, 0, messageCount);
 			messages = newMessages;
 		}
 		messages [messageCount++] = lock;
-		wake = messageCount == 1;
+		wake = messageCount is 1;
 	}
 	if (wake) display.wakeThread ();
 }
@@ -86,8 +79,8 @@
  *
  * @see #syncExec
  */
-protected void asyncExec (Runnable runnable) {
-	if (runnable == null) {
+public void asyncExec (Runnable runnable) {
+	if (runnable is null) {
 		display.wake ();
 		return;
 	}
@@ -109,32 +102,32 @@
 
 RunnableLock removeFirst () {
 	synchronized (messageLock) {
-		if (messageCount == 0) return null;
+		if (messageCount is 0) return null;
 		RunnableLock lock = messages [0];
 		System.arraycopy (messages, 1, messages, 0, --messageCount);
 		messages [messageCount] = null;
-		if (messageCount == 0) {
+		if (messageCount is 0) {
 			if (messages.length > 64) messages = null;
 		}
 		return lock;
 	}
 }
 
-boolean runAsyncMessages () {
+bool runAsyncMessages () {
 	return runAsyncMessages (false);
 }
 
-boolean runAsyncMessages (boolean all) {
-	boolean run = false;
+bool runAsyncMessages (bool all) {
+	bool run = false;
 	do {
 		RunnableLock lock = removeFirst ();
-		if (lock == null) return run;
+		if (lock is null) return run;
 		run = true;
 		synchronized (lock) {
 			syncThread = lock.thread;
 			try {
 				lock.run ();
-			} catch (Throwable t) {
+			} catch (TracedException t) {
 				lock.throwable = t;
 				SWT.error (SWT.ERROR_FAILED_EXEC, t);
 			} finally {
@@ -160,12 +153,12 @@
  *
  * @see #asyncExec
  */
-protected void syncExec (Runnable runnable) {
+public void syncExec (Runnable runnable) {
 	if (display.isValidThread ()) {
-		if (runnable != null) runnable.run ();
+		if (runnable !is null) runnable.run ();
 		return;
 	}
-	if (runnable == null) {
+	if (runnable is null) {
 		display.wake ();
 		return;
 	}
@@ -173,25 +166,24 @@
 	/*
 	 * Only remember the syncThread for syncExec.
 	 */
-	lock.thread = Thread.currentThread();
+	lock.thread = Thread.getThis();
 	synchronized (lock) {
 		addLast (lock);
-		boolean interrupted = false;
+		bool interrupted = false;
 		while (!lock.done ()) {
 			try {
 				lock.wait ();
-			} catch (InterruptedException e) {
+			} catch (SyncException e) {
 				interrupted = true;
 			}
 		}
 		if (interrupted) {
 			Compatibility.interrupt();
 		}
-		if (lock.throwable != null) {
+		if (lock.throwable !is null) {
 			SWT.error (SWT.ERROR_FAILED_EXEC, lock.throwable);
 		}
 	}
 }
 
 }
-++/
\ No newline at end of file
--- a/dwt/widgets/Widget.d	Fri Jan 11 06:46:36 2008 +0100
+++ b/dwt/widgets/Widget.d	Fri Jan 11 07:11:08 2008 +0100
@@ -25,6 +25,7 @@
 
 import tango.stdc.stringz;
 import tango.stdc.string;
+import tango.core.Thread;
 
 /**
  * This class is the abstract superclass of all user interface objects.
--- a/todo.txt	Fri Jan 11 06:46:36 2008 +0100
+++ b/todo.txt	Fri Jan 11 07:11:08 2008 +0100
@@ -18,7 +18,7 @@
     * accessibility package (independant)
     * Shell
 
-Button, EventTable, Menu, ScrollBar, Synchronizer, Tray
+EventTable, Menu, Tray
 
 Questions:
     Whats needed at minimum to make a test with empty window?
@@ -74,7 +74,7 @@
 graphics/TextStyle                     // OK
 graphics/Transform                     // OK
 
-widgets/Button
+widgets/Button                         // OK
 widgets/Canvas                         // OK
 widgets/Caret                          //
 widgets/ColorDialog
@@ -95,7 +95,7 @@
 widgets/FileDialog
 widgets/FontDialog
 widgets/Group
-widgets/ImageList
+widgets/ImageList                      // OK
 widgets/Item
 widgets/Label
 widgets/Layout
@@ -107,15 +107,15 @@
 widgets/MessageBox
 widgets/Monitor
 widgets/ProgressBar
-widgets/RunnableLock
+widgets/RunnableLock                   // OK
 widgets/Sash
 widgets/Scale
 widgets/Scrollable
-widgets/ScrollBar
+widgets/ScrollBar                      // OK
 widgets/Shell                          //Decorations,Canvas,Composite,Scrollable,Control,Widget
 widgets/Slider
 widgets/Spinner
-widgets/Synchronizer
+widgets/Synchronizer                   // OK
 widgets/TabFolder
 widgets/TabItem
 widgets/Table