@@ -4,10 +4,7 @@ use crate::stdlib::{
44 fmt,
55 hash:: { Hash , Hasher } ,
66 ptr,
7- sync:: {
8- atomic:: { AtomicPtr , Ordering } ,
9- Mutex , MutexGuard ,
10- } ,
7+ sync:: atomic:: { AtomicPtr , Ordering } ,
118} ;
129use crate :: {
1310 dispatcher:: { self , Dispatch } ,
@@ -71,18 +68,19 @@ pub use self::inner::{rebuild_interest_cache, register};
7168#[ cfg( feature = "std" ) ]
7269mod inner {
7370 use super :: * ;
71+ use std:: sync:: RwLock ;
7472 use std:: vec:: Vec ;
7573 type Dispatchers = Vec < dispatcher:: Registrar > ;
7674
7775 struct Registry {
7876 callsites : Callsites ,
79- dispatchers : Mutex < Dispatchers > ,
77+ dispatchers : RwLock < Dispatchers > ,
8078 }
8179
8280 lazy_static ! {
8381 static ref REGISTRY : Registry = Registry {
8482 callsites: LinkedList :: new( ) ,
85- dispatchers: Mutex :: new( Vec :: new( ) ) ,
83+ dispatchers: RwLock :: new( Vec :: new( ) ) ,
8684 } ;
8785 }
8886
@@ -106,7 +104,7 @@ mod inner {
106104 /// [`Interest::sometimes()`]: super::subscriber::Interest::sometimes
107105 /// [`Subscriber`]: super::subscriber::Subscriber
108106 pub fn rebuild_interest_cache ( ) {
109- let mut dispatchers = REGISTRY . dispatchers . lock ( ) . unwrap ( ) ;
107+ let mut dispatchers = REGISTRY . dispatchers . write ( ) . unwrap ( ) ;
110108 let callsites = & REGISTRY . callsites ;
111109 rebuild_interest ( callsites, & mut dispatchers) ;
112110 }
@@ -116,13 +114,13 @@ mod inner {
116114 /// This should be called once per callsite after the callsite has been
117115 /// constructed.
118116 pub fn register ( registration : & ' static Registration ) {
119- let mut dispatchers = REGISTRY . dispatchers . lock ( ) . unwrap ( ) ;
117+ let mut dispatchers = REGISTRY . dispatchers . read ( ) . unwrap ( ) ;
120118 rebuild_callsite_interest ( & mut dispatchers, registration. callsite ) ;
121119 REGISTRY . callsites . push ( registration) ;
122120 }
123121
124122 pub ( crate ) fn register_dispatch ( dispatch : & Dispatch ) {
125- let mut dispatchers = REGISTRY . dispatchers . lock ( ) . unwrap ( ) ;
123+ let mut dispatchers = REGISTRY . dispatchers . write ( ) . unwrap ( ) ;
126124 let callsites = & REGISTRY . callsites ;
127125
128126 dispatchers. push ( dispatch. registrar ( ) ) ;
@@ -131,7 +129,7 @@ mod inner {
131129 }
132130
133131 fn rebuild_callsite_interest (
134- dispatchers : & mut MutexGuard < ' _ , Vec < dispatcher:: Registrar > > ,
132+ dispatchers : & [ dispatcher:: Registrar ] ,
135133 callsite : & ' static dyn Callsite ,
136134 ) {
137135 let meta = callsite. metadata ( ) ;
@@ -156,10 +154,7 @@ mod inner {
156154 callsite. set_interest ( interest)
157155 }
158156
159- fn rebuild_interest (
160- callsites : & Callsites ,
161- dispatchers : & mut MutexGuard < ' _ , Vec < dispatcher:: Registrar > > ,
162- ) {
157+ fn rebuild_interest ( callsites : & Callsites , dispatchers : & mut Vec < dispatcher:: Registrar > ) {
163158 let mut max_level = LevelFilter :: OFF ;
164159 dispatchers. retain ( |registrar| {
165160 if let Some ( dispatch) = registrar. upgrade ( ) {
0 commit comments