Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 163946 Details for
Bug 308252
EMF's Lock class doesn't restore/propogate InterruptedExceptions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Propagate InterruptedExceptions
emfLock.patch (text/plain), 6.31 KB, created by
Min Idzelis
on 2010-04-06 14:14:03 EDT
(
hide
)
Description:
Propagate InterruptedExceptions
Filename:
MIME Type:
Creator:
Min Idzelis
Created:
2010-04-06 14:14:03 EDT
Size:
6.31 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.emf.transaction >Index: src/org/eclipse/emf/transaction/util/Lock.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.transaction/plugins/org.eclipse.emf.transaction/src/org/eclipse/emf/transaction/util/Lock.java,v >retrieving revision 1.16 >diff -u -r1.16 Lock.java >--- src/org/eclipse/emf/transaction/util/Lock.java 31 Mar 2010 21:01:56 -0000 1.16 >+++ src/org/eclipse/emf/transaction/util/Lock.java 6 Apr 2010 18:13:39 -0000 >@@ -267,6 +267,13 @@ > * @see org.eclipse.emf.transaction.util.ITransactionLock#uiSafeAcquire(boolean) > */ > public void uiSafeAcquire(boolean exclusive) throws InterruptedException { >+ // If we already are interrupted, we abort early >+ if (Thread.interrupted()) { >+ InterruptedException exc = new InterruptedException(); >+ Tracing.throwing(Lock.class, "uiSafeAcquire", exc); //$NON-NLS-1$ >+ throw exc; >+ } >+ > // Only try the special acquiring procedure for Display thread and when > // no begin rule is done on the display thread. > boolean acquired = false; >@@ -283,11 +290,6 @@ > jobRule = new AcquireRule(); > } > >- // if we already are interrupted, clear the interrupt status >- // because we will be performing a timed wait that must not >- // be interrupted. We ignore interrupts because we know that >- // the UI thread will often be interrupted by Display.syncExec >- Thread.interrupted(); > > if (Tracing.shouldTrace(EMFTransactionDebugOptions.LOCKING)) { > Tracing.trace("::: UI-Safe Acquire [id=" //$NON-NLS-1$ >@@ -304,6 +306,8 @@ > return; > } > >+ boolean interrupted=false; >+ try{ > // loop until the lock is acquired > AcquireJob job = new AcquireJob(current, exclusive); > job.setRule(jobRule); >@@ -390,8 +394,8 @@ > try { > acquired = acquire(250L, exclusive); > } catch (InterruptedException e) { >- Thread.interrupted(); >- // ignore the exception >+ // Why not just re-throw this exception? Not changing behavior now. >+ interrupted=true; > } > } else { > acquired = getOwner() == current; >@@ -412,16 +416,15 @@ > > resume(); > } else if (jobStatus.getSeverity() == IStatus.CANCEL) { >- // user canceled. Interrupt >- Thread.interrupted(); >+ // user canceled. > InterruptedException exc = new InterruptedException(); > Tracing.throwing(Lock.class, "uiSafeAcquire", exc); //$NON-NLS-1$ > throw exc; > } > } catch (OperationCanceledException e) { >- // user canceled. Interrupt >- Thread.interrupted(); >+ // user canceled. > InterruptedException exc = new InterruptedException(); >+ exc.initCause(e); > Tracing.throwing(Lock.class, "uiSafeAcquire", exc); //$NON-NLS-1$ > throw exc; > } catch (IllegalArgumentException e) { >@@ -434,6 +437,7 @@ > InterruptedException exc = (e.getLocalizedMessage() != null) ? new InterruptedException( > e.getLocalizedMessage()) > : new InterruptedException(); >+ exc.initCause(e); > Tracing.throwing(Lock.class, "uiSafeAcquire", exc); //$NON-NLS-1$ > throw exc; > } finally { >@@ -452,6 +456,11 @@ > } > } > } >+ } finally { >+ //propogate interruptions >+ if (interrupted) >+ Thread.currentThread().interrupt(); >+ } > > assert getOwner() == current; > } >@@ -481,19 +490,25 @@ > long start = System.currentTimeMillis(); > boolean result = false; > >- while (timeout > 0L) { >- try { >- result = acquire(timeout, exclusive); >- break; >- } catch (InterruptedException e) { >- // ignore it and clear the interrupt status >- Thread.interrupted(); >- >- // see how much longer we have to wait >- long when = System.currentTimeMillis(); >- timeout -= (when - start); // how long did we just wait? >- start = when; // restart the clock >+ boolean interrupted = false; >+ try { >+ while (timeout > 0L) { >+ try { >+ result = acquire(timeout, exclusive); >+ break; >+ } catch (InterruptedException e) { >+ interrupted=true; >+ >+ // see how much longer we have to wait >+ long when = System.currentTimeMillis(); >+ timeout -= (when - start); // how long did we just wait? >+ start = when; // restart the clock >+ } > } >+ } finally { >+ // Propogate InterruptedException >+ if (interrupted) >+ Thread.currentThread().interrupt(); > } > > return result; >@@ -506,16 +521,22 @@ > * @param o the object to wait for without interruption > */ > private static void uninterruptibleWait(Object o) { >- synchronized (o) { >- for (;;) { >- try { >- o.wait(); >- break; >- } catch (InterruptedException e) { >- // ignore it and clear the interrupt status >- Thread.interrupted(); >+ boolean interrupted=false; >+ try { >+ synchronized (o) { >+ for (;;) { >+ try { >+ o.wait(); >+ break; >+ } catch (InterruptedException e) { >+ interrupted=true; >+ } > } > } >+ } finally { >+ // Propogate InterruptedException >+ if (interrupted) >+ Thread.currentThread().interrupt(); > } > } > >@@ -743,7 +764,7 @@ > } > } catch (InterruptedException e) { > // I was interrupted: give up >- Thread.interrupted(); // clear interrupt flag >+ // There is no need to propagate InterruptedException since we are terminating thread execution > acquireStatus = Status.CANCEL_STATUS; > return acquireStatus; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 308252
: 163946