@@ -1504,6 +1504,63 @@ mod tests {
15041504 } ) ;
15051505 }
15061506
1507+ #[ cfg( feature = "macros" ) ]
1508+ #[ cfg( all(
1509+ any( feature = "parking_lot" , feature = "lock_api" ) ,
1510+ not( target_arch = "wasm32" ) // We are building wasm Python with pthreads disabled
1511+ ) ) ]
1512+ #[ test]
1513+ fn test_parking_lot_rwlock_ext ( ) {
1514+ macro_rules! test_rwlock {
1515+ ( $write_guard: ty, $read_guard: ty, $rwlock: stmt) => { {
1516+ let barrier = Barrier :: new( 2 ) ;
1517+
1518+ let rwlock = Python :: attach( { $rwlock } ) ;
1519+
1520+ std:: thread:: scope( |s| {
1521+ s. spawn( || {
1522+ Python :: attach( |py| {
1523+ let b: $write_guard = rwlock. write_py_attached( py) ;
1524+ barrier. wait( ) ;
1525+ // sleep to ensure the other thread actually blocks
1526+ std:: thread:: sleep( std:: time:: Duration :: from_millis( 10 ) ) ;
1527+ ( * b) . bind( py) . borrow( ) . 0 . store( true , Ordering :: Release ) ;
1528+ drop( b) ;
1529+ } ) ;
1530+ } ) ;
1531+ s. spawn( || {
1532+ barrier. wait( ) ;
1533+ Python :: attach( |py| {
1534+ // blocks until the other thread releases the lock
1535+ let b: $read_guard = rwlock. read_py_attached( py) ;
1536+ assert!( ( * b) . bind( py) . borrow( ) . 0 . load( Ordering :: Acquire ) ) ;
1537+ } ) ;
1538+ } ) ;
1539+ } ) ;
1540+ } } ;
1541+ }
1542+
1543+ test_rwlock ! (
1544+ parking_lot:: RwLockWriteGuard <' _, _>,
1545+ parking_lot:: RwLockReadGuard <' _, _>,
1546+ |py| {
1547+ parking_lot:: RwLock :: new( Py :: new( py, BoolWrapper ( AtomicBool :: new( false ) ) ) . unwrap( ) )
1548+ }
1549+ ) ;
1550+
1551+ #[ cfg( feature = "arc_lock" ) ]
1552+ test_rwlock ! (
1553+ parking_lot:: ArcRwLockWriteGuard <_, _>,
1554+ parking_lot:: ArcRwLockReadGuard <_, _>,
1555+ |py| {
1556+ let rwlock = parking_lot:: RwLock :: new(
1557+ Py :: new( py, BoolWrapper ( AtomicBool :: new( false ) ) ) . unwrap( ) ,
1558+ ) ;
1559+ std:: sync:: Arc :: new( rwlock)
1560+ }
1561+ ) ;
1562+ }
1563+
15071564 #[ cfg( not( target_arch = "wasm32" ) ) ] // We are building wasm Python with pthreads disabled
15081565 #[ test]
15091566 fn test_rwlock_ext_poison ( ) {
0 commit comments