/** * Adds a new scheduling rule to the stack of rules for this thread. Throws * a runtime exception if the new rule is not compatible with the base * scheduling rule for this thread. * @GuardedBy("JobManager.implicitJobs") */ void push(final ISchedulingRule rule) { final ISchedulingRule baseRule = getRule(); if (++top >= ruleStack.length) { ISchedulingRule[] newStack = new ISchedulingRule[ruleStack.length * 2]; System.arraycopy(ruleStack, 0, newStack, 0, ruleStack.length); ruleStack = newStack; } ruleStack[top] = rule; if (JobManager.DEBUG_BEGIN_END) lastPush = (RuntimeException) new RuntimeException().fillInStackTrace(); //check for containment last because we don't want to fail again on endRule if (baseRule != null && rule != null && !baseRule.contains(rule)) illegalPush(rule, baseRule); }
/** * Adds a new scheduling rule to the stack of rules for this thread. Throws * a runtime exception if the new rule is not compatible with the base * scheduling rule for this thread. * @GuardedBy("JobManager.implicitJobs") */ void push(final ISchedulingRule rule) { final ISchedulingRule baseRule = getRule(); if (++top >= ruleStack.length) { ISchedulingRule[] newStack = new ISchedulingRule[ruleStack.length * 2]; System.arraycopy(ruleStack, 0, newStack, 0, ruleStack.length); ruleStack = newStack; } ruleStack[top] = rule; if (JobManager.DEBUG_BEGIN_END) lastPush = (RuntimeException) new RuntimeException().fillInStackTrace(); //check for containment last because we don't want to fail again on endRule if (baseRule != null && rule != null && !(baseRule.contains(rule) && baseRule.isConflicting(rule))) illegalPush(rule, baseRule); }
/** * Adds a new scheduling rule to the stack of rules for this thread. Throws * a runtime exception if the new rule is not compatible with the base * scheduling rule for this thread. * @GuardedBy("JobManager.implicitJobs") */ void push(final ISchedulingRule rule) { final ISchedulingRule baseRule = getRule(); if (++top >= ruleStack.length) { ISchedulingRule[] newStack = new ISchedulingRule[ruleStack.length * 2]; System.arraycopy(ruleStack, 0, newStack, 0, ruleStack.length); ruleStack = newStack; } ruleStack[top] = rule; if (JobManager.DEBUG_BEGIN_END) lastPush = (RuntimeException) new RuntimeException().fillInStackTrace(); //check for containment last because we don't want to fail again on endRule if (baseRule != null && rule != null && !(baseRule.contains(rule) && baseRule.isConflicting(rule))) illegalPush(rule, baseRule); }
/** * 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); }
/** * 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); } }
/** * 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); }
/** * 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); } }
/** * @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); }