File tree Expand file tree Collapse file tree 1 file changed +6
-10
lines changed
rust/cubestore/cubestore/src/util Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change 1717use crate :: CubeError ;
1818use std:: net:: ToSocketAddrs ;
1919use std:: net:: UdpSocket ;
20- use std:: sync:: Once ;
2120
2221#[ derive( Debug , PartialEq , Eq ) ]
2322pub enum Compatibility {
@@ -189,8 +188,9 @@ impl Sink {
189188
190189mod global_sink {
191190 use super :: * ;
192- static mut GLOBAL_SINK : Option < Sink > = None ;
193- static ONCE : Once = Once :: new ( ) ;
191+ use std:: sync:: OnceLock ;
192+
193+ static GLOBAL_SINK : OnceLock < Option < Sink > > = OnceLock :: new ( ) ;
194194
195195 pub fn init (
196196 bind_addr : impl ToSocketAddrs ,
@@ -201,11 +201,9 @@ mod global_sink {
201201 let s = Sink :: connect ( bind_addr, server_addr, mode, constant_tags) ?;
202202
203203 let mut called = false ;
204- ONCE . call_once ( || {
205- unsafe {
206- GLOBAL_SINK = Some ( s) ;
207- }
204+ GLOBAL_SINK . get_or_init ( || {
208205 called = true ;
206+ Some ( s)
209207 } ) ;
210208 if !called {
211209 panic ! ( "Metrics initialized twice or used before initialization" ) ;
@@ -214,9 +212,7 @@ mod global_sink {
214212 }
215213
216214 pub ( super ) fn sink ( ) -> & ' static Option < Sink > {
217- // Ensure we synchronize access to GLOBAL_SINK.
218- ONCE . call_once ( || { } ) ;
219- unsafe { & GLOBAL_SINK }
215+ GLOBAL_SINK . get_or_init ( || None )
220216 }
221217}
222218
You can’t perform that action at this time.
0 commit comments