Skip to main content

task/manager/
relationships.rs

1// Relationships module - handles parent/child relationships between tasks
2
3use alloc::vec::Vec;
4
5use super::*;
6
7impl Manager {
8    /// Number of currently registered tasks, including the root task.
9    ///
10    /// This is an instantaneous registry count, not a CPU utilization measure.
11    /// It does not allocate or traverse task relationships.
12    pub async fn get_task_count(&self) -> usize {
13        self.0.read().await.tasks.len()
14    }
15
16    /// Get the children tasks of a task.
17    pub async fn get_children(
18        &self,
19        task_identifier: TaskIdentifier,
20    ) -> Result<Vec<TaskIdentifier>> {
21        Ok(self
22            .0
23            .read()
24            .await
25            .tasks
26            .iter()
27            .filter(|(_, metadata)| metadata.parent == task_identifier)
28            .map(|(identifier, _)| *identifier)
29            .collect())
30    }
31
32    /// Get the parent task of a task.
33    pub async fn get_parent(&self, task_identifier: TaskIdentifier) -> Result<TaskIdentifier> {
34        Self::get_task(&*self.0.read().await, task_identifier).map(|task| task.parent)
35    }
36}