Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 308252
Collapse All | Expand All

(-)src/org/eclipse/emf/transaction/util/Lock.java (-32 / +53 lines)
Lines 267-272 Link Here
267
	 * @see org.eclipse.emf.transaction.util.ITransactionLock#uiSafeAcquire(boolean)
267
	 * @see org.eclipse.emf.transaction.util.ITransactionLock#uiSafeAcquire(boolean)
268
	 */
268
	 */
269
	public void uiSafeAcquire(boolean exclusive) throws InterruptedException {
269
	public void uiSafeAcquire(boolean exclusive) throws InterruptedException {
270
        // If we already are interrupted, we abort early
271
        if (Thread.interrupted()) {
272
        	InterruptedException exc = new InterruptedException();
273
			Tracing.throwing(Lock.class, "uiSafeAcquire", exc); //$NON-NLS-1$
274
			throw exc;
275
        }
276
        
270
        // Only try the special acquiring procedure for Display thread and when
277
        // Only try the special acquiring procedure for Display thread and when
271
        // no begin rule is done on the display thread.
278
        // no begin rule is done on the display thread.
272
        boolean acquired = false;
279
        boolean acquired = false;
Lines 283-293 Link Here
283
            jobRule = new AcquireRule();
290
            jobRule = new AcquireRule();
284
        }
291
        }
285
292
286
        // if we already are interrupted, clear the interrupt status
287
        // because we will be performing a timed wait that must not
288
        // be interrupted. We ignore interrupts because we know that
289
        // the UI thread will often be interrupted by Display.syncExec
290
        Thread.interrupted();
291
293
292
        if (Tracing.shouldTrace(EMFTransactionDebugOptions.LOCKING)) {
294
        if (Tracing.shouldTrace(EMFTransactionDebugOptions.LOCKING)) {
293
            Tracing.trace("::: UI-Safe Acquire  [id=" //$NON-NLS-1$
295
            Tracing.trace("::: UI-Safe Acquire  [id=" //$NON-NLS-1$
Lines 304-309 Link Here
304
            return;
306
            return;
305
        }
307
        }
306
308
309
        boolean interrupted=false;
310
        try{
307
        // loop until the lock is acquired
311
        // loop until the lock is acquired
308
    	AcquireJob job = new AcquireJob(current, exclusive);
312
    	AcquireJob job = new AcquireJob(current, exclusive);
309
        job.setRule(jobRule);
313
        job.setRule(jobRule);
Lines 390-397 Link Here
390
                            try {
394
                            try {
391
                            	acquired = acquire(250L, exclusive);
395
                            	acquired = acquire(250L, exclusive);
392
                            } catch (InterruptedException e) {
396
                            } catch (InterruptedException e) {
393
                            	Thread.interrupted();
397
                            	// Why not just re-throw this exception? Not changing behavior now. 
394
                            	// ignore the exception
398
                            	interrupted=true;
395
                            }
399
                            }
396
                        } else {
400
                        } else {
397
                            acquired = getOwner() == current;
401
                            acquired = getOwner() == current;
Lines 412-427 Link Here
412
416
413
                    resume();
417
                    resume();
414
                } else if (jobStatus.getSeverity() == IStatus.CANCEL) {
418
                } else if (jobStatus.getSeverity() == IStatus.CANCEL) {
415
                    // user canceled.  Interrupt
419
                    // user canceled.
416
                    Thread.interrupted();
417
                    InterruptedException exc = new InterruptedException();
420
                    InterruptedException exc = new InterruptedException();
418
                    Tracing.throwing(Lock.class, "uiSafeAcquire", exc); //$NON-NLS-1$
421
                    Tracing.throwing(Lock.class, "uiSafeAcquire", exc); //$NON-NLS-1$
419
                    throw exc;
422
                    throw exc;
420
                }
423
                }
421
            } catch (OperationCanceledException e) {
424
            } catch (OperationCanceledException e) {
422
                // user canceled.  Interrupt
425
                // user canceled.  
423
                Thread.interrupted();
424
                InterruptedException exc = new InterruptedException();
426
                InterruptedException exc = new InterruptedException();
427
                exc.initCause(e);
425
                Tracing.throwing(Lock.class, "uiSafeAcquire", exc); //$NON-NLS-1$
428
                Tracing.throwing(Lock.class, "uiSafeAcquire", exc); //$NON-NLS-1$
426
                throw exc;
429
                throw exc;
427
            } catch (IllegalArgumentException e) {
430
            } catch (IllegalArgumentException e) {
Lines 434-439 Link Here
434
                InterruptedException exc = (e.getLocalizedMessage() != null) ? new InterruptedException(
437
                InterruptedException exc = (e.getLocalizedMessage() != null) ? new InterruptedException(
435
                    e.getLocalizedMessage())
438
                    e.getLocalizedMessage())
436
                    : new InterruptedException();
439
                    : new InterruptedException();
440
                exc.initCause(e);
437
                Tracing.throwing(Lock.class, "uiSafeAcquire", exc); //$NON-NLS-1$
441
                Tracing.throwing(Lock.class, "uiSafeAcquire", exc); //$NON-NLS-1$
438
                throw exc;
442
                throw exc;
439
            } finally {
443
            } finally {
Lines 452-457 Link Here
452
                }
456
                }
453
            }
457
            }
454
        }
458
        }
459
        } finally {
460
        	//propogate interruptions
461
        	if (interrupted)
462
        		Thread.currentThread().interrupt();
463
        }
455
464
456
        assert getOwner() == current;
465
        assert getOwner() == current;
457
    }
466
    }
Lines 481-499 Link Here
481
		long start = System.currentTimeMillis();
490
		long start = System.currentTimeMillis();
482
		boolean result = false;
491
		boolean result = false;
483
		
492
		
484
		while (timeout > 0L) {
493
		boolean interrupted = false;
485
			try {
494
		try {
486
				result = acquire(timeout, exclusive);
495
			while (timeout > 0L) {
487
				break;
496
				try {
488
			} catch (InterruptedException e) {
497
					result = acquire(timeout, exclusive);
489
				// ignore it and clear the interrupt status
498
					break;
490
				Thread.interrupted();
499
				} catch (InterruptedException e) {
491
				
500
					interrupted=true;
492
				// see how much longer we have to wait
501
					
493
				long when = System.currentTimeMillis();
502
					// see how much longer we have to wait
494
				timeout -= (when - start);  // how long did we just wait?
503
					long when = System.currentTimeMillis();
495
				start = when;               // restart the clock
504
					timeout -= (when - start);  // how long did we just wait?
505
					start = when;               // restart the clock
506
				}
496
			}
507
			}
508
		} finally {
509
			// Propogate InterruptedException
510
			if (interrupted)
511
				Thread.currentThread().interrupt();
497
		}
512
		}
498
		
513
		
499
		return result;
514
		return result;
Lines 506-521 Link Here
506
	 * @param o the object to wait for without interruption
521
	 * @param o the object to wait for without interruption
507
	 */
522
	 */
508
	private static void uninterruptibleWait(Object o) {
523
	private static void uninterruptibleWait(Object o) {
509
		synchronized (o) {
524
		boolean interrupted=false;
510
			for (;;) {
525
		try {
511
				try {
526
			synchronized (o) {
512
					o.wait();
527
				for (;;) {
513
					break;
528
					try {
514
				} catch (InterruptedException e) {
529
						o.wait();
515
					// ignore it and clear the interrupt status
530
						break;
516
					Thread.interrupted();
531
					} catch (InterruptedException e) {
532
						interrupted=true;
533
					}
517
				}
534
				}
518
			}
535
			}
536
		} finally {
537
			// Propogate InterruptedException
538
			if (interrupted)
539
				Thread.currentThread().interrupt();
519
		}
540
		}
520
	}
541
	}
521
	
542
	
Lines 743-749 Link Here
743
                    }
764
                    }
744
                } catch (InterruptedException e) {
765
                } catch (InterruptedException e) {
745
                    // I was interrupted: give up
766
                    // I was interrupted: give up
746
                    Thread.interrupted(); // clear interrupt flag
767
                	// There is no need to propagate InterruptedException since we are terminating thread execution
747
                    acquireStatus = Status.CANCEL_STATUS;
768
                    acquireStatus = Status.CANCEL_STATUS;
748
                    return acquireStatus;
769
                    return acquireStatus;
749
                }
770
                }

Return to bug 308252