11//! Types related to the PHP executor, sapi and process globals.
22
3+ #[ cfg( php_zts) ]
4+ use parking_lot:: lock_api;
35use parking_lot:: { ArcRwLockReadGuard , ArcRwLockWriteGuard , RawRwLock , RwLock } ;
46use std:: collections:: HashMap ;
57use std:: ffi:: CStr ;
@@ -47,6 +49,7 @@ impl ExecutorGlobals {
4749 /// # Panics
4850 ///
4951 /// * If static executor globals are not set
52+ #[ must_use]
5053 pub fn get ( ) -> GlobalReadGuard < Self > {
5154 // SAFETY: PHP executor globals are statically declared therefore should never
5255 // return an invalid pointer.
@@ -55,7 +58,7 @@ impl ExecutorGlobals {
5558
5659 cfg_if:: cfg_if! {
5760 if #[ cfg( php_zts) ] {
58- let guard = lock:: GLOBALS_LOCK . with( |l| l . read_arc( ) ) ;
61+ let guard = lock:: GLOBALS_LOCK . with( lock_api :: RwLock :: read_arc) ;
5962 } else {
6063 let guard = lock:: GLOBALS_LOCK . read_arc( ) ;
6164 }
@@ -75,6 +78,7 @@ impl ExecutorGlobals {
7578 /// # Panics
7679 ///
7780 /// * If static executor globals are not set
81+ #[ must_use]
7882 pub fn get_mut ( ) -> GlobalWriteGuard < Self > {
7983 // SAFETY: PHP executor globals are statically declared therefore should never
8084 // return an invalid pointer.
@@ -83,7 +87,7 @@ impl ExecutorGlobals {
8387
8488 cfg_if:: cfg_if! {
8589 if #[ cfg( php_zts) ] {
86- let guard = lock:: GLOBALS_LOCK . with( |l| l . write_arc( ) ) ;
90+ let guard = lock:: GLOBALS_LOCK . with( parking_lot :: lock_api :: RwLock :: write_arc) ;
8791 } else {
8892 let guard = lock:: GLOBALS_LOCK . write_arc( ) ;
8993 }
@@ -237,6 +241,7 @@ impl CompilerGlobals {
237241 /// # Panics
238242 ///
239243 /// * If static executor globals are not set
244+ #[ must_use]
240245 pub fn get ( ) -> GlobalReadGuard < Self > {
241246 // SAFETY: PHP compiler globals are statically declared therefore should never
242247 // return an invalid pointer.
@@ -245,7 +250,7 @@ impl CompilerGlobals {
245250
246251 cfg_if:: cfg_if! {
247252 if #[ cfg( php_zts) ] {
248- let guard = lock:: GLOBALS_LOCK . with( |l| l . read_arc( ) ) ;
253+ let guard = lock:: GLOBALS_LOCK . with( lock_api :: RwLock :: read_arc) ;
249254 } else {
250255 let guard = lock:: GLOBALS_LOCK . read_arc( ) ;
251256 }
@@ -265,6 +270,7 @@ impl CompilerGlobals {
265270 /// # Panics
266271 ///
267272 /// * If static compiler globals are not set
273+ #[ must_use]
268274 pub fn get_mut ( ) -> GlobalWriteGuard < Self > {
269275 // SAFETY: PHP compiler globals are statically declared therefore should never
270276 // return an invalid pointer.
@@ -273,7 +279,7 @@ impl CompilerGlobals {
273279
274280 cfg_if:: cfg_if! {
275281 if #[ cfg( php_zts) ] {
276- let guard = lock:: GLOBALS_LOCK . with( |l| l . write_arc( ) ) ;
282+ let guard = lock:: GLOBALS_LOCK . with( parking_lot :: lock_api :: RwLock :: write_arc) ;
277283 } else {
278284 let guard = lock:: GLOBALS_LOCK . write_arc( ) ;
279285 }
@@ -339,14 +345,15 @@ impl ProcessGlobals {
339345 /// Attempting to retrieve the globals while already holding the global
340346 /// guard will lead to a deadlock. Dropping the globals guard will release
341347 /// the lock.
348+ #[ must_use]
342349 pub fn get ( ) -> GlobalReadGuard < Self > {
343350 // SAFETY: PHP executor globals are statically declared therefore should never
344351 // return an invalid pointer.
345352 let globals = unsafe { & * ext_php_rs_process_globals ( ) } ;
346353
347354 cfg_if:: cfg_if! {
348355 if #[ cfg( php_zts) ] {
349- let guard = lock:: PROCESS_GLOBALS_LOCK . with( |l| l . read_arc( ) ) ;
356+ let guard = lock:: PROCESS_GLOBALS_LOCK . with( lock_api :: RwLock :: read_arc) ;
350357 } else {
351358 let guard = lock:: PROCESS_GLOBALS_LOCK . read_arc( ) ;
352359 }
@@ -362,14 +369,15 @@ impl ProcessGlobals {
362369 /// Attempting to retrieve the globals while already holding the global
363370 /// guard will lead to a deadlock. Dropping the globals guard will release
364371 /// the lock.
372+ #[ must_use]
365373 pub fn get_mut ( ) -> GlobalWriteGuard < Self > {
366374 // SAFETY: PHP executor globals are statically declared therefore should never
367375 // return an invalid pointer.
368376 let globals = unsafe { & mut * ext_php_rs_process_globals ( ) } ;
369377
370378 cfg_if:: cfg_if! {
371379 if #[ cfg( php_zts) ] {
372- let guard = lock:: PROCESS_GLOBALS_LOCK . with( |l| l . write_arc( ) ) ;
380+ let guard = lock:: PROCESS_GLOBALS_LOCK . with( parking_lot :: lock_api :: RwLock :: write_arc) ;
373381 } else {
374382 let guard = lock:: PROCESS_GLOBALS_LOCK . write_arc( ) ;
375383 }
@@ -506,14 +514,15 @@ impl SapiGlobals {
506514 /// Attempting to retrieve the globals while already holding the global
507515 /// guard will lead to a deadlock. Dropping the globals guard will release
508516 /// the lock.
517+ #[ must_use]
509518 pub fn get ( ) -> GlobalReadGuard < Self > {
510519 // SAFETY: PHP executor globals are statically declared therefore should never
511520 // return an invalid pointer.
512521 let globals = unsafe { & * ext_php_rs_sapi_globals ( ) } ;
513522
514523 cfg_if:: cfg_if! {
515524 if #[ cfg( php_zts) ] {
516- let guard = lock:: SAPI_GLOBALS_LOCK . with( |l| l . read_arc( ) ) ;
525+ let guard = lock:: SAPI_GLOBALS_LOCK . with( lock_api :: RwLock :: read_arc) ;
517526 } else {
518527 let guard = lock:: SAPI_GLOBALS_LOCK . read_arc( ) ;
519528 }
@@ -529,14 +538,15 @@ impl SapiGlobals {
529538 /// Attempting to retrieve the globals while already holding the global
530539 /// guard will lead to a deadlock. Dropping the globals guard will release
531540 /// the lock.
541+ #[ must_use]
532542 pub fn get_mut ( ) -> GlobalWriteGuard < Self > {
533543 // SAFETY: PHP executor globals are statically declared therefore should never
534544 // return an invalid pointer.
535545 let globals = unsafe { & mut * ext_php_rs_sapi_globals ( ) } ;
536546
537547 cfg_if:: cfg_if! {
538548 if #[ cfg( php_zts) ] {
539- let guard = lock:: SAPI_GLOBALS_LOCK . with( |l| l . write_arc( ) ) ;
549+ let guard = lock:: SAPI_GLOBALS_LOCK . with( parking_lot :: lock_api :: RwLock :: write_arc) ;
540550 } else {
541551 let guard = lock:: SAPI_GLOBALS_LOCK . write_arc( ) ;
542552 }
@@ -769,6 +779,7 @@ impl FileGlobals {
769779 /// # Panics
770780 ///
771781 /// * If static file globals are not set
782+ #[ must_use]
772783 pub fn get ( ) -> GlobalReadGuard < Self > {
773784 // SAFETY: PHP executor globals are statically declared therefore should never
774785 // return an invalid pointer.
@@ -777,7 +788,7 @@ impl FileGlobals {
777788
778789 cfg_if:: cfg_if! {
779790 if #[ cfg( php_zts) ] {
780- let guard = lock:: FILE_GLOBALS_LOCK . with( |l| l . read_arc( ) ) ;
791+ let guard = lock:: FILE_GLOBALS_LOCK . with( lock_api :: RwLock :: read_arc) ;
781792 } else {
782793 let guard = lock:: FILE_GLOBALS_LOCK . read_arc( ) ;
783794 }
@@ -793,14 +804,15 @@ impl FileGlobals {
793804 /// Attempting to retrieve the globals while already holding the global
794805 /// guard will lead to a deadlock. Dropping the globals guard will release
795806 /// the lock.
807+ #[ must_use]
796808 pub fn get_mut ( ) -> GlobalWriteGuard < Self > {
797809 // SAFETY: PHP executor globals are statically declared therefore should never
798810 // return an invalid pointer.
799811 let globals = unsafe { & mut * ext_php_rs_file_globals ( ) } ;
800812
801813 cfg_if:: cfg_if! {
802814 if #[ cfg( php_zts) ] {
803- let guard = lock:: FILE_GLOBALS_LOCK . with( |l| l . write_arc( ) ) ;
815+ let guard = lock:: FILE_GLOBALS_LOCK . with( parking_lot :: lock_api :: RwLock :: write_arc) ;
804816 } else {
805817 let guard = lock:: FILE_GLOBALS_LOCK . write_arc( ) ;
806818 }
0 commit comments