Skip to content

Commit 0b6ccec

Browse files
committed
tweak docs a little
1 parent 342a2b6 commit 0b6ccec

File tree

2 files changed

+19
-35
lines changed

2 files changed

+19
-35
lines changed

src/tools/miri/src/concurrency/thread.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::concurrency::data_race;
1919
use crate::shims::tls;
2020
use crate::*;
2121

22-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
22+
#[derive(Clone, Copy, Debug, PartialEq)]
2323
enum SchedulingAction {
2424
/// Execute step on the active thread.
2525
ExecuteStep,
@@ -30,6 +30,7 @@ enum SchedulingAction {
3030
}
3131

3232
/// What to do with TLS allocations from terminated threads
33+
#[derive(Clone, Copy, Debug, PartialEq)]
3334
pub enum TlsAllocAction {
3435
/// Deallocate backing memory of thread-local statics as usual
3536
Deallocate,
@@ -39,15 +40,16 @@ pub enum TlsAllocAction {
3940
}
4041

4142
/// The argument type for the "unblock" callback, indicating why the thread got unblocked.
42-
#[derive(Debug, PartialEq)]
43+
#[derive(Clone, Copy, Debug, PartialEq)]
4344
pub enum UnblockKind {
4445
/// Operation completed successfully, thread continues normal execution.
4546
Ready,
4647
/// The operation did not complete within its specified duration.
4748
TimedOut,
4849
}
4950

50-
/// Type alias for unblock callbacks using UnblockKind argument.
51+
/// Type alias for unblock callbacks, i.e. machine callbacks invoked when
52+
/// a thread gets unblocked.
5153
pub type DynUnblockCallback<'tcx> = DynMachineCallback<'tcx, UnblockKind>;
5254

5355
/// A thread identifier.

src/tools/miri/src/machine.rs

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,44 +1737,26 @@ pub trait MachineCallback<'tcx, T>: VisitProvenance {
17371737
/// Type alias for boxed machine callbacks with generic argument type.
17381738
pub type DynMachineCallback<'tcx, T> = Box<dyn MachineCallback<'tcx, T> + 'tcx>;
17391739

1740-
/// Creates a callback for blocking operations with captured state.
1740+
/// Creates a `DynMachineCallback`:
17411741
///
1742-
/// When a thread blocks on a resource (as defined in `enum BlockReason`), this callback
1743-
/// executes once that resource becomes available. The callback captures needed
1744-
/// variables and handles the completion of the blocking operation.
1745-
///
1746-
/// # Example
17471742
/// ```rust
1748-
/// // Block thread until mutex is available
1749-
/// this.block_thread(
1750-
/// BlockReason::Mutex,
1751-
/// None,
1752-
/// callback!(
1753-
/// @capture<'tcx> {
1754-
/// mutex_ref: MutexRef,
1755-
/// retval: Scalar,
1756-
/// dest: MPlaceTy<'tcx>,
1757-
/// }
1758-
/// |this, unblock: UnblockKind| {
1759-
/// // Verify successful mutex acquisition
1760-
/// assert_eq!(unblock, UnblockKind::Ready);
1761-
///
1762-
/// // Enter critical section
1763-
/// this.mutex_lock(&mutex_ref);
1764-
///
1765-
/// // Process protected data and store result
1766-
/// this.write_scalar(retval, &dest)?;
1767-
///
1768-
/// // Exit critical section implicitly when callback completes
1769-
/// interp_ok(())
1770-
/// }
1771-
/// ),
1772-
/// );
1743+
/// callback!(
1744+
/// @capture<'tcx> {
1745+
/// var1: Ty1,
1746+
/// var2: Ty2<'tcx>,
1747+
/// }
1748+
/// |this, arg: ArgTy| {
1749+
/// // Implement the callback here.
1750+
/// todo!()
1751+
/// }
1752+
/// )
17731753
/// ```
1754+
///
1755+
/// All the argument types must implement `VisitProvenance`.
17741756
#[macro_export]
17751757
macro_rules! callback {
17761758
(@capture<$tcx:lifetime $(,)? $($lft:lifetime),*>
1777-
{ $($name:ident: $type:ty),* $(,)? }
1759+
{ $($name:ident: $type:ty),* $(,)? }
17781760
|$this:ident, $arg:ident: $arg_ty:ty| $body:expr $(,)?) => {{
17791761
struct Callback<$tcx, $($lft),*> {
17801762
$($name: $type,)*

0 commit comments

Comments
 (0)