HTTrack Website Copier
Free software offline browser - FORUM
Subject: Re: [Windows] libhttrack.dll and LoadLibrary
Author: Xavier Roche
Date: 04/17/2004 18:09
 
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)
 
Reply Create subthread


All articles

Subject Author Date
[Windows] libhttrack.dll and LoadLibrary

04/16/2004 21:07
Re: [Windows] libhttrack.dll and LoadLibrary

04/17/2004 17:18
Re: [Windows] libhttrack.dll and LoadLibrary

04/17/2004 18:09
Re: [Windows] libhttrack.dll and LoadLibrary

08/18/2005 19:55




8

Created with FORUM 2.0.11