Mercurial > projects > dwt2
diff org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/Lock.d @ 22:4642ab680468
some work on dwt-win for tango/phobos
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 20 Mar 2009 12:52:28 +0100 |
parents | 52184e4b815c |
children | 0ecb2b338560 |
line wrap: on
line diff
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/Lock.d Thu Mar 19 20:38:55 2009 +0100 +++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/Lock.d Fri Mar 20 12:52:28 2009 +0100 @@ -13,8 +13,11 @@ module org.eclipse.swt.internal.Lock; import java.lang.Thread; -import tango.core.sync.Mutex; -import tango.core.sync.Condition; +version(Tango){ + import tango.core.sync.Mutex; + import tango.core.sync.Condition; +} else { // Phobos +} /** * Instance of this represent a recursive monitor. @@ -22,52 +25,68 @@ public class Lock { int count, waitCount; Thread owner; - Mutex mutex; - Condition cond; + version(Tango){ + Mutex mutex; + Condition cond; + } else { // Phobos + } + public this() { - mutex = new Mutex; - cond = new Condition(mutex); + version(Tango){ + mutex = new Mutex; + cond = new Condition(mutex); + } else { // Phobos + } } -/** - * Locks the monitor and returns the lock count. If - * the lock is owned by another thread, wait until - * the lock is released. - * - * @return the lock count - */ -public int lock() { - synchronized (mutex) { - Thread current = Thread.currentThread(); - if (owner !is current) { - waitCount++; - while (count > 0) { - try { - cond.wait(); - } catch (SyncException e) { - /* Wait forever, just like synchronized blocks */ + /** + * Locks the monitor and returns the lock count. If + * the lock is owned by another thread, wait until + * the lock is released. + * + * @return the lock count + */ + public int lock() { + version(Tango){ + synchronized (mutex) { + Thread current = Thread.currentThread(); + if (owner !is current) { + waitCount++; + while (count > 0) { + try { + cond.wait(); + } catch (SyncException e) { + /* Wait forever, just like synchronized blocks */ + } + } + --waitCount; + owner = current; + } + return ++count; + } + } else { // Phobos + implMissing( __FILE__, __LINE__ ); + return 0; + } + } + + /** + * Unlocks the monitor. If the current thread is not + * the monitor owner, do nothing. + */ + public void unlock() { + version(Tango){ + synchronized (mutex) { + Thread current = Thread.currentThread(); + if (owner is current) { + if (--count is 0) { + owner = null; + if (waitCount > 0) cond.notifyAll(); + } } } - --waitCount; - owner = current; - } - return ++count; - } -} - -/** - * Unlocks the monitor. If the current thread is not - * the monitor owner, do nothing. - */ -public void unlock() { - synchronized (mutex) { - Thread current = Thread.currentThread(); - if (owner is current) { - if (--count is 0) { - owner = null; - if (waitCount > 0) cond.notifyAll(); - } + } else { // Phobos + implMissing( __FILE__, __LINE__ ); } } } -}