Skip to content

Commit

Permalink
fix: remove excess task_name/tid clones for ExecState
Browse files Browse the repository at this point in the history
Signed-off-by: Amin Yahyaabadi <aminyahyaabadi74@gmail.com>
  • Loading branch information
aminya committed Dec 6, 2023
1 parent ead26c5 commit 4365997
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
7 changes: 3 additions & 4 deletions src/engine/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,10 @@ impl Dag {
/// - Create a graph from task dependencies.
/// - Generate task heart sequence according to topological sorting of graph.
pub(crate) fn init(&mut self) -> Result<(), DagError> {
self.execute_states.reserve(self.tasks.len());
self.tasks.values().for_each(|task| {
self.execute_states.insert(
task.id(),
Arc::new(ExecState::new(task.id(), task.name().to_string())),
);
self.execute_states
.insert(task.id(), Arc::new(ExecState::new()));
});

self.create_graph()?;
Expand Down
26 changes: 2 additions & 24 deletions src/task/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ pub(crate) struct ExecState {
success: AtomicBool,
/// Output produced by a task.
output: AtomicPtr<Output>,
/// Task output identified by id.
tid: usize,
task_name: String,
/// The semaphore is used to control the synchronous blocking of subsequent tasks to obtain the
/// execution results of this task.
/// When a task is successfully executed, the permits inside the semaphore will be increased to
Expand All @@ -105,15 +102,13 @@ pub enum Output {
#[derive(Debug)]
pub struct Input(Vec<Content>);

#[allow(dead_code)]
impl ExecState {
/// Construct a new [`ExeState`].
pub(crate) fn new(task_id: usize, task_name: String) -> Self {
pub(crate) fn new() -> Self {
// initialize the task to failure without output.
Self {
success: AtomicBool::new(false),
output: AtomicPtr::new(std::ptr::null_mut()),
tid: task_id,
task_name,
semaphore: Semaphore::new(0),
}
}
Expand Down Expand Up @@ -145,23 +140,6 @@ impl ExecState {
self.success.store(true, Ordering::Relaxed)
}

pub(crate) fn get_err(&self) -> Option<String> {
if let Some(out) = unsafe { self.output.load(Ordering::Relaxed).as_ref() } {
out.get_err()
} else {
None
}
}

/// Use id to indicate the output of which task.
pub(crate) fn tid(&self) -> usize {
self.tid
}

pub(crate) fn task_name(&self) -> &str {
&self.task_name
}

/// The semaphore is used to control the synchronous acquisition of task output results.
/// Under normal circumstances, first use the semaphore to obtain a permit, and then call
/// the `get_output` function to obtain the output. If the current task is not completed
Expand Down

0 comments on commit 4365997

Please sign in to comment.