@Override public ILock newLock() { return lockManager.newLock(); }
/** * 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) { if ((currentOperationThread != null) && (newThread == null)) manager.removeLockThread(currentOperationThread, this); this.currentOperationThread = newThread; if (currentOperationThread != null) manager.addLockThread(currentOperationThread, this); }
/** * There was an internal error in the deadlock detection code. Shut the entire * thing down to prevent further errors. Recovery is too complex as it * requires freezing all threads and inferring the present lock state. */ private void handleInternalError(Throwable t) { try { handleException(t); } catch (Exception e) { //ignore failure to log } //discard the deadlock detector for good locks = null; }
/** * Releases all the acquires that were called on the given rule. Needs to be called only once. */ void removeLockCompletely(Thread thread, ISchedulingRule rule) { DeadlockDetector tempLocks = locks; if (tempLocks == null) return; try { synchronized (tempLocks) { try { tempLocks.lockReleasedCompletely(thread, rule); } catch (Exception e) { throw createDebugException(tempLocks, e); } } } catch (Exception e) { handleInternalError(e); } }
static ThreadJob waitForRun(ThreadJob threadJob, IProgressMonitor monitor, InternalJob blockingJob, Thread blocker) { final boolean canBlock = manager.getLockManager().canBlock(); ThreadJob result = threadJob; boolean interrupted = false; if (manager.getLockManager().aboutToWait(blocker)) manager.getLockManager().addLockWaitThread(currentThread, threadJob.getRule()); synchronized (blockingJob.jobStateLock) { try { manager.getLockManager().removeLockWaitThread(currentThread, threadJob.getRule());
throw new OperationCanceledException(); lockManager.aboutToWait(null); Thread.sleep(100); lockManager.aboutToRelease(); removeJobChangeListener(listener); reportUnblocked(monitor);
/** * Reports that this thread was blocked, but is no longer blocked and is able * to proceed. * @param monitor The monitor to report unblocking to. */ private void waitEnd(IProgressMonitor monitor) { final LockManager lockManager = manager.getLockManager(); final Thread currentThread = Thread.currentThread(); if (isRunning()) { lockManager.addLockThread(currentThread, getRule()); //need to re-acquire any locks that were suspended while this thread was blocked on the rule lockManager.resumeSuspendedLocks(currentThread); } else { //tell lock manager that this thread gave up waiting lockManager.removeLockWaitThread(currentThread, getRule()); } }
boolean success = false; if (manager.aboutToWait(this.currentOperationThread)) { manager.addLockThread(currentOperationThread, this); return true; if (semaphore == null) return true; manager.addLockWaitThread(Thread.currentThread(), this); try { success = semaphore.acquire(delay); } else { removeFromQueue(semaphore); manager.removeLockWaitThread(Thread.currentThread(), this);
boolean success = false; if (manager.aboutToWait(this.currentOperationThread)) { manager.addLockThread(currentOperationThread, this); return true; return true; final Thread currentThread = Thread.currentThread(); manager.addLockWaitThread(currentThread, this); try { success = semaphore.acquire(delay);
boolean canBlock = lockManager.canBlock(); while (true) { if (monitor != null && monitor.isCanceled()) lockManager.aboutToWait(job.getThread()); try { lockManager.aboutToRelease(); job.removeJobChangeListener(listener);
public void release() { if (depth == 0) return; //only release the lock when the depth reaches zero Assert.isTrue(depth >= 0, "Lock released too many times"); //$NON-NLS-1$ if (--depth == 0) doRelease(); else manager.removeLockThread(currentOperationThread, this); }
/** * Releases all the acquires that were called on the given rule. Needs to be called only once. */ void removeLockCompletely(Thread thread, ISchedulingRule rule) { DeadlockDetector tempLocks = locks; if (tempLocks == null) return; try { synchronized (tempLocks) { tempLocks.lockReleasedCompletely(thread, rule); } } catch (Exception e) { handleInternalError(e); } }
/** * Forces the lock to be at the given depth. * Used when re-acquiring a suspended lock. */ protected void setDepth(int newDepth) { for (int i = depth; i < newDepth; i++) { manager.addLockThread(currentOperationThread, this); } this.depth = newDepth; }
/** * Returns whether this thread currently owns any locks * @return <code>true</code> if this thread owns any locks, and * <code>false</code> otherwise. */ protected final boolean isLockOwnerThread() { return manager.isLockOwner(); } }
/** * Releases this lock from the thread that used to own it. * Grants this lock to the next thread in the queue. */ private synchronized void doRelease() { //notify hook manager.aboutToRelease(); depth = 0; Semaphore next = (Semaphore) operations.peek(); setCurrentOperationThread(null); if (next != null) next.release(); }
/** * Signals the end of a job. Note that this method can be called under * OutOfMemoryError conditions and thus must be paranoid about allocating objects. */ protected void endJob(InternalJob job, IStatus result) { decrementBusyThreads(); //need to end rule in graph before ending job so that 2 threads //do not become the owners of the same rule in the graph if ((job.getRule() != null) && !(job instanceof ThreadJob)) { //remove any locks this thread may be owning on that rule manager.getLockManager().removeLockCompletely(Thread.currentThread(), job.getRule()); } manager.endJob(job, result, true); //ensure this thread no longer owns any scheduling rules manager.implicitJobs.endJob(job); }
/** * Indicates the start of a wait on a scheduling rule. Report the * blockage to the progress manager and update the lock manager. * @param monitor The monitor to report blocking to * @param blockingJob The job that is blocking this thread, or <code>null</code> */ private void waitStart(IProgressMonitor monitor, InternalJob blockingJob) { manager.getLockManager().addLockWaitThread(Thread.currentThread(), getRule()); isBlocked = true; manager.reportBlocked(monitor, blockingJob); } }
static ThreadJob waitForRun(ThreadJob threadJob, IProgressMonitor monitor, InternalJob blockingJob, Thread blocker) { final boolean canBlock = manager.getLockManager().canBlock(); ThreadJob result = threadJob; boolean interrupted = false; if (manager.getLockManager().aboutToWait(blocker)) manager.getLockManager().addLockWaitThread(currentThread, threadJob.getRule()); synchronized (blockingJob.jobStateLock) { try { manager.getLockManager().removeLockWaitThread(currentThread, threadJob.getRule());
throw new OperationCanceledException(); lockManager.aboutToWait(null); Thread.sleep(100); lockManager.aboutToRelease(); removeJobChangeListener(listener); reportUnblocked(monitor);
/** * Reports that this thread was blocked, but is no longer blocked and is able * to proceed. * @param monitor The monitor to report unblocking to. */ static private void waitEnd(ThreadJob threadJob, boolean updateLockManager, IProgressMonitor monitor) { if (updateLockManager) { final LockManager lockManager = manager.getLockManager(); final Thread currentThread = Thread.currentThread(); if (threadJob.isRunning()) { lockManager.addLockThread(currentThread, threadJob.getRule()); //need to re-acquire any locks that were suspended while this thread was blocked on the rule lockManager.resumeSuspendedLocks(currentThread); } else { //tell lock manager that this thread gave up waiting lockManager.removeLockWaitThread(currentThread, threadJob.getRule()); } } if (threadJob.isBlocked) { threadJob.isBlocked = false; manager.reportUnblocked(monitor); } }