win32: Fix very unlikely race condition in late linking code.
* include/arch/win32/apr_arch_misc.h
(APR_DECLARE_LATE_DLL_FUNC): Use INIT_ONCE to wait for concurrent
DLL loading if any.
@@ -199,13 +199,18 @@ 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 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) \
+ static INIT_ONCE apr_winapi_ctrl_##fn = {INIT_ONCE_STATIC_INIT}; \
+ static BOOL WINAPI apr_winapi_init_once_##fn(PINIT_ONCE init_once,\
+ PVOID baton, PVOID *context) \
+ { \
apr_winapi_pfn_##fn = (apr_winapi_fpt_##fn) \
apr_load_dll_func(lib, #fn, ord); \
+ return TRUE; \
+ } \
+static APR_INLINE int apr_winapi_ld_##fn(void) \
+ { if (apr_winapi_pfn_##fn) return 1; \
+ InitOnceExecuteOnce(&apr_winapi_ctrl_##fn, apr_winapi_init_once_##fn, \
+ NULL, NULL); \
if (apr_winapi_pfn_##fn) return 1; else return 0; }; \
static APR_INLINE rettype apr_winapi_##fn args \
{ if (apr_winapi_ld_##fn()) \
