2 * threads.c: set of generic threading related routines
4 * See Copyright for the status of this software.
6 * Gary Pennington <Gary.Pennington@uk.sun.com>
15 #include <libxml/threads.h>
16 #include <libxml/globals.h>
18 #ifdef HAVE_SYS_TYPES_H
19 #include <sys/types.h>
29 #elif defined HAVE_WIN32_THREADS
31 #ifndef HAVE_COMPILER_TLS
36 #ifdef HAVE_BEOS_THREADS
45 /* #define DEBUG_THREADS */
49 static int libxml_is_threaded = -1;
50 #if defined(__GNUC__) && defined(__GLIBC__)
52 #if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || (__GNUC__ > 3)
53 #pragma weak pthread_once
54 #pragma weak pthread_getspecific
55 #pragma weak pthread_setspecific
56 #pragma weak pthread_key_create
57 #pragma weak pthread_key_delete
58 #pragma weak pthread_mutex_init
59 #pragma weak pthread_mutex_destroy
60 #pragma weak pthread_mutex_lock
61 #pragma weak pthread_mutex_unlock
62 #pragma weak pthread_cond_init
63 #pragma weak pthread_cond_destroy
64 #pragma weak pthread_cond_wait
65 #pragma weak pthread_equal
66 #pragma weak pthread_self
67 #pragma weak pthread_key_create
68 #pragma weak pthread_key_delete
69 #pragma weak pthread_cond_signal
72 #endif /* defined(__GNUC__) && defined(__GLIBC__) */
73 #endif /* HAVE_PTHREAD_H */
76 * TODO: this module still uses malloc/free and not xmlMalloc/xmlFree
77 * to avoid some crazyness since xmlMalloc/xmlFree may actually
78 * be hosted on allocated blocks needing them for the allocation ...
82 * xmlMutex are a simple mutual exception locks
87 #elif defined HAVE_WIN32_THREADS
89 #elif defined HAVE_BEOS_THREADS
98 * xmlRMutex are reentrant mutual exception locks
101 #ifdef HAVE_PTHREAD_H
102 pthread_mutex_t lock;
104 unsigned int waiters;
107 #elif defined HAVE_WIN32_THREADS
110 #elif defined HAVE_BEOS_THREADS
120 * This module still has some internal static data.
121 * - xmlLibraryLock a global lock
122 * - globalkey used for per-thread data
125 #ifdef HAVE_PTHREAD_H
126 static pthread_key_t globalkey;
127 static pthread_t mainthread;
128 static pthread_once_t once_control = PTHREAD_ONCE_INIT;
129 static pthread_once_t once_control_init = PTHREAD_ONCE_INIT;
130 static pthread_mutex_t global_init_lock = PTHREAD_MUTEX_INITIALIZER;
131 #elif defined HAVE_WIN32_THREADS
132 #if defined(HAVE_COMPILER_TLS)
133 static __declspec(thread) xmlGlobalState tlstate;
134 static __declspec(thread) int tlstate_inited = 0;
135 #else /* HAVE_COMPILER_TLS */
136 static DWORD globalkey = TLS_OUT_OF_INDEXES;
137 #endif /* HAVE_COMPILER_TLS */
138 static DWORD mainthread;
142 } run_once = { 0, 0};
143 static volatile LPCRITICAL_SECTION global_init_lock = NULL;
145 /* endif HAVE_WIN32_THREADS */
146 #elif defined HAVE_BEOS_THREADS
148 thread_id mainthread = 0;
149 int32 run_once_init = 0;
150 static int32 global_init_lock = -1;
151 static vint32 global_init_count = 0;
154 static xmlRMutexPtr xmlLibraryLock = NULL;
156 #ifdef LIBXML_THREAD_ENABLED
157 static void xmlOnceInit(void);
163 * xmlNewMutex() is used to allocate a libxml2 token struct for use in
164 * synchronizing access to data.
166 * Returns a new simple mutex pointer or NULL in case of error
173 if ((tok = malloc(sizeof(xmlMutex))) == NULL)
175 #ifdef HAVE_PTHREAD_H
176 if (libxml_is_threaded != 0)
177 pthread_mutex_init(&tok->lock, NULL);
178 #elif defined HAVE_WIN32_THREADS
179 tok->mutex = CreateMutex(NULL, FALSE, NULL);
180 #elif defined HAVE_BEOS_THREADS
181 if ((tok->sem = create_sem(1, "xmlMutex")) < B_OK) {
192 * @tok: the simple mutex
194 * xmlFreeMutex() is used to reclaim resources associated with a libxml2 token
198 xmlFreeMutex(xmlMutexPtr tok)
203 #ifdef HAVE_PTHREAD_H
204 if (libxml_is_threaded != 0)
205 pthread_mutex_destroy(&tok->lock);
206 #elif defined HAVE_WIN32_THREADS
207 CloseHandle(tok->mutex);
208 #elif defined HAVE_BEOS_THREADS
209 delete_sem(tok->sem);
216 * @tok: the simple mutex
218 * xmlMutexLock() is used to lock a libxml2 token.
221 xmlMutexLock(xmlMutexPtr tok)
225 #ifdef HAVE_PTHREAD_H
226 if (libxml_is_threaded != 0)
227 pthread_mutex_lock(&tok->lock);
228 #elif defined HAVE_WIN32_THREADS
229 WaitForSingleObject(tok->mutex, INFINITE);
230 #elif defined HAVE_BEOS_THREADS
231 if (acquire_sem(tok->sem) != B_NO_ERROR) {
233 xmlGenericError(xmlGenericErrorContext,
234 "xmlMutexLock():BeOS:Couldn't aquire semaphore\n");
237 tok->tid = find_thread(NULL);
244 * @tok: the simple mutex
246 * xmlMutexUnlock() is used to unlock a libxml2 token.
249 xmlMutexUnlock(xmlMutexPtr tok)
253 #ifdef HAVE_PTHREAD_H
254 if (libxml_is_threaded != 0)
255 pthread_mutex_unlock(&tok->lock);
256 #elif defined HAVE_WIN32_THREADS
257 ReleaseMutex(tok->mutex);
258 #elif defined HAVE_BEOS_THREADS
259 if (tok->tid == find_thread(NULL)) {
261 release_sem(tok->sem);
269 * xmlRNewMutex() is used to allocate a reentrant mutex for use in
270 * synchronizing access to data. token_r is a re-entrant lock and thus useful
271 * for synchronizing access to data structures that may be manipulated in a
274 * Returns the new reentrant mutex pointer or NULL in case of error
281 if ((tok = malloc(sizeof(xmlRMutex))) == NULL)
283 #ifdef HAVE_PTHREAD_H
284 if (libxml_is_threaded != 0) {
285 pthread_mutex_init(&tok->lock, NULL);
288 pthread_cond_init(&tok->cv, NULL);
290 #elif defined HAVE_WIN32_THREADS
291 InitializeCriticalSection(&tok->cs);
293 #elif defined HAVE_BEOS_THREADS
294 if ((tok->lock = xmlNewMutex()) == NULL) {
305 * @tok: the reentrant mutex
307 * xmlRFreeMutex() is used to reclaim resources associated with a
311 xmlFreeRMutex(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
315 #ifdef HAVE_PTHREAD_H
316 if (libxml_is_threaded != 0) {
317 pthread_mutex_destroy(&tok->lock);
318 pthread_cond_destroy(&tok->cv);
320 #elif defined HAVE_WIN32_THREADS
321 DeleteCriticalSection(&tok->cs);
322 #elif defined HAVE_BEOS_THREADS
323 xmlFreeMutex(tok->lock);
330 * @tok: the reentrant mutex
332 * xmlRMutexLock() is used to lock a libxml2 token_r.
335 xmlRMutexLock(xmlRMutexPtr tok)
339 #ifdef HAVE_PTHREAD_H
340 if (libxml_is_threaded == 0)
343 pthread_mutex_lock(&tok->lock);
345 if (pthread_equal(tok->tid, pthread_self())) {
347 pthread_mutex_unlock(&tok->lock);
352 pthread_cond_wait(&tok->cv, &tok->lock);
356 tok->tid = pthread_self();
358 pthread_mutex_unlock(&tok->lock);
359 #elif defined HAVE_WIN32_THREADS
360 EnterCriticalSection(&tok->cs);
362 #elif defined HAVE_BEOS_THREADS
363 if (tok->lock->tid == find_thread(NULL)) {
367 xmlMutexLock(tok->lock);
375 * @tok: the reentrant mutex
377 * xmlRMutexUnlock() is used to unlock a libxml2 token_r.
380 xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
384 #ifdef HAVE_PTHREAD_H
385 if (libxml_is_threaded == 0)
388 pthread_mutex_lock(&tok->lock);
390 if (tok->held == 0) {
392 pthread_cond_signal(&tok->cv);
393 memset(&tok->tid, 0, sizeof(tok->tid));
395 pthread_mutex_unlock(&tok->lock);
396 #elif defined HAVE_WIN32_THREADS
397 if (tok->count > 0) {
399 LeaveCriticalSection(&tok->cs);
401 #elif defined HAVE_BEOS_THREADS
402 if (tok->lock->tid == find_thread(NULL)) {
404 if (tok->count == 0) {
405 xmlMutexUnlock(tok->lock);
413 * xmlGlobalInitMutexLock
415 * Makes sure that the global initialization mutex is initialized and
419 __xmlGlobalInitMutexLock(void)
421 /* Make sure the global init lock is initialized and then lock it. */
422 #ifdef HAVE_PTHREAD_H
423 /* The mutex is statically initialized, so we just lock it. */
424 if (pthread_mutex_lock != NULL)
425 pthread_mutex_lock(&global_init_lock);
426 #elif defined HAVE_WIN32_THREADS
427 LPCRITICAL_SECTION cs;
429 /* Create a new critical section */
430 if (global_init_lock == NULL) {
431 cs = malloc(sizeof(CRITICAL_SECTION));
433 xmlGenericError(xmlGenericErrorContext,
434 "xmlGlobalInitMutexLock: out of memory\n");
437 InitializeCriticalSection(cs);
439 /* Swap it into the global_init_lock */
440 #ifdef InterlockedCompareExchangePointer
441 InterlockedCompareExchangePointer(&global_init_lock, cs, NULL);
442 #else /* Use older void* version */
443 InterlockedCompareExchange((void **) &global_init_lock,
445 #endif /* InterlockedCompareExchangePointer */
447 /* If another thread successfully recorded its critical
448 * section in the global_init_lock then discard the one
449 * allocated by this thread. */
450 if (global_init_lock != cs) {
451 DeleteCriticalSection(cs);
456 /* Lock the chosen critical section */
457 EnterCriticalSection(global_init_lock);
458 #elif defined HAVE_BEOS_THREADS
461 /* Allocate a new semaphore */
462 sem = create_sem(1, "xmlGlobalinitMutex");
464 while (global_init_lock == -1) {
465 if (atomic_add(&global_init_count, 1) == 0) {
466 global_init_lock = sem;
469 atomic_add(&global_init_count, -1);
473 /* If another thread successfully recorded its critical
474 * section in the global_init_lock then discard the one
475 * allocated by this thread. */
476 if (global_init_lock != sem)
479 /* Acquire the chosen semaphore */
480 if (acquire_sem(global_init_lock) != B_NO_ERROR) {
482 xmlGenericError(xmlGenericErrorContext,
483 "xmlGlobalInitMutexLock():BeOS:Couldn't acquire semaphore\n");
490 __xmlGlobalInitMutexUnlock(void)
492 #ifdef HAVE_PTHREAD_H
493 if (pthread_mutex_unlock != NULL)
494 pthread_mutex_unlock(&global_init_lock);
495 #elif defined HAVE_WIN32_THREADS
496 if (global_init_lock != NULL) {
497 LeaveCriticalSection(global_init_lock);
499 #elif defined HAVE_BEOS_THREADS
500 release_sem(global_init_lock);
505 * xmlGlobalInitMutexDestroy
507 * Makes sure that the global initialization mutex is destroyed before
508 * application termination.
511 __xmlGlobalInitMutexDestroy(void)
513 #ifdef HAVE_PTHREAD_H
514 #elif defined HAVE_WIN32_THREADS
515 if (global_init_lock != NULL) {
516 DeleteCriticalSection(global_init_lock);
517 free(global_init_lock);
518 global_init_lock = NULL;
523 /************************************************************************
525 * Per thread global state handling *
527 ************************************************************************/
529 #ifdef LIBXML_THREAD_ENABLED
535 * xmlFreeGlobalState:
536 * @state: a thread global state
538 * xmlFreeGlobalState() is called when a thread terminates with a non-NULL
539 * global state. It is is used here to reclaim memory resources.
542 xmlFreeGlobalState(void *state)
544 xmlGlobalState *gs = (xmlGlobalState *) state;
546 /* free any memory allocated in the thread's xmlLastError */
547 xmlResetError(&(gs->xmlLastError));
554 * xmlNewGlobalState() allocates a global state. This structure is used to
555 * hold all data for use by a thread when supporting backwards compatibility
556 * of libxml2 to pre-thread-safe behaviour.
558 * Returns the newly allocated xmlGlobalStatePtr or NULL in case of error
560 static xmlGlobalStatePtr
561 xmlNewGlobalState(void)
565 gs = malloc(sizeof(xmlGlobalState));
567 xmlGenericError(xmlGenericErrorContext,
568 "xmlGetGlobalState: out of memory\n");
572 memset(gs, 0, sizeof(xmlGlobalState));
573 xmlInitializeGlobalState(gs);
576 #endif /* LIBXML_THREAD_ENABLED */
578 #ifdef HAVE_PTHREAD_H
579 #elif defined HAVE_WIN32_THREADS
580 #if !defined(HAVE_COMPILER_TLS)
581 #if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
582 typedef struct _xmlGlobalStateCleanupHelperParams {
585 } xmlGlobalStateCleanupHelperParams;
588 xmlGlobalStateCleanupHelper(void *p)
590 xmlGlobalStateCleanupHelperParams *params =
591 (xmlGlobalStateCleanupHelperParams *) p;
592 WaitForSingleObject(params->thread, INFINITE);
593 CloseHandle(params->thread);
594 xmlFreeGlobalState(params->memory);
598 #else /* LIBXML_STATIC && !LIBXML_STATIC_FOR_DLL */
600 typedef struct _xmlGlobalStateCleanupHelperParams {
602 struct _xmlGlobalStateCleanupHelperParams *prev;
603 struct _xmlGlobalStateCleanupHelperParams *next;
604 } xmlGlobalStateCleanupHelperParams;
606 static xmlGlobalStateCleanupHelperParams *cleanup_helpers_head = NULL;
607 static CRITICAL_SECTION cleanup_helpers_cs;
609 #endif /* LIBXMLSTATIC && !LIBXML_STATIC_FOR_DLL */
610 #endif /* HAVE_COMPILER_TLS */
611 #endif /* HAVE_WIN32_THREADS */
613 #if defined HAVE_BEOS_THREADS
616 * xmlGlobalStateCleanup:
617 * @data: unused parameter
622 xmlGlobalStateCleanup(void *data)
624 void *globalval = tls_get(globalkey);
626 if (globalval != NULL)
627 xmlFreeGlobalState(globalval);
634 * xmlGetGlobalState() is called to retrieve the global state for a thread.
636 * Returns the thread global state or NULL in case of error
639 xmlGetGlobalState(void)
641 #ifdef HAVE_PTHREAD_H
642 xmlGlobalState *globalval;
644 if (libxml_is_threaded == 0)
647 pthread_once(&once_control, xmlOnceInit);
649 if ((globalval = (xmlGlobalState *)
650 pthread_getspecific(globalkey)) == NULL) {
651 xmlGlobalState *tsd = xmlNewGlobalState();
655 pthread_setspecific(globalkey, tsd);
659 #elif defined HAVE_WIN32_THREADS
660 #if defined(HAVE_COMPILER_TLS)
661 if (!tlstate_inited) {
663 xmlInitializeGlobalState(&tlstate);
666 #else /* HAVE_COMPILER_TLS */
667 xmlGlobalState *globalval;
668 xmlGlobalStateCleanupHelperParams *p;
671 #if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
672 globalval = (xmlGlobalState *) TlsGetValue(globalkey);
674 p = (xmlGlobalStateCleanupHelperParams *) TlsGetValue(globalkey);
675 globalval = (xmlGlobalState *) (p ? p->memory : NULL);
677 if (globalval == NULL) {
678 xmlGlobalState *tsd = xmlNewGlobalState();
682 p = (xmlGlobalStateCleanupHelperParams *)
683 malloc(sizeof(xmlGlobalStateCleanupHelperParams));
685 xmlGenericError(xmlGenericErrorContext,
686 "xmlGetGlobalState: out of memory\n");
687 xmlFreeGlobalState(tsd);
691 #if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
692 DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
693 GetCurrentProcess(), &p->thread, 0, TRUE,
694 DUPLICATE_SAME_ACCESS);
695 TlsSetValue(globalkey, tsd);
696 _beginthread(xmlGlobalStateCleanupHelper, 0, p);
698 EnterCriticalSection(&cleanup_helpers_cs);
699 if (cleanup_helpers_head != NULL) {
700 cleanup_helpers_head->prev = p;
702 p->next = cleanup_helpers_head;
704 cleanup_helpers_head = p;
705 TlsSetValue(globalkey, p);
706 LeaveCriticalSection(&cleanup_helpers_cs);
712 #endif /* HAVE_COMPILER_TLS */
713 #elif defined HAVE_BEOS_THREADS
714 xmlGlobalState *globalval;
718 if ((globalval = (xmlGlobalState *) tls_get(globalkey)) == NULL) {
719 xmlGlobalState *tsd = xmlNewGlobalState();
723 tls_set(globalkey, tsd);
724 on_exit_thread(xmlGlobalStateCleanup, NULL);
733 /************************************************************************
735 * Library wide thread interfaces *
737 ************************************************************************/
742 * xmlGetThreadId() find the current thread ID number
743 * Note that this is likely to be broken on some platforms using pthreads
744 * as the specification doesn't mandate pthread_t to be an integer type
746 * Returns the current thread ID number
751 #ifdef HAVE_PTHREAD_H
755 if (libxml_is_threaded == 0)
758 /* horrible but preserves compat, see warning above */
759 memcpy(&ret, &id, sizeof(ret));
761 #elif defined HAVE_WIN32_THREADS
762 return GetCurrentThreadId();
763 #elif defined HAVE_BEOS_THREADS
764 return find_thread(NULL);
773 * xmlIsMainThread() check whether the current thread is the main thread.
775 * Returns 1 if the current thread is the main thread, 0 otherwise
778 xmlIsMainThread(void)
780 #ifdef HAVE_PTHREAD_H
781 if (libxml_is_threaded == -1)
783 if (libxml_is_threaded == 0)
785 pthread_once(&once_control, xmlOnceInit);
786 #elif defined HAVE_WIN32_THREADS
788 #elif defined HAVE_BEOS_THREADS
793 xmlGenericError(xmlGenericErrorContext, "xmlIsMainThread()\n");
795 #ifdef HAVE_PTHREAD_H
796 return (pthread_equal(mainthread,pthread_self()));
797 #elif defined HAVE_WIN32_THREADS
798 return (mainthread == GetCurrentThreadId());
799 #elif defined HAVE_BEOS_THREADS
800 return (mainthread == find_thread(NULL));
809 * xmlLockLibrary() is used to take out a re-entrant lock on the libxml2
816 xmlGenericError(xmlGenericErrorContext, "xmlLockLibrary()\n");
818 xmlRMutexLock(xmlLibraryLock);
824 * xmlUnlockLibrary() is used to release a re-entrant lock on the libxml2
828 xmlUnlockLibrary(void)
831 xmlGenericError(xmlGenericErrorContext, "xmlUnlockLibrary()\n");
833 xmlRMutexUnlock(xmlLibraryLock);
839 * xmlInitThreads() is used to to initialize all the thread related
840 * data of the libxml2 library.
845 #ifdef HAVE_PTHREAD_H
846 if (libxml_is_threaded == -1) {
847 if ((pthread_once != NULL) &&
848 (pthread_getspecific != NULL) &&
849 (pthread_setspecific != NULL) &&
850 (pthread_key_create != NULL) &&
851 (pthread_key_delete != NULL) &&
852 (pthread_mutex_init != NULL) &&
853 (pthread_mutex_destroy != NULL) &&
854 (pthread_mutex_lock != NULL) &&
855 (pthread_mutex_unlock != NULL) &&
856 (pthread_cond_init != NULL) &&
857 (pthread_cond_destroy != NULL) &&
858 (pthread_cond_wait != NULL) &&
859 (pthread_equal != NULL) &&
860 (pthread_self != NULL) &&
861 (pthread_cond_signal != NULL)) {
862 libxml_is_threaded = 1;
864 /* fprintf(stderr, "Running multithreaded\n"); */
867 /* fprintf(stderr, "Running without multithread\n"); */
868 libxml_is_threaded = 0;
871 #elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
872 InitializeCriticalSection(&cleanup_helpers_cs);
879 * xmlCleanupThreads() is used to to cleanup all the thread related
880 * data of the libxml2 library once processing has ended.
882 * WARNING: if your application is multithreaded or has plugin support
883 * calling this may crash the application if another thread or
884 * a plugin is still using libxml2. It's sometimes very hard to
885 * guess if libxml2 is in use in the application, some libraries
886 * or plugins may use it without notice. In case of doubt abstain
887 * from calling this function or do it just before calling exit()
888 * to avoid leak reports from valgrind !
891 xmlCleanupThreads(void)
894 xmlGenericError(xmlGenericErrorContext, "xmlCleanupThreads()\n");
896 #ifdef HAVE_PTHREAD_H
897 if ((libxml_is_threaded) && (pthread_key_delete != NULL))
898 pthread_key_delete(globalkey);
899 once_control = once_control_init;
900 #elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
901 if (globalkey != TLS_OUT_OF_INDEXES) {
902 xmlGlobalStateCleanupHelperParams *p;
904 EnterCriticalSection(&cleanup_helpers_cs);
905 p = cleanup_helpers_head;
907 xmlGlobalStateCleanupHelperParams *temp = p;
910 xmlFreeGlobalState(temp->memory);
913 cleanup_helpers_head = 0;
914 LeaveCriticalSection(&cleanup_helpers_cs);
916 globalkey = TLS_OUT_OF_INDEXES;
918 DeleteCriticalSection(&cleanup_helpers_cs);
922 #ifdef LIBXML_THREAD_ENABLED
927 * xmlOnceInit() is used to initialize the value of mainthread for use
928 * in other routines. This function should only be called using
929 * pthread_once() in association with the once_control variable to ensure
930 * that the function is only called once. See man pthread_once for more
936 #ifdef HAVE_PTHREAD_H
937 (void) pthread_key_create(&globalkey, xmlFreeGlobalState);
938 mainthread = pthread_self();
939 __xmlInitializeDict();
940 #elif defined(HAVE_WIN32_THREADS)
941 if (!run_once.done) {
942 if (InterlockedIncrement(&run_once.control) == 1) {
943 #if !defined(HAVE_COMPILER_TLS)
944 globalkey = TlsAlloc();
946 mainthread = GetCurrentThreadId();
947 __xmlInitializeDict();
950 /* Another thread is working; give up our slice and
951 * wait until they're done. */
952 while (!run_once.done)
956 #elif defined HAVE_BEOS_THREADS
957 if (atomic_add(&run_once_init, 1) == 0) {
958 globalkey = tls_allocate();
959 tls_set(globalkey, NULL);
960 mainthread = find_thread(NULL);
961 __xmlInitializeDict();
963 atomic_add(&run_once_init, -1);
970 * @hinstDLL: handle to DLL instance
971 * @fdwReason: Reason code for entry
972 * @lpvReserved: generic pointer (depends upon reason code)
974 * Entry point for Windows library. It is being used to free thread-specific
977 * Returns TRUE always
979 #ifdef HAVE_PTHREAD_H
980 #elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
981 #if defined(LIBXML_STATIC_FOR_DLL)
983 xmlDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
986 DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
990 case DLL_THREAD_DETACH:
991 if (globalkey != TLS_OUT_OF_INDEXES) {
992 xmlGlobalState *globalval = NULL;
993 xmlGlobalStateCleanupHelperParams *p =
994 (xmlGlobalStateCleanupHelperParams *)
995 TlsGetValue(globalkey);
996 globalval = (xmlGlobalState *) (p ? p->memory : NULL);
998 xmlFreeGlobalState(globalval);
999 TlsSetValue(globalkey, NULL);
1002 EnterCriticalSection(&cleanup_helpers_cs);
1003 if (p == cleanup_helpers_head)
1004 cleanup_helpers_head = p->next;
1006 p->prev->next = p->next;
1007 if (p->next != NULL)
1008 p->next->prev = p->prev;
1009 LeaveCriticalSection(&cleanup_helpers_cs);
1018 #define bottom_threads
1019 #include "elfgcchack.h"