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,
@@ -131,7 +131,41 @@ unsafe impl<T: ?Sized + Send, B: Backend> Sync for Lock<T, B> {}
131131
132132impl < T , B : Backend > Lock < T , B > {
133133 /// Constructs a new lock initialiser.
134- pub fn new ( t : T , name : & ' static CStr , key : LockClassKey ) -> impl PinInit < Self > {
134+ #[ track_caller]
135+ pub fn new ( t : T ) -> impl PinInit < Self > {
136+ let ( key, name) = caller_lock_class ( ) ;
137+ Self :: new_with_key ( t, name, key)
138+ }
139+
140+ /// Constructs a new lock initialiser taking an initialiser/
141+ #[ track_caller]
142+ pub fn pin_init < E > ( t : impl PinInit < T , E > ) -> impl PinInit < Self , E >
143+ where
144+ E : core:: convert:: From < core:: convert:: Infallible > ,
145+ {
146+ let ( key, name) = caller_lock_class ( ) ;
147+ Self :: pin_init_with_key ( t, name, key)
148+ }
149+
150+ /// Constructs a new lock initialiser.
151+ #[ track_caller]
152+ pub fn new_named ( t : T , name : & ' static CStr ) -> impl PinInit < Self > {
153+ let ( key, _) = caller_lock_class ( ) ;
154+ Self :: new_with_key ( t, name, key)
155+ }
156+
157+ /// Constructs a new lock initialiser taking an initialiser/
158+ #[ track_caller]
159+ pub fn pin_init_named < E > ( t : impl PinInit < T , E > , name : & ' static CStr ) -> impl PinInit < Self , E >
160+ where
161+ E : core:: convert:: From < core:: convert:: Infallible > ,
162+ {
163+ let ( key, _) = caller_lock_class ( ) ;
164+ Self :: pin_init_with_key ( t, name, key)
165+ }
166+
167+ /// Constructs a new lock initialiser given a particular name and lock class key.
168+ pub fn new_with_key ( t : T , name : & ' static CStr , key : LockClassKey ) -> impl PinInit < Self > {
135169 pin_init ! ( Self {
136170 data: UnsafeCell :: new( t) ,
137171 _pin: PhantomPinned ,
@@ -143,8 +177,9 @@ impl<T, B: Backend> Lock<T, B> {
143177 } )
144178 }
145179
146- /// Constructs a new lock initialiser taking an initialiser.
147- pub fn pin_init < E > (
180+ /// Constructs a new lock initialiser taking an initialiser given a particular
181+ /// name and lock class key.
182+ pub fn pin_init_with_key < E > (
148183 t : impl PinInit < T , E > ,
149184 name : & ' static CStr ,
150185 key : LockClassKey ,
0 commit comments