summaryrefslogtreecommitdiffstats
path: root/include/arch/win32/apr_arch_misc.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/arch/win32/apr_arch_misc.h')
-rw-r--r--include/arch/win32/apr_arch_misc.h17
1 files changed, 9 insertions, 8 deletions
diff --git a/include/arch/win32/apr_arch_misc.h b/include/arch/win32/apr_arch_misc.h
index 4dbe899..3cc91b0 100644
--- a/include/arch/win32/apr_arch_misc.h
+++ b/include/arch/win32/apr_arch_misc.h
@@ -198,15 +198,16 @@ FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char *fnName, int ordinal);
*/
#define APR_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names) \
typedef rettype (calltype *apr_winapi_fpt_##fn) args; \
- static apr_winapi_fpt_##fn apr_winapi_pfn_##fn = NULL; \
- static int apr_winapi_chk_##fn = 0; \
+ static volatile apr_winapi_fpt_##fn apr_winapi_pfn_##fn = (apr_winapi_fpt_##fn) (ULONG_PTR) (-1); \
static APR_INLINE int apr_winapi_ld_##fn(void) \
- { if (apr_winapi_pfn_##fn) return 1; \
- if (apr_winapi_chk_##fn ++) return 0; \
- if (!apr_winapi_pfn_##fn) \
- apr_winapi_pfn_##fn = (apr_winapi_fpt_##fn) \
- apr_load_dll_func(lib, #fn, ord); \
- if (apr_winapi_pfn_##fn) return 1; else return 0; }; \
+ { \
+ apr_winapi_fpt_##fn cached_func = apr_winapi_pfn_##fn; \
+ if (cached_func == (apr_winapi_fpt_##fn) (ULONG_PTR) (-1)) { \
+ cached_func = (apr_winapi_fpt_##fn) apr_load_dll_func(lib, #fn, ord); \
+ /* Pointer-sized writes are atomic on Windows. */ \
+ apr_winapi_pfn_##fn = cached_func; \
+ } \
+ if (cached_func) return 1; else return 0; }; \
static APR_INLINE rettype apr_winapi_##fn args \
{ if (apr_winapi_ld_##fn()) \
return (*(apr_winapi_pfn_##fn)) names; \