7
7
//! `GetModuleHandle` and `GetProcAddress` to look up DLL entry points at
8
8
//! runtime.
9
9
//!
10
- //! This is implemented simply by storing a function pointer in an atomic
11
- //! and using relaxed ordering to load it. This means that calling it will be no
12
- //! more expensive then calling any other dynamically imported function.
10
+ //! This is implemented simply by storing a function pointer in an atomic.
11
+ //! Loading and calling this function will have little or no overhead
12
+ //! compared with calling any other dynamically imported function.
13
13
//!
14
14
//! The stored function pointer starts out as an importer function which will
15
15
//! swap itself with the real function when it's called for the first time. If
16
16
//! the real function can't be imported then a fallback function is used in its
17
- //! place. While this is zero cost for the happy path (where the function is
17
+ //! place. While this is low cost for the happy path (where the function is
18
18
//! already loaded) it does mean there's some overhead the first time the
19
19
//! function is called. In the worst case, multiple threads may all end up
20
20
//! importing the same function unnecessarily.
@@ -175,7 +175,7 @@ pub mod WaitOnAddress {
175
175
176
176
#[ inline( always) ]
177
177
pub fn option ( ) -> Option < F > {
178
- let f = WAIT_ON_ADDRESS . load ( Ordering :: Relaxed ) ;
178
+ let f = WAIT_ON_ADDRESS . load ( Ordering :: Acquire ) ;
179
179
if !f. is_null ( ) { Some ( unsafe { mem:: transmute ( f) } ) } else { try_load ( ) }
180
180
}
181
181
@@ -185,7 +185,7 @@ pub mod WaitOnAddress {
185
185
// load the module
186
186
let mut wait_on_address = None ;
187
187
if let Some ( func) = try_load_inner ( ) {
188
- WAIT_ON_ADDRESS . store ( func. as_ptr ( ) , Ordering :: Relaxed ) ;
188
+ WAIT_ON_ADDRESS . store ( func. as_ptr ( ) , Ordering :: Release ) ;
189
189
wait_on_address = Some ( unsafe { mem:: transmute ( func) } ) ;
190
190
}
191
191
// Don't try to load the module again even if loading failed.
0 commit comments