/** * 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); } }
/** * Implements IJobManager#transferRule(ISchedulingRule, Thread) */ synchronized void transfer(ISchedulingRule rule, Thread destinationThread) { //nothing to do for null if (rule == null) return; final Thread currentThread = Thread.currentThread(); //nothing to do if transferring to the same thread if (currentThread == destinationThread) return; //ensure destination thread doesn't already have a rule ThreadJob job = (ThreadJob) threadJobs.get(destinationThread); Assert.isLegal(job == null, "Transfer rule to job that already owns a rule"); //$NON-NLS-1$ //ensure calling thread owns the job being transferred job = (ThreadJob) threadJobs.get(currentThread); Assert.isNotNull(job, "transferRule without beginRule"); //$NON-NLS-1$ Assert.isLegal(job.getRule() == rule, "transferred rule " + rule + " does not match beginRule: " + job.getRule()); //$NON-NLS-1$ //$NON-NLS-2$ //transfer the thread job without ending it job.setThread(destinationThread); threadJobs.remove(currentThread); threadJobs.put(destinationThread, job); //transfer lock if (job.acquireRule) { manager.getLockManager().removeLockThread(currentThread, rule); manager.getLockManager().addLockThread(destinationThread, rule); } } }
/** * Implements IJobManager#transferRule(ISchedulingRule, Thread) */ synchronized void transfer(ISchedulingRule rule, Thread destinationThread) { //nothing to do for null if (rule == null) return; final Thread currentThread = Thread.currentThread(); //nothing to do if transferring to the same thread if (currentThread == destinationThread) return; //ensure destination thread doesn't already have a rule ThreadJob target = threadJobs.get(destinationThread); Assert.isLegal(target == null, "Transfer rule to job that already owns a rule"); //$NON-NLS-1$ //ensure calling thread owns the job being transferred ThreadJob source = threadJobs.get(currentThread); Assert.isNotNull(source, "transferRule without beginRule"); //$NON-NLS-1$ Assert.isLegal(source.getRule() == rule, "transferred rule " + rule + " does not match beginRule: " + source.getRule()); //$NON-NLS-1$ //$NON-NLS-2$ // transfer the thread job without ending it source.setThread(destinationThread); threadJobs.remove(currentThread); threadJobs.put(destinationThread, source); // transfer lock if (source.acquireRule) { manager.getLockManager().removeLockThread(currentThread, rule); manager.getLockManager().addLockThread(destinationThread, rule); } // Wake up any blocked jobs (waiting within yield or joinRun) waiting on // this rule notifyWaitingThreadJobs(source); }
/** * Implements IJobManager#transferRule(ISchedulingRule, Thread) */ synchronized void transfer(ISchedulingRule rule, Thread destinationThread) { //nothing to do for null if (rule == null) return; final Thread currentThread = Thread.currentThread(); //nothing to do if transferring to the same thread if (currentThread == destinationThread) return; //ensure destination thread doesn't already have a rule ThreadJob target = threadJobs.get(destinationThread); Assert.isLegal(target == null, "Transfer rule to job that already owns a rule"); //$NON-NLS-1$ //ensure calling thread owns the job being transferred ThreadJob source = threadJobs.get(currentThread); Assert.isNotNull(source, "transferRule without beginRule"); //$NON-NLS-1$ Assert.isLegal(source.getRule() == rule, "transferred rule " + rule + " does not match beginRule: " + source.getRule()); //$NON-NLS-1$ //$NON-NLS-2$ // transfer the thread job without ending it source.setThread(destinationThread); threadJobs.remove(currentThread); threadJobs.put(destinationThread, source); // transfer lock if (source.acquireRule) { manager.getLockManager().removeLockThread(currentThread, rule); manager.getLockManager().addLockThread(destinationThread, rule); } // Wake up any blocked jobs (waiting within yield or joinRun) waiting on // this rule notifyWaitingThreadJobs(source); }
/** * Implements IJobManager#transferRule(ISchedulingRule, Thread) */ synchronized void transfer(ISchedulingRule rule, Thread destinationThread) { //nothing to do for null if (rule == null) return; final Thread currentThread = Thread.currentThread(); //nothing to do if transferring to the same thread if (currentThread == destinationThread) return; //ensure destination thread doesn't already have a rule ThreadJob target = (ThreadJob) threadJobs.get(destinationThread); Assert.isLegal(target == null, "Transfer rule to job that already owns a rule"); //$NON-NLS-1$ //ensure calling thread owns the job being transferred ThreadJob source = (ThreadJob) threadJobs.get(currentThread); Assert.isNotNull(source, "transferRule without beginRule"); //$NON-NLS-1$ Assert.isLegal(source.getRule() == rule, "transferred rule " + rule + " does not match beginRule: " + source.getRule()); //$NON-NLS-1$ //$NON-NLS-2$ // transfer the thread job without ending it source.setThread(destinationThread); threadJobs.remove(currentThread); threadJobs.put(destinationThread, source); // transfer lock if (source.acquireRule) { manager.getLockManager().removeLockThread(currentThread, rule); manager.getLockManager().addLockThread(destinationThread, rule); } // Wake up any blocked jobs (waiting within yield or joinRun) waiting on // this rule notifyWaitingThreadJobs(source); }
private void endThreadJob(ThreadJob threadJob, boolean resume) { Thread currentThread = Thread.currentThread(); //clean up when last rule scope exits threadJobs.remove(currentThread); ISchedulingRule rule = threadJob.getRule(); if (resume && rule != null) suspendedRules.remove(rule); //if this job had a rule, then we are essentially releasing a lock //note it is safe to do this even if the acquire was aborted if (threadJob.acquireRule) { manager.getLockManager().removeLockThread(currentThread, rule); notifyWaitingThreadJobs(); } //if the job was started, we need to notify job manager to end it if (threadJob.isRunning()) manager.endJob(threadJob, Status.OK_STATUS, false); recycle(threadJob); }
/** * @GuardedBy("this") */ private void endThreadJob(ThreadJob threadJob, boolean resume) { Thread currentThread = Thread.currentThread(); //clean up when last rule scope exits threadJobs.remove(currentThread); ISchedulingRule rule = threadJob.getRule(); if (resume && rule != null) suspendedRules.remove(rule); //if this job had a rule, then we are essentially releasing a lock //note it is safe to do this even if the acquire was aborted if (threadJob.acquireRule) { manager.getLockManager().removeLockThread(currentThread, rule); notifyWaitingThreadJobs(threadJob); } //if the job was started, we need to notify job manager to end it if (threadJob.isRunning()) manager.endJob(threadJob, Status.OK_STATUS, false); recycle(threadJob); }
/** * @GuardedBy("this") */ private void endThreadJob(ThreadJob threadJob, boolean resume) { Thread currentThread = Thread.currentThread(); //clean up when last rule scope exits threadJobs.remove(currentThread); ISchedulingRule rule = threadJob.getRule(); if (resume && rule != null) suspendedRules.remove(rule); //if this job had a rule, then we are essentially releasing a lock //note it is safe to do this even if the acquire was aborted if (threadJob.acquireRule) { manager.getLockManager().removeLockThread(currentThread, rule); notifyWaitingThreadJobs(threadJob); } //if the job was started, we need to notify job manager to end it if (threadJob.isRunning()) manager.endJob(threadJob, Status.OK_STATUS, false); recycle(threadJob); }
/** * @GuardedBy("this") */ private void endThreadJob(ThreadJob threadJob, boolean resume) { Thread currentThread = Thread.currentThread(); //clean up when last rule scope exits threadJobs.remove(currentThread); ISchedulingRule rule = threadJob.getRule(); if (resume && rule != null) suspendedRules.remove(rule); //if this job had a rule, then we are essentially releasing a lock //note it is safe to do this even if the acquire was aborted if (threadJob.acquireRule) { manager.getLockManager().removeLockThread(currentThread, rule); notifyWaitingThreadJobs(threadJob); } //if the job was started, we need to notify job manager to end it if (threadJob.isRunning()) manager.endJob(threadJob, Status.OK_STATUS, false); recycle(threadJob); }
/** * 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); }
/** * 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()); } }
/** * 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) { try { //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); } finally { decrementBusyThreads(); } }
/** * 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) { try { //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); } finally { decrementBusyThreads(); } }
/** * 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) { try { //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); } finally { decrementBusyThreads(); } }
try { if (manager.getLockManager().aboutToWait(blocker)) return threadJob; return waitForRun(threadJob, monitor, blockingJob, blocker); } finally { manager.getLockManager().aboutToRelease();
try { if (manager.getLockManager().aboutToWait(blocker)) return threadJob; return waitForRun(threadJob, monitor, blockingJob, blocker); } finally { manager.getLockManager().aboutToRelease();
try { if (manager.getLockManager().aboutToWait(blocker)) return threadJob; return waitForRun(threadJob, monitor, blockingJob, blocker); } finally { manager.getLockManager().aboutToRelease();
/** * 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); } }
/** * 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); } }
/** * 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); } }