RE: [xml] win32 threads feedback





Today, when I look at it, why not? The static and the dynamic
libs are compiled independently anyway.

I can give it a try if you want. What would be the #define to
test for to know we are compiling as a DLL or static lib?


Feel free.
#ifdef LIBXML_STATIC
-> static lib is being compiled
#else
-> dynamic lib is being compiled
#endif

Looks quite simple. The patch is attached.

-sbi
Index: threads.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/threads.c,v
retrieving revision 1.14
diff -c -r1.14 threads.c
*** threads.c   10 Dec 2002 15:19:07 -0000      1.14
--- threads.c   4 May 2003 08:53:27 -0000
***************
*** 323,329 ****
  
  
  #ifdef HAVE_WIN32_THREADS
! #if !defined(HAVE_COMPILER_TLS)
  typedef struct _xmlGlobalStateCleanupHelperParams
  {
      HANDLE thread;
--- 323,329 ----
  
  
  #ifdef HAVE_WIN32_THREADS
! #if defined(LIBXML_STATIC) && !defined(HAVE_COMPILER_TLS)
  typedef struct _xmlGlobalStateCleanupHelperParams
  {
      HANDLE thread;
***************
*** 372,378 ****
        xmlInitializeGlobalState(&tlstate);
      }
      return &tlstate;
! #else /* HAVE_COMPILER_TLS */
      xmlGlobalState *globalval;
  
      if (run_once_init) { 
--- 372,384 ----
        xmlInitializeGlobalState(&tlstate);
      }
      return &tlstate;
! #elif defined(LIBXML_STATIC) /* HAVE_COMPILER_TLS */
!     /**
!      * When libxml is compiled as a static library,
!      * special care must be taken to free the thread global
!      * state when the thread terminates, because of
!      * limitations in the Windows Tls API.
!      */
      xmlGlobalState *globalval;
  
      if (run_once_init) { 
***************
*** 392,397 ****
--- 398,410 ----
        return (tsd);
      }
      return (globalval);
+ #else /* LIBXML_STATIC */
+     /**
+      * When libxml is compiled as a dll,
+      * allocation and deallocation of the thread global
+      * state is cared for in DllMain.
+      */
+     return (xmlGlobalState *) TlsGetValue(globalkey);
  #endif /* HAVE_COMPILER_TLS */
  #else
      return(NULL);
***************
*** 535,537 ****
--- 548,576 ----
      mainthread = GetCurrentThreadId();
  #endif
  }
+ 
+ #if defined(HAVE_WIN32_THREADS) && !defined(LIBXML_STATIC)
+ BOOL WINAPI DllMain(HINSTANCE hinstDLL,
+                     DWORD fdwReason,
+                     LPVOID lpvReserved) {
+     switch(fdwReason)
+     {
+     case DLL_PROCESS_ATTACH:
+         if (run_once_init) {
+             run_once_init = 0;
+             xmlOnceInit();
+         }
+         break;
+     case DLL_THREAD_ATTACH:
+         TlsSetValue(globalkey,xmlNewGlobalState());
+         break;
+     case DLL_THREAD_DETACH:
+         xmlFreeGlobalState(TlsGetValue(globalkey));
+         break;
+     case DLL_PROCESS_DETACH:
+         TlsFree(globalkey);
+         run_once_init = 1;
+         break;
+     }
+ }
+ #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]