Mercurial > projects > dwt-addons
diff dwtx/core/internal/jobs/OrderedLock.d @ 167:862b05e0334a
Add a wrapper for Thread
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 09 Sep 2008 15:59:16 +0200 |
parents | 9d0585bcb7aa |
children |
line wrap: on
line diff
--- a/dwtx/core/internal/jobs/OrderedLock.d Mon Sep 08 01:01:30 2008 +0200 +++ b/dwtx/core/internal/jobs/OrderedLock.d Tue Sep 09 15:59:16 2008 +0200 @@ -13,7 +13,7 @@ module dwtx.core.internal.jobs.OrderedLock; import tango.text.convert.Format; -import tango.core.Thread; +import dwtx.dwtxhelper.JThread; import tango.io.Stdout; import dwt.dwthelper.utils; @@ -53,7 +53,7 @@ /** * The thread of the operation that currently owns the lock. */ - private /+volatile+/ Thread currentOperationThread; + private /+volatile+/ JThread currentOperationThread; /** * Records the number of successive acquires in the same * thread. The lock is released only when the depth @@ -116,13 +116,13 @@ if (semaphore is null) return true; if (DEBUG) - Stdout.formatln("[{}] Operation waiting to be executed... ", Thread.getThis(), this); //$NON-NLS-1$ //$NON-NLS-2$ + Stdout.formatln("[{}] Operation waiting to be executed... ", JThread.currentThread(), this); //$NON-NLS-1$ //$NON-NLS-2$ success = doAcquire(semaphore, delay); - manager.resumeSuspendedLocks(Thread.getThis()); + manager.resumeSuspendedLocks(JThread.currentThread()); if (DEBUG && success) - Stdout.formatln("[{}] Operation started... ", Thread.getThis(), this); //$NON-NLS-1$ //$NON-NLS-2$ + Stdout.formatln("[{}] Operation started... ", JThread.currentThread(), this); //$NON-NLS-1$ //$NON-NLS-2$ else if (DEBUG) - Stdout.formatln("[{}] Operation timed out... ", Thread.getThis(), this); //$NON-NLS-1$ //$NON-NLS-2$ + Stdout.formatln("[{}] Operation timed out... ", JThread.currentThread(), this); //$NON-NLS-1$ //$NON-NLS-2$ return success; } @@ -133,9 +133,9 @@ private synchronized bool attempt() { //return true if we already own the lock //also, if nobody is waiting, grant the lock immediately - if ((currentOperationThread is Thread.getThis()) || (currentOperationThread is null && operations.isEmpty())) { + if ((currentOperationThread is JThread.currentThread()) || (currentOperationThread is null && operations.isEmpty())) { depth++; - setCurrentOperationThread(Thread.getThis()); + setCurrentOperationThread(JThread.currentThread()); return true; } return false; @@ -154,7 +154,7 @@ * otherwise a new semaphore will be created, enqueued, and returned. */ private synchronized Semaphore createSemaphore() { - return attempt() ? null : enqueue(new Semaphore(Thread.getThis())); + return attempt() ? null : enqueue(new Semaphore(JThread.currentThread())); } /** @@ -179,12 +179,12 @@ semaphore = createSemaphore(); if (semaphore is null) return true; - manager.addLockWaitThread(Thread.getThis(), this); + manager.addLockWaitThread(JThread.currentThread(), this); try { success = semaphore.acquire(delay); } catch (InterruptedException e) { if (DEBUG) - Stdout.formatln(Format("[{}] Operation interrupted while waiting... :-|", Thread.getThis())); //$NON-NLS-1$ //$NON-NLS-2$ + Stdout.formatln(Format("[{}] Operation interrupted while waiting... :-|", JThread.currentThread())); //$NON-NLS-1$ //$NON-NLS-2$ throw e; } if (success) { @@ -192,7 +192,7 @@ updateCurrentOperation(); } else { removeFromQueue(semaphore); - manager.removeLockWaitThread(Thread.getThis(), this); + manager.removeLockWaitThread(JThread.currentThread(), this); } return success; } @@ -278,7 +278,7 @@ * If newThread is null, release this lock from its previous owner. * If newThread is not null, grant this lock to newThread. */ - private void setCurrentOperationThread(Thread newThread) { + private void setCurrentOperationThread(JThread newThread) { if ((currentOperationThread !is null) && (newThread is null)) manager.removeLockThread(currentOperationThread, this); this.currentOperationThread = newThread; @@ -313,6 +313,6 @@ */ private synchronized void updateCurrentOperation() { operations.dequeue(); - setCurrentOperationThread(Thread.getThis()); + setCurrentOperationThread(JThread.currentThread()); } }