@@ -6,7 +6,6 @@ use crate::{
66 subscriber:: Interest ,
77 sync:: { Mutex , MutexGuard } ,
88} ;
9- use alloc:: vec:: Vec ;
109use core:: {
1110 fmt,
1211 hash:: { Hash , Hasher } ,
@@ -70,18 +69,19 @@ pub use self::inner::{rebuild_interest_cache, register};
7069#[ cfg( feature = "std" ) ]
7170mod inner {
7271 use super :: * ;
72+ use std:: sync:: RwLock ;
7373 use std:: vec:: Vec ;
7474 type Dispatchers = Vec < dispatcher:: Registrar > ;
7575
7676 struct Registry {
7777 callsites : Callsites ,
78- dispatchers : Mutex < Dispatchers > ,
78+ dispatchers : RwLock < Dispatchers > ,
7979 }
8080
8181 lazy_static ! {
8282 static ref REGISTRY : Registry = Registry {
8383 callsites: LinkedList :: new( ) ,
84- dispatchers: Mutex :: new( Vec :: new( ) ) ,
84+ dispatchers: RwLock :: new( Vec :: new( ) ) ,
8585 } ;
8686 }
8787
@@ -105,7 +105,7 @@ mod inner {
105105 /// [`Interest::sometimes()`]: super::subscriber::Interest::sometimes
106106 /// [`Subscriber`]: super::subscriber::Subscriber
107107 pub fn rebuild_interest_cache ( ) {
108- let mut dispatchers = REGISTRY . dispatchers . lock ( ) . unwrap ( ) ;
108+ let mut dispatchers = REGISTRY . dispatchers . write ( ) . unwrap ( ) ;
109109 let callsites = & REGISTRY . callsites ;
110110 rebuild_interest ( callsites, & mut dispatchers) ;
111111 }
@@ -115,13 +115,13 @@ mod inner {
115115 /// This should be called once per callsite after the callsite has been
116116 /// constructed.
117117 pub fn register ( registration : & ' static Registration ) {
118- let mut dispatchers = REGISTRY . dispatchers . lock ( ) . unwrap ( ) ;
118+ let mut dispatchers = REGISTRY . dispatchers . read ( ) . unwrap ( ) ;
119119 rebuild_callsite_interest ( & mut dispatchers, registration. callsite ) ;
120120 REGISTRY . callsites . push ( registration) ;
121121 }
122122
123123 pub ( crate ) fn register_dispatch ( dispatch : & Dispatch ) {
124- let mut dispatchers = REGISTRY . dispatchers . lock ( ) . unwrap ( ) ;
124+ let mut dispatchers = REGISTRY . dispatchers . write ( ) . unwrap ( ) ;
125125 let callsites = & REGISTRY . callsites ;
126126
127127 dispatchers. push ( dispatch. registrar ( ) ) ;
@@ -130,7 +130,7 @@ mod inner {
130130 }
131131
132132 fn rebuild_callsite_interest (
133- dispatchers : & mut MutexGuard < ' _ , Vec < dispatcher:: Registrar > > ,
133+ dispatchers : & [ dispatcher:: Registrar ] ,
134134 callsite : & ' static dyn Callsite ,
135135 ) {
136136 let meta = callsite. metadata ( ) ;
@@ -155,10 +155,7 @@ mod inner {
155155 callsite. set_interest ( interest)
156156 }
157157
158- fn rebuild_interest (
159- callsites : & Callsites ,
160- dispatchers : & mut MutexGuard < ' _ , Vec < dispatcher:: Registrar > > ,
161- ) {
158+ fn rebuild_interest ( callsites : & Callsites , dispatchers : & mut Vec < dispatcher:: Registrar > ) {
162159 let mut max_level = LevelFilter :: OFF ;
163160 dispatchers. retain ( |registrar| {
164161 if let Some ( dispatch) = registrar. upgrade ( ) {
0 commit comments