-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move clock functions into their own module
Just an effort to not pollute the top-level namespace too much. Putting these into their own module gives us a place to put future functions that also reveal information about the current execution.
- Loading branch information
1 parent
b781b1e
commit a63064a
Showing
6 changed files
with
62 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! Information about the current thread and current Shuttle execution. | ||
//! | ||
//! This module provides access to information about the current Shuttle execution. It is useful for | ||
//! building tools that need to exploit Shuttle's total ordering of concurrent operations; for | ||
//! example, a tool that wants to check linearizability might want access to a global timestamp for | ||
//! events, which the [`context_switches`] function provides. | ||
use crate::runtime::execution::ExecutionState; | ||
use crate::runtime::task::clock::VectorClock; | ||
use crate::runtime::task::TaskId; | ||
|
||
/// The number of context switches that happened so far in the current Shuttle execution. | ||
/// | ||
/// Note that this is the number of *possible* context switches, i.e., including times when the | ||
/// scheduler decided to continue with the same task. This means the result can be used as a | ||
/// timestamp for atomic actions during an execution. | ||
/// | ||
/// Panics if called outside of a Shuttle execution. | ||
pub fn context_switches() -> usize { | ||
ExecutionState::context_switches() | ||
} | ||
|
||
/// Get the current thread's vector clock | ||
pub fn clock() -> VectorClock { | ||
crate::runtime::execution::ExecutionState::with(|state| { | ||
let me = state.current(); | ||
state.get_clock(me.id()).clone() | ||
}) | ||
} | ||
|
||
/// Gets the clock for the thread with the given task ID | ||
pub fn clock_for(task_id: TaskId) -> VectorClock { | ||
ExecutionState::with(|state| state.get_clock(task_id).clone()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters