When a thread is finished any task that is not finished is re-queued.

This commit is contained in:
Jason Travis Smith 2016-06-26 08:05:44 -04:00
parent 7bd5378500
commit 7492d3989e

View File

@ -1,5 +1,4 @@
use std::collections::binary_heap::BinaryHeap;
use std::vec::Drain;
use std::ops::DerefMut;
use std::sync::{Arc, Mutex};
use std::sync::mpsc::{Receiver, Sender, TryRecvError};
@ -83,6 +82,8 @@ impl ComputeThread
///
fn retrieve_task(&mut self)
{
let task: Option<Box<TaskStateMachine>>;
// There is nothing to do if this thread already
// has a task to work on.
if self.current_task.is_some() == true
@ -203,8 +204,11 @@ impl Thread for ComputeThread
ThreadState::Idle =>
{
let mut is_valid_task: bool;
// Check to see if we have a task.
if self.current_task.is_some() == true
is_valid_task = self.current_task.is_some();
if is_valid_task == true
{
// Why are we idling? We should not get here.
debug!("Thread is idling when it should be processing.");
@ -215,7 +219,8 @@ impl Thread for ComputeThread
// We need to check if there is a task that
// we should be processing.
self.retrieve_task();
if self.current_task.is_some() == true
is_valid_task = self.current_task.is_some();
if is_valid_task == true
{
// We got a new task to process,
// so switch to the Processing state.
@ -229,6 +234,7 @@ impl Thread for ComputeThread
ThreadState::Processing =>
{
let mut switch_to_idle: bool;
let mut is_task_finished: bool;
let mut has_spawned_children: bool;
let mut tasks: Vec<Box<TaskStateMachine>>;
@ -239,6 +245,7 @@ impl Thread for ComputeThread
// the current task we need to mark the action to take
// and then handle it outside of the match statement
// if it changes the current task.
switch_to_idle = false;
is_task_finished = false;
has_spawned_children = false;
match self.current_task
@ -265,10 +272,15 @@ impl Thread for ComputeThread
{
// Why are we processing? We should not get here.
debug!("Thread is processing when it should be idling.");
self.change_state(ThreadState::Idle);
switch_to_idle = true;
}
}
if switch_to_idle == true
{
self.change_state(ThreadState::Idle);
}
// If there are any sibling tasks that were
// spawned then add them to the queue.
if self.spawner.has_sibling_tasks() == true
@ -339,9 +351,8 @@ impl Thread for ComputeThread
// Also, if the thread is currently working on
// an unfinished task then we should requeue it.
task = self.current_task.take();
self.current_task = None;
/*
task = self.current_task;
match task
{
Some(old_task) =>
@ -356,7 +367,6 @@ impl Thread for ComputeThread
{
}
}
*/
}
}