/// <summary> /// Enqueue a job for execution. /// </summary> /// <param name="job">The job.</param> public void Enqueue(Job job) { lock (this.queueLock) { this.queue.Enqueue(job); } this.jobQueuedEvent.Set(); }
/// <summary> /// Moves the owner queues of a job forward. This means each queue is stepped to the job after this one. /// </summary> /// <param name="job">The job.</param> private void MoveToNextJob(Job job) { if (job is MasterJob) { this.queuesLock.Enter(); try { this.masterQueueJobs.Remove(job); } finally { this.queuesLock.Exit(); } } foreach (JobQueue owner in job.GetOwners()) { owner.MoveNext(); } }
/// <summary> /// Handle a job pending execution. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="job">The job.</param> private void Job_IsPendingChanged(object sender, Job job) { if (job.IsPending) { if (!job.IsSkipRequested) { // Enqueue this job to be executed this.jobPool.Enqueue(job); } else { // Skip the job by moving each owner queue forward this.MoveToNextJob(job); } } }
/// <summary> /// Handle a job entering the completed state. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="job">The job.</param> private void Job_Completed(object sender, Job job) { this.MoveToNextJob(job); }
/// <summary> /// Enqueues a job. /// </summary> /// <param name="job">The job.</param> public void Enqueue(Job job) { bool jobIsPending; this.queueLock.Enter(); try { if (this.pendingJob != null) { this.queue.Enqueue(job); jobIsPending = false; } else { this.pendingJob = job; jobIsPending = true; } } finally { this.queueLock.Exit(); } // Indicate to the job that this queue is pending. If this queue is the last to pend, enqueue for execution if (jobIsPending) { job.IncrementPendingQueues(this.FlaggedForRemoval); } }
/// <summary> /// Moves to the next job in the queue. /// </summary> public void MoveNext() { Job nextJob; this.queueLock.Enter(); try { if (this.queue.Count > 0) { nextJob = this.pendingJob = this.queue.Dequeue(); } else { nextJob = this.pendingJob = null; } } finally { this.queueLock.Exit(); } if (nextJob != null) { // Indicate to the job that this queue is pending nextJob.IncrementPendingQueues(this.FlaggedForRemoval); } else { // The queue is now idle if (this.Idle != null) { this.Idle(this, this); } } }