From 9aab3038cc41b5f621d545df8302fdd7f957aa49 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Sat, 10 Dec 2011 20:39:17 +1100 Subject: [PATCH] InitOnceExecuteOnce not present on XP --- mech_eap/util.h | 8 +++----- mech_eap/util_attr.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mech_eap/util.h b/mech_eap/util.h index 4f54d41..23d6ff8 100644 --- a/mech_eap/util.h +++ b/mech_eap/util.h @@ -816,14 +816,12 @@ verifyTokenHeader(OM_uint32 *minor, #define GSSEAP_MUTEX_DESTROY(m) DeleteCriticalSection((m)) #define GSSEAP_MUTEX_LOCK(m) EnterCriticalSection((m)) #define GSSEAP_MUTEX_UNLOCK(m) LeaveCriticalSection((m)) -#define GSSEAP_ONCE_LEAVE do { return TRUE; } while (0) /* Thread-local is handled separately */ -#define GSSEAP_THREAD_ONCE INIT_ONCE -#define GSSEAP_ONCE_CALLBACK(cb) BOOL CALLBACK cb(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context) -#define GSSEAP_ONCE(o, i) InitOnceExecuteOnce((o), (i), NULL, NULL) -#define GSSEAP_ONCE_INITIALIZER INIT_ONCE_STATIC_INIT +/* Once is handled separately because INIT_ONCE is only on Vista and above */ +#define GSSEAP_ONCE_LEAVE +#define GSSEAP_ONCE_CALLBACK(cb) void CALLBACK cb(void) #else diff --git a/mech_eap/util_attr.cpp b/mech_eap/util_attr.cpp index 3bfe785..d3c99d3 100644 --- a/mech_eap/util_attr.cpp +++ b/mech_eap/util_attr.cpp @@ -43,8 +43,12 @@ #include /* lazy initialisation */ +#ifdef WIN32 +static volatile OM_uint32 gssEapAttrProvidersInitStatus = GSS_S_UNAVAILABLE; +#else static GSSEAP_THREAD_ONCE gssEapAttrProvidersInitOnce = GSSEAP_ONCE_INITIALIZER; static OM_uint32 gssEapAttrProvidersInitStatus = GSS_S_UNAVAILABLE; +#endif GSSEAP_ONCE_CALLBACK(gssEapAttrProvidersInitInternal) { @@ -74,7 +78,12 @@ cleanup: GSSEAP_ASSERT(major == GSS_S_COMPLETE); #endif +#ifdef WIN32 + InterlockedCompareExchangeRelease(&gssEapAttrProvidersInitStatus, + major, GSS_S_UNAVAILABLE); +#else gssEapAttrProvidersInitStatus = major; +#endif GSSEAP_ONCE_LEAVE; } @@ -82,7 +91,12 @@ cleanup: static OM_uint32 gssEapAttrProvidersInit(OM_uint32 *minor) { +#ifdef WIN32 + if (gssEapAttrProvidersInitStatus == GSS_S_UNAVAILABLE) + gssEapAttrProvidersInitInternal(); +#else GSSEAP_ONCE(&gssEapAttrProvidersInitOnce, gssEapAttrProvidersInitInternal); +#endif if (GSS_ERROR(gssEapAttrProvidersInitStatus)) *minor = GSSEAP_NO_ATTR_PROVIDERS; -- 2.1.4