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 init:: PinInit ,
1111 pin_init,
@@ -123,7 +123,41 @@ unsafe impl<T: ?Sized + Send, B: Backend> Sync for Lock<T, B> {}
123123
124124impl < T , B : Backend > Lock < T , B > {
125125 /// Constructs a new lock initialiser.
126- pub fn new ( t : T , name : & ' static CStr , key : LockClassKey ) -> impl PinInit < Self > {
126+ #[ track_caller]
127+ pub fn new ( t : T ) -> impl PinInit < Self > {
128+ let ( key, name) = caller_lock_class ( ) ;
129+ Self :: new_with_key ( t, name, key)
130+ }
131+
132+ /// Constructs a new lock initialiser taking an initialiser/
133+ #[ track_caller]
134+ pub fn pin_init < E > ( t : impl PinInit < T , E > ) -> impl PinInit < Self , E >
135+ where
136+ E : core:: convert:: From < core:: convert:: Infallible > ,
137+ {
138+ let ( key, name) = caller_lock_class ( ) ;
139+ Self :: pin_init_with_key ( t, name, key)
140+ }
141+
142+ /// Constructs a new lock initialiser.
143+ #[ track_caller]
144+ pub fn new_named ( t : T , name : & ' static CStr ) -> impl PinInit < Self > {
145+ let ( key, _) = caller_lock_class ( ) ;
146+ Self :: new_with_key ( t, name, key)
147+ }
148+
149+ /// Constructs a new lock initialiser taking an initialiser/
150+ #[ track_caller]
151+ pub fn pin_init_named < E > ( t : impl PinInit < T , E > , name : & ' static CStr ) -> impl PinInit < Self , E >
152+ where
153+ E : core:: convert:: From < core:: convert:: Infallible > ,
154+ {
155+ let ( key, _) = caller_lock_class ( ) ;
156+ Self :: pin_init_with_key ( t, name, key)
157+ }
158+
159+ /// Constructs a new lock initialiser given a particular name and lock class key.
160+ pub fn new_with_key ( t : T , name : & ' static CStr , key : LockClassKey ) -> impl PinInit < Self > {
127161 pin_init ! ( Self {
128162 data: UnsafeCell :: new( t) ,
129163 _pin: PhantomPinned ,
@@ -135,8 +169,9 @@ impl<T, B: Backend> Lock<T, B> {
135169 } )
136170 }
137171
138- /// Constructs a new lock initialiser taking an initialiser.
139- pub fn pin_init < E > (
172+ /// Constructs a new lock initialiser taking an initialiser given a particular
173+ /// name and lock class key.
174+ pub fn pin_init_with_key < E > (
140175 t : impl PinInit < T , E > ,
141176 name : & ' static CStr ,
142177 key : LockClassKey ,
0 commit comments