Skip to content

Commit 3002f98

Browse files
Improve CriticalSection docs
1 parent 7420011 commit 3002f98

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use core::marker::PhantomData;
99

1010
/// Critical section token.
1111
///
12-
/// Indicates that you are executing code within a critical section.
12+
/// An instance of this type indicates that the current core is executing code within a critical
13+
/// section. This means that no interrupts must be enabled that could preempt the currently running
14+
/// code.
1315
#[derive(Clone, Copy)]
1416
pub struct CriticalSection<'cs> {
1517
_0: PhantomData<&'cs ()>,
@@ -18,8 +20,17 @@ pub struct CriticalSection<'cs> {
1820
impl<'cs> CriticalSection<'cs> {
1921
/// Creates a critical section token.
2022
///
21-
/// This method is meant to be used to create safe abstractions rather than
22-
/// meant to be directly used in applications.
23+
/// This method is meant to be used to create safe abstractions rather than being directly used
24+
/// in applications.
25+
///
26+
/// # Safety
27+
///
28+
/// This must only be called when the current core is in a critical section. The caller must
29+
/// ensure that the returned instance will not live beyond the end of the critical section.
30+
///
31+
/// Note that the lifetime `'cs` of the returned instance is unconstrained. User code must not
32+
/// be able to influence the lifetime picked for this type, since that might cause it to be
33+
/// inferred to `'static`.
2334
#[inline(always)]
2435
pub unsafe fn new() -> Self {
2536
CriticalSection { _0: PhantomData }

0 commit comments

Comments
 (0)