@@ -23,13 +23,13 @@ type Key = &'static LocalMutexNode;
2323/// See: [`try_lock_with_local_then`], [`lock_with_local_then`],
2424/// [`try_lock_with_local_then_unchecked`] or [`lock_with_local_then_unchecked`].
2525///
26- /// The thread local node definition generated by this macro avoids lazy
26+ /// The thread local node declaration generated by this macro avoids lazy
2727/// initialization and does not need to be dropped, which enables a more
2828/// efficient underlying implementation. See [`std::thread_local!`] macro.
2929///
3030/// # Sintax
3131///
32- /// * Allows multiple static definitions , must be separated with semicolons.
32+ /// * Allows multiple static declarations , must be separated with semicolons.
3333/// * Visibility is optional (private by default).
3434/// * Requires `static` keyword and a **UPPER_SNAKE_CASE** name.
3535///
@@ -38,15 +38,13 @@ type Key = &'static LocalMutexNode;
3838/// ```
3939/// use mcslock::raw::spins::Mutex;
4040///
41- /// // Multiple difenitions .
41+ /// // Multiple declarations allowed .
4242/// mcslock::thread_local_node! {
4343/// pub static NODE;
44- /// static OTHER_NODE1;
44+ /// static OTHER_NODE;
45+ /// // ...
4546/// }
4647///
47- /// // Single definition.
48- /// mcslock::thread_local_node!(pub static OTHER_NODE2);
49- ///
5048/// let mutex = Mutex::new(0);
5149/// // Keys are provided to APIs by reference.
5250/// mutex.lock_with_local_then(&NODE, |data| *data = 10);
@@ -63,14 +61,14 @@ type Key = &'static LocalMutexNode;
6361macro_rules! thread_local_node {
6462 // Empty (base for recursion).
6563 ( ) => { } ;
66- // Process multiply definitions (recursive).
64+ // Process multiple declarations (recursive).
6765 ( $vis: vis static $node: ident; $( $rest: tt) * ) => {
68- $crate:: __thread_local_node_inner!( $vis $node, raw) ;
69- $crate:: thread_local_node!( $( $rest) * ) ;
66+ $crate:: __thread_local_node_inner! { $vis $node, raw }
67+ $crate:: thread_local_node! { $( $rest) * }
7068 } ;
7169 // Process single declaration.
7270 ( $vis: vis static $node: ident) => {
73- $crate:: __thread_local_node_inner!( $vis $node, raw) ;
71+ $crate:: __thread_local_node_inner! { $vis $node, raw }
7472 } ;
7573}
7674
@@ -158,7 +156,7 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
158156 ///
159157 /// use mcslock::raw::spins::Mutex;
160158 ///
161- /// mcslock::thread_local_node!( static NODE);
159+ /// mcslock::thread_local_node! { static NODE }
162160 ///
163161 /// let mutex = Arc::new(Mutex::new(0));
164162 /// let c_mutex = Arc::clone(&mutex);
@@ -182,7 +180,7 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
182180 /// ```compile_fail,E0515
183181 /// use mcslock::raw::spins::Mutex;
184182 ///
185- /// mcslock::thread_local_node!( static NODE);
183+ /// mcslock::thread_local_node! { static NODE }
186184 ///
187185 /// let mutex = Mutex::new(1);
188186 /// let borrow = mutex.try_lock_with_local_then(&NODE, |data| &*data.unwrap());
@@ -194,7 +192,7 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
194192 #[ doc = concat ! ( "```should_panic(expected = " , already_borrowed_error!( ) , ")" ) ]
195193 /// use mcslock::raw::spins::Mutex;
196194 ///
197- /// mcslock::thread_local_node!( static NODE);
195+ /// mcslock::thread_local_node! { static NODE }
198196 ///
199197 /// let mutex = Mutex::new(0);
200198 ///
@@ -205,7 +203,7 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
205203 /// let mutex = Mutex::new(());
206204 /// mutex.try_lock_with_local_then(&NODE, |_data| ());
207205 /// });
208- /// ```
206+ # [ doc = " ```" ]
209207 #[ inline]
210208 #[ track_caller]
211209 pub fn try_lock_with_local_then < F , Ret > ( & self , node : Key , f : F ) -> Ret
@@ -250,7 +248,7 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
250248 ///
251249 /// use mcslock::raw::spins::Mutex;
252250 ///
253- /// mcslock::thread_local_node!( static NODE);
251+ /// mcslock::thread_local_node! { static NODE }
254252 ///
255253 /// let mutex = Arc::new(Mutex::new(0));
256254 /// let c_mutex = Arc::clone(&mutex);
@@ -274,11 +272,11 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
274272 /// ```compile_fail,E0515
275273 /// use mcslock::raw::spins::Mutex;
276274 ///
277- /// mcslock::thread_local_node!( static NODE);
275+ /// mcslock::thread_local_node! { static NODE }
278276 ///
279277 /// let mutex = Mutex::new(1);
280278 /// let data = unsafe {
281- /// mutex.try_lock_with_local_then_unchecked(&NODE, |g | &*g .unwrap())
279+ /// mutex.try_lock_with_local_then_unchecked(&NODE, |d | &*d .unwrap())
282280 /// };
283281 /// ```
284282 ///
@@ -288,7 +286,7 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
288286 /// ```no_run
289287 /// use mcslock::raw::spins::Mutex;
290288 ///
291- /// mcslock::thread_local_node!( static NODE);
289+ /// mcslock::thread_local_node! { static NODE }
292290 ///
293291 /// let mutex = Mutex::new(0);
294292 ///
@@ -339,7 +337,7 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
339337 ///
340338 /// use mcslock::raw::spins::Mutex;
341339 ///
342- /// mcslock::thread_local_node!( static NODE);
340+ /// mcslock::thread_local_node! { static NODE }
343341 ///
344342 /// let mutex = Arc::new(Mutex::new(0));
345343 /// let c_mutex = Arc::clone(&mutex);
@@ -357,7 +355,7 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
357355 /// ```compile_fail,E0515
358356 /// use mcslock::raw::spins::Mutex;
359357 ///
360- /// mcslock::thread_local_node!( static NODE);
358+ /// mcslock::thread_local_node! { static NODE }
361359 ///
362360 /// let mutex = Mutex::new(1);
363361 /// let borrow = mutex.lock_with_local_then(&NODE, |data| &*data);
@@ -369,7 +367,7 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
369367 #[ doc = concat ! ( "```should_panic(expected = " , already_borrowed_error!( ) , ")" ) ]
370368 /// use mcslock::raw::spins::Mutex;
371369 ///
372- /// mcslock::thread_local_node!( static NODE);
370+ /// mcslock::thread_local_node! { static NODE }
373371 ///
374372 /// let mutex = Mutex::new(0);
375373 ///
@@ -380,7 +378,7 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
380378 /// let mutex = Mutex::new(());
381379 /// mutex.lock_with_local_then(&NODE, |_data| ());
382380 /// });
383- /// ```
381+ # [ doc = " ```" ]
384382 #[ inline]
385383 #[ track_caller]
386384 pub fn lock_with_local_then < F , Ret > ( & self , node : Key , f : F ) -> Ret
@@ -424,7 +422,7 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
424422 ///
425423 /// use mcslock::raw::spins::Mutex;
426424 ///
427- /// mcslock::thread_local_node!( static NODE);
425+ /// mcslock::thread_local_node! { static NODE }
428426 ///
429427 /// let mutex = Arc::new(Mutex::new(0));
430428 /// let c_mutex = Arc::clone(&mutex);
@@ -442,7 +440,7 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
442440 /// ```compile_fail,E0515
443441 /// use mcslock::raw::spins::Mutex;
444442 ///
445- /// mcslock::thread_local_node!( static NODE);
443+ /// mcslock::thread_local_node! { static NODE }
446444 ///
447445 /// let mutex = Mutex::new(1);
448446 /// let data = unsafe {
@@ -456,7 +454,7 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
456454 /// ```no_run
457455 /// use mcslock::raw::spins::Mutex;
458456 ///
459- /// mcslock::thread_local_node!( static NODE);
457+ /// mcslock::thread_local_node!{ static NODE }
460458 ///
461459 /// let mutex = Mutex::new(0);
462460 ///
@@ -482,7 +480,8 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
482480 ///
483481 /// ```compile_fail
484482 /// use mcslock::raw::spins::Mutex;
485- /// mcslock::thread_local_node!(static NODE);
483+ ///
484+ /// mcslock::thread_local_node! { static NODE }
486485 ///
487486 /// let mutex = Mutex::new(1);
488487 /// let borrow = mutex.lock_with_local_then(&NODE, |data| data);
@@ -491,7 +490,8 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
491490 /// ```compile_fail,E0521
492491 /// use std::thread;
493492 /// use mcslock::raw::spins::Mutex;
494- /// mcslock::thread_local_node!(static NODE);
493+ ///
494+ /// mcslock::thread_local_node! { static NODE }
495495 ///
496496 /// let mutex = Mutex::new(1);
497497 /// mutex.lock_with_local_then(&NODE, |data| {
@@ -506,9 +506,11 @@ impl<T: ?Sized, R: Relax> Mutex<T, R> {
506506}
507507
508508// A thread local node definition used for testing.
509+ //
510+ // NOTE: Be mindfull of usage since it is a module global name.
509511#[ cfg( test) ]
510512#[ cfg( not( tarpaulin_include) ) ]
511- thread_local_node ! ( static TEST_NODE ) ;
513+ thread_local_node ! { static TEST_NODE }
512514
513515/// A Mutex wrapper type that calls `lock_with_local_then` and
514516/// `try_lock_with_local_then` when implementing testing traits.
@@ -598,8 +600,8 @@ impl<T: ?Sized, R: Relax> LockWithThen for MutexUnchecked<T, R> {
598600 where
599601 F : FnOnce ( & mut Self :: Target ) -> Ret ,
600602 {
601- // SAFETY: caller must guarantee that this thread local node is not
602- // already mutably borrowed for some other lock acquisition .
603+ // SAFETY: The thread local node is not borrowed to any other
604+ // locking operation for all duration of this call .
603605 unsafe { self . 0 . lock_with_local_then_unchecked ( & TEST_NODE , f) }
604606 }
605607}
@@ -610,8 +612,8 @@ impl<T: ?Sized, R: Relax> TryLockWithThen for MutexUnchecked<T, R> {
610612 where
611613 F : FnOnce ( Option < & mut Self :: Target > ) -> Ret ,
612614 {
613- // SAFETY: caller must guarantee that this thread local node is not
614- // already mutably borrowed for some other lock acquisition .
615+ // SAFETY: The thread local node is not borrowed to any other
616+ // locking operation for all duration of this call .
615617 unsafe { self . 0 . try_lock_with_local_then_unchecked ( & TEST_NODE , f) }
616618 }
617619
0 commit comments