@@ -52,7 +52,7 @@ impl<T> TryFrom<Arc<Mutex<Vec<T>>>> for DLPackTensor where T: GetDLPackDataType
5252 fn try_from ( array : Arc < Mutex < Vec < T > > > ) -> Result < DLPackTensor , Self :: Error > {
5353 let ctx = MutexCtxBuilder {
5454 array : array,
55- lock_builder : |array| { array. lock ( ) . expect ( "could not lock the mutex" ) } ,
55+ lock_builder : |array| { array. try_lock ( ) . expect ( "could not lock the mutex" ) } ,
5656 shape : Box :: new ( 0 ) ,
5757 stride : Box :: new ( 1 ) ,
5858 } ;
@@ -152,7 +152,7 @@ impl<T> TryFrom<ReadWrite<Arc<RwLock<Vec<T>>>>> for DLPackTensor where T: GetDLP
152152 fn try_from ( ReadWrite ( array) : ReadWrite < Arc < RwLock < Vec < T > > > > ) -> Result < DLPackTensor , Self :: Error > {
153153 let ctx = RwLockCtxWriteBuilder {
154154 array : array,
155- lock_builder : move |array| { array. write ( ) . expect ( "could not lock the rwlock" ) } ,
155+ lock_builder : move |array| { array. try_write ( ) . expect ( "could not lock the rwlock" ) } ,
156156 shape : Box :: new ( 0 ) ,
157157 stride : Box :: new ( 1 ) ,
158158 } ;
@@ -214,7 +214,7 @@ impl<T> TryFrom<ReadOnly<Arc<RwLock<Vec<T>>>>> for DLPackTensor where T: GetDLPa
214214 fn try_from ( ReadOnly ( array) : ReadOnly < Arc < RwLock < Vec < T > > > > ) -> Result < DLPackTensor , Self :: Error > {
215215 let ctx = RwLockCtxReadBuilder {
216216 array : array,
217- lock_builder : move |array| { array. read ( ) . expect ( "could not lock the rwlock" ) } ,
217+ lock_builder : move |array| { array. try_read ( ) . expect ( "could not lock the rwlock" ) } ,
218218 shape : Box :: new ( 0 ) ,
219219 stride : Box :: new ( 1 ) ,
220220 } ;
@@ -287,7 +287,7 @@ mod tests {
287287 slice[ 1 ] = 42 ;
288288 }
289289
290- let lock = data. lock ( ) . unwrap ( ) ;
290+ let lock = data. try_lock ( ) . unwrap ( ) ;
291291 assert_eq ! ( & * lock, & [ 1 , 42 , 3 ] ) ;
292292 }
293293
@@ -306,7 +306,7 @@ mod tests {
306306 slice[ 1 ] = 42 ;
307307 }
308308
309- let lock = data. read ( ) . unwrap ( ) ;
309+ let lock = data. try_read ( ) . unwrap ( ) ;
310310 assert_eq ! ( & * lock, & [ 1 , 42 , 3 ] ) ;
311311 }
312312
@@ -324,7 +324,7 @@ mod tests {
324324 assert_eq ! ( slice, & [ 1 , 2 , 3 ] ) ;
325325 }
326326
327- let lock = data. read ( ) . unwrap ( ) ;
327+ let lock = data. try_read ( ) . unwrap ( ) ;
328328 assert_eq ! ( & * lock, & [ 1 , 2 , 3 ] ) ;
329329 }
330330
0 commit comments