synchronized void removeWaiting(ThreadJob threadJob) { synchronized (((InternalJob) threadJob).jobStateLock) { threadJob.isWaiting = false; notifyWaitingThreadJobs(threadJob); ((InternalJob) threadJob).setWaitQueueStamp(InternalJob.T_NONE); } manager.dequeue(manager.waitingThreadJobs, threadJob); }
synchronized void removeWaiting(ThreadJob threadJob) { synchronized (((InternalJob) threadJob).jobStateLock) { threadJob.isWaiting = false; notifyWaitingThreadJobs(threadJob); ((InternalJob) threadJob).setWaitQueueStamp(InternalJob.T_NONE); } manager.dequeue(manager.waitingThreadJobs, threadJob); }
synchronized void removeWaiting(ThreadJob threadJob) { synchronized (((InternalJob) threadJob).jobStateLock) { threadJob.isWaiting = false; notifyWaitingThreadJobs(threadJob); ((InternalJob) threadJob).setWaitQueueStamp(InternalJob.T_NONE); } manager.dequeue(manager.waitingThreadJobs, threadJob); }
synchronized void addWaiting(ThreadJob threadJob) { synchronized (((InternalJob) threadJob).jobStateLock) { threadJob.isWaiting = true; notifyWaitingThreadJobs(threadJob); ((InternalJob) threadJob).setWaitQueueStamp(manager.waitQueueCounter.increment()); } manager.enqueue(manager.waitingThreadJobs, threadJob); }
synchronized void addWaiting(ThreadJob threadJob) { synchronized (((InternalJob) threadJob).jobStateLock) { threadJob.isWaiting = true; notifyWaitingThreadJobs(threadJob); ((InternalJob) threadJob).setWaitQueueStamp(manager.waitQueueCounter.increment()); } manager.enqueue(manager.waitingThreadJobs, threadJob); }
synchronized void addWaiting(ThreadJob threadJob) { synchronized (((InternalJob) threadJob).jobStateLock) { threadJob.isWaiting = true; notifyWaitingThreadJobs(threadJob); ((InternalJob) threadJob).setWaitQueueStamp(manager.waitQueueCounter.increment()); } manager.enqueue(manager.waitingThreadJobs, threadJob); }
/** * Called when a worker thread has finished running a job. At this * point, the worker thread must not own any scheduling rules * @param lastJob The last job to run in this thread */ void endJob(InternalJob lastJob) { final Thread currentThread = Thread.currentThread(); IStatus error; synchronized (this) { ThreadJob threadJob = (ThreadJob) threadJobs.get(currentThread); if (threadJob == null) { if (lastJob.getRule() != null) notifyWaitingThreadJobs(); return; } String msg = "Worker thread ended job: " + lastJob + ", but still holds rule: " + threadJob; //$NON-NLS-1$ //$NON-NLS-2$ error = new Status(IStatus.ERROR, JobManager.PI_JOBS, 1, msg, null); //end the thread job endThreadJob(threadJob, false); } try { RuntimeLog.log(error); } catch (RuntimeException e) { //failed to log, so print to console instead System.err.println(error.getMessage()); } }
/** * Called when a worker thread has finished running a job. At this * point, the worker thread must not own any scheduling rules * @param lastJob The last job to run in this thread */ void endJob(InternalJob lastJob) { final Thread currentThread = Thread.currentThread(); IStatus error; synchronized (this) { ThreadJob threadJob = threadJobs.get(currentThread); if (threadJob == null) { if (lastJob.getRule() != null) notifyWaitingThreadJobs(lastJob); return; } String msg = "Worker thread ended job: " + lastJob + ", but still holds rule: " + threadJob; //$NON-NLS-1$ //$NON-NLS-2$ error = new Status(IStatus.ERROR, JobManager.PI_JOBS, 1, msg, null); //end the thread job endThreadJob(threadJob, false); } try { RuntimeLog.log(error); } catch (RuntimeException e) { //failed to log, so print to console instead System.err.println(error.getMessage()); } }
/** * Called when a worker thread has finished running a job. At this * point, the worker thread must not own any scheduling rules * @param lastJob The last job to run in this thread */ void endJob(InternalJob lastJob) { final Thread currentThread = Thread.currentThread(); IStatus error; synchronized (this) { ThreadJob threadJob = threadJobs.get(currentThread); if (threadJob == null) { if (lastJob.getRule() != null) notifyWaitingThreadJobs(lastJob); return; } String msg = "Worker thread ended job: " + lastJob + ", but still holds rule: " + threadJob; //$NON-NLS-1$ //$NON-NLS-2$ error = new Status(IStatus.ERROR, JobManager.PI_JOBS, 1, msg, null); //end the thread job endThreadJob(threadJob, false); } try { RuntimeLog.log(error); } catch (RuntimeException e) { //failed to log, so print to console instead System.err.println(error.getMessage()); } }
/** * Called when a worker thread has finished running a job. At this * point, the worker thread must not own any scheduling rules * @param lastJob The last job to run in this thread */ void endJob(InternalJob lastJob) { final Thread currentThread = Thread.currentThread(); IStatus error; synchronized (this) { ThreadJob threadJob = (ThreadJob) threadJobs.get(currentThread); if (threadJob == null) { if (lastJob.getRule() != null) notifyWaitingThreadJobs(lastJob); return; } String msg = "Worker thread ended job: " + lastJob + ", but still holds rule: " + threadJob; //$NON-NLS-1$ //$NON-NLS-2$ error = new Status(IStatus.ERROR, JobManager.PI_JOBS, 1, msg, null); //end the thread job endThreadJob(threadJob, false); } try { RuntimeLog.log(error); } catch (RuntimeException e) { //failed to log, so print to console instead System.err.println(error.getMessage()); } }
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); }
/** * 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); }