#[allow(deprecated)]
use crate::runtime::execution::TASK_ID_TO_TAGS;
use crate::runtime::execution::{ExecutionState, LABELS};
use crate::runtime::task::clock::VectorClock;
pub use crate::runtime::task::labels::Labels;
pub use crate::runtime::task::{ChildLabelFn, TaskId, TaskName};
#[allow(deprecated)]
pub use crate::runtime::task::{Tag, Taggable};
use std::fmt::Debug;
use std::sync::Arc;
pub fn context_switches() -> usize {
ExecutionState::context_switches()
}
pub fn clock() -> VectorClock {
ExecutionState::with(|state| {
let me = state.current();
state.get_clock(me.id()).clone()
})
}
pub fn clock_for(task_id: TaskId) -> VectorClock {
ExecutionState::with(|state| state.get_clock(task_id).clone())
}
pub fn with_labels_for_task<F, T>(task_id: TaskId, f: F) -> T
where
F: FnOnce(&mut Labels) -> T,
{
LABELS.with(|cell| {
let mut map = cell.borrow_mut();
let m = map.entry(task_id).or_default();
f(m)
})
}
pub fn get_label_for_task<T: Clone + Debug + 'static>(task_id: TaskId) -> Option<T> {
with_labels_for_task(task_id, |labels| labels.get().cloned())
}
pub fn set_label_for_task<T: Clone + Debug + 'static>(task_id: TaskId, value: T) -> Option<T> {
with_labels_for_task(task_id, |labels| labels.insert(value))
}
pub fn remove_label_for_task<T: Clone + Debug + 'static>(task_id: TaskId) -> Option<T> {
with_labels_for_task(task_id, |labels| labels.remove())
}
pub fn get_name_for_task(task_id: TaskId) -> Option<TaskName> {
get_label_for_task::<TaskName>(task_id)
}
pub fn set_name_for_task(task_id: TaskId, task_name: impl Into<TaskName>) -> Option<TaskName> {
let task_name = task_name.into();
crate::annotations::record_name_for_task(task_id, &task_name);
set_label_for_task::<TaskName>(task_id, task_name)
}
pub fn get_current_task() -> Option<TaskId> {
ExecutionState::with(|s| Some(s.try_current()?.id()))
}
pub fn me() -> TaskId {
get_current_task().unwrap()
}
pub fn reset_step_count() {
ExecutionState::with(|s| s.steps_reset_at = s.current_schedule.len());
}
#[deprecated]
#[allow(deprecated)]
pub fn set_tag_for_current_task(tag: Arc<dyn Tag>) -> Option<Arc<dyn Tag>> {
ExecutionState::set_tag_for_current_task(tag)
}
#[deprecated]
#[allow(deprecated)]
pub fn get_tag_for_current_task() -> Option<Arc<dyn Tag>> {
ExecutionState::get_tag_for_current_task()
}
#[deprecated]
#[allow(deprecated)]
pub fn get_tag_for_task(task_id: TaskId) -> Option<Arc<dyn Tag>> {
TASK_ID_TO_TAGS.with(|cell| {
let map = cell.borrow();
map.get(&task_id).cloned()
})
}
#[deprecated]
#[allow(deprecated)]
pub fn set_tag_for_task(task: TaskId, tag: Arc<dyn Tag>) -> Option<Arc<dyn Tag>> {
ExecutionState::set_tag_for_task(task, tag)
}