@@ -147,7 +147,7 @@ macro_rules! compat_fn_with_fallback {
147
147
use super :: * ;
148
148
use crate :: mem;
149
149
use crate :: ffi:: CStr ;
150
- use crate :: sync:: atomic:: { AtomicBool , AtomicPtr , Ordering } ;
150
+ use crate :: sync:: atomic:: { AtomicPtr , Ordering } ;
151
151
use crate :: sys:: compat:: Module ;
152
152
153
153
type F = unsafe extern "system" fn ( $( $argtype) ,* ) -> $rettype;
@@ -158,7 +158,6 @@ macro_rules! compat_fn_with_fallback {
158
158
/// If it succeeds, `PTR` is set to the address of that symbol.
159
159
/// If it fails, then `PTR` is set to `fallback`.
160
160
static PTR : AtomicPtr <c_void> = AtomicPtr :: new( load as * mut _) ;
161
- static AVAILABLE : AtomicBool = AtomicBool :: new( false ) ;
162
161
163
162
unsafe extern "system" fn load( $( $argname: $argtype) ,* ) -> $rettype {
164
163
let func = load_from_module( Module :: new( $module) ) ;
@@ -173,11 +172,9 @@ macro_rules! compat_fn_with_fallback {
173
172
. or_else( || module. and_then( |m| m. proc_address( SYMBOL_NAME ) ) )
174
173
{
175
174
PTR . store( f. as_ptr( ) , Ordering :: Relaxed ) ;
176
- AVAILABLE . store( true , Ordering :: Relaxed ) ;
177
175
mem:: transmute( f)
178
176
} else {
179
177
PTR . store( fallback as * mut _, Ordering :: Relaxed ) ;
180
- AVAILABLE . store( false , Ordering :: Relaxed ) ;
181
178
fallback
182
179
}
183
180
}
@@ -189,17 +186,21 @@ macro_rules! compat_fn_with_fallback {
189
186
}
190
187
191
188
pub unsafe fn available( ) -> bool {
192
- // Quickly return if already available
193
- if AVAILABLE . load( Ordering :: Relaxed ) {
189
+ let func = PTR . load( Ordering :: Relaxed ) ;
190
+
191
+ // Check the function pointer to see if it is not equal to `load`
192
+ if func == fallback as * mut _ {
193
+ return false ;
194
+ } else if func != load as * mut _ {
194
195
return true ;
195
196
}
196
197
197
- // Try to avoid fetching the load status every time
198
- if PTR . load( Ordering :: Relaxed ) == load as * mut _ {
199
- let _ = load_from_module( Module :: new( $module) ) ;
200
- }
198
+ // Otherwise, the function pointer should be resolved
199
+ let _ = load_from_module( Module :: new( $module) ) ;
201
200
202
- AVAILABLE . load( Ordering :: Relaxed )
201
+ // After resolution, the function pointer will only point to `fallback` if
202
+ // the target function was not found
203
+ PTR . load( Ordering :: Relaxed ) == fallback as * mut _
203
204
}
204
205
205
206
#[ inline( always) ]
0 commit comments