| By the way, I rewrote the macro code (the suggested macro
was actually bogus - the TLS thread-global variable must be
allocated once BUT the malloc must be thread-dependent:
#define NOSTATIC_XRESERVE(name,type,nelt) do { \
static DWORD tlsIndex = 0; \
static int initValue = 0; \
if (initValue == 0) \
{ \
if (!hts_maylockvar()) { \
abortLog("unable to lock mutex (not initialized?!)");
\
abort(); \
} \
hts_lockvar(); \
if (initValue == 0) { \
tlsIndex = TlsAlloc(); \
if (tlsIndex == 0xFFFFFFFF) { \
abortLog("unable to allocate thread local storage
(TLS) for variable!"); \
abort(); \
} \
initValue = 1; \
} \
hts_unlockvar(); \
} \
name = (type*)TlsGetValue(tlsIndex); \
if (name == NULL) { \
name = (type*)malloc(sizeof(type)*nelt); \
if (name == NULL) { \
abortLog("unable to allocate memory for variable!"); \
abort(); \
} \
memset(name, 0, sizeof(type)*nelt); \
TlsSetValue(tlsIndex, name); \
} \
} while(0)
| |