55//! It contains a generic Rust lock and guard that allow for different backends (e.g., mutexes,
66//! spinlocks, raw spinlocks) to be provided with minimal effort.
77
8- use super :: LockClassKey ;
8+ use super :: { lockdep :: caller_lock_class , LockClassKey } ;
99use crate :: {
1010 bindings, init:: PinInit , pin_init, str:: CStr , try_pin_init, types:: Opaque , types:: ScopeGuard ,
1111} ;
@@ -103,7 +103,40 @@ unsafe impl<T: ?Sized + Send, B: Backend> Sync for Lock<T, B> {}
103103impl < T , B : Backend > Lock < T , B > {
104104 /// Constructs a new lock initialiser.
105105 #[ allow( clippy:: new_ret_no_self) ]
106- pub fn new ( t : T , name : & ' static CStr , key : LockClassKey ) -> impl PinInit < Self > {
106+ #[ track_caller]
107+ pub fn new ( t : T ) -> impl PinInit < Self > {
108+ let ( key, name) = caller_lock_class ( ) ;
109+ Self :: new_with_key ( t, name, key)
110+ }
111+
112+ /// Constructs a new lock initialiser taking an initialiser/
113+ pub fn pin_init < E > ( t : impl PinInit < T , E > ) -> impl PinInit < Self , E >
114+ where
115+ E : core:: convert:: From < core:: convert:: Infallible > ,
116+ {
117+ let ( key, name) = caller_lock_class ( ) ;
118+ Self :: pin_init_with_key ( t, name, key)
119+ }
120+
121+ /// Constructs a new lock initialiser.
122+ #[ allow( clippy:: new_ret_no_self) ]
123+ #[ track_caller]
124+ pub fn new_named ( t : T , name : & ' static CStr ) -> impl PinInit < Self > {
125+ let ( key, _) = caller_lock_class ( ) ;
126+ Self :: new_with_key ( t, name, key)
127+ }
128+
129+ /// Constructs a new lock initialiser taking an initialiser/
130+ pub fn pin_init_named < E > ( t : impl PinInit < T , E > , name : & ' static CStr ) -> impl PinInit < Self , E >
131+ where
132+ E : core:: convert:: From < core:: convert:: Infallible > ,
133+ {
134+ let ( key, _) = caller_lock_class ( ) ;
135+ Self :: pin_init_with_key ( t, name, key)
136+ }
137+
138+ /// Constructs a new lock initialiser given a particular name and lock class key.
139+ pub fn new_with_key ( t : T , name : & ' static CStr , key : LockClassKey ) -> impl PinInit < Self > {
107140 pin_init ! ( Self {
108141 data: UnsafeCell :: new( t) ,
109142 _pin: PhantomPinned ,
@@ -115,8 +148,9 @@ impl<T, B: Backend> Lock<T, B> {
115148 } )
116149 }
117150
118- /// Constructs a new lock initialiser taking an initialiser.
119- pub fn pin_init < E > (
151+ /// Constructs a new lock initialiser taking an initialiser given a particular
152+ /// name and lock class key.
153+ pub fn pin_init_with_key < E > (
120154 t : impl PinInit < T , E > ,
121155 name : & ' static CStr ,
122156 key : LockClassKey ,
0 commit comments