ReactOS 0.4.15-dev-7897-g78dc504
threads.c File Reference
#include "libxml.h"
#include <string.h>
#include <stdlib.h>
#include <libxml/threads.h>
#include <libxml/globals.h>
Include dependency graph for threads.c:

Go to the source code of this file.

Classes

struct  _xmlMutex
 
struct  _xmlRMutex
 

Macros

#define IN_LIBXML
 

Functions

xmlMutexPtr xmlNewMutex (void)
 
void xmlFreeMutex (xmlMutexPtr tok)
 
void xmlMutexLock (xmlMutexPtr tok)
 
void xmlMutexUnlock (xmlMutexPtr tok)
 
xmlRMutexPtr xmlNewRMutex (void)
 
void xmlFreeRMutex (xmlRMutexPtr tok ATTRIBUTE_UNUSED)
 
void xmlRMutexLock (xmlRMutexPtr tok)
 
void xmlRMutexUnlock (xmlRMutexPtr tok ATTRIBUTE_UNUSED)
 
void __xmlGlobalInitMutexLock (void)
 
void __xmlGlobalInitMutexUnlock (void)
 
void __xmlGlobalInitMutexDestroy (void)
 
xmlGlobalStatePtr xmlGetGlobalState (void)
 
int xmlGetThreadId (void)
 
int xmlIsMainThread (void)
 
void xmlLockLibrary (void)
 
void xmlUnlockLibrary (void)
 
void xmlInitThreads (void)
 
void xmlCleanupThreads (void)
 

Variables

static xmlRMutexPtr xmlLibraryLock = NULL
 

Macro Definition Documentation

◆ IN_LIBXML

#define IN_LIBXML

threads.c: set of generic threading related routines

See Copyright for the status of this software.

Gary Pennington Gary..nosp@m.Penn.nosp@m.ingto.nosp@m.n@uk.nosp@m..sun..nosp@m.com danie.nosp@m.l@ve.nosp@m.illar.nosp@m.d.co.nosp@m.m

Definition at line 10 of file threads.c.

Function Documentation

◆ __xmlGlobalInitMutexDestroy()

void __xmlGlobalInitMutexDestroy ( void  )

xmlGlobalInitMutexDestroy

Makes sure that the global initialization mutex is destroyed before application termination.

Definition at line 512 of file threads.c.

513{
514#ifdef HAVE_PTHREAD_H
515#elif defined HAVE_WIN32_THREADS
516 if (global_init_lock != NULL) {
517 DeleteCriticalSection(global_init_lock);
518 free(global_init_lock);
519 global_init_lock = NULL;
520 }
521#endif
522}
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

Referenced by xmlCleanupGlobals().

◆ __xmlGlobalInitMutexLock()

void __xmlGlobalInitMutexLock ( void  )

xmlGlobalInitMutexLock

Makes sure that the global initialization mutex is initialized and locks it.

Definition at line 413 of file threads.c.

414{
415 /* Make sure the global init lock is initialized and then lock it. */
416#ifdef HAVE_PTHREAD_H
417 /* The mutex is statically initialized, so we just lock it. */
418#ifdef XML_PTHREAD_WEAK
419 if (pthread_mutex_lock == NULL)
420 return;
421#endif /* XML_PTHREAD_WEAK */
422 pthread_mutex_lock(&global_init_lock);
423#elif defined HAVE_WIN32_THREADS
425
426 /* Create a new critical section */
427 if (global_init_lock == NULL) {
428 cs = malloc(sizeof(CRITICAL_SECTION));
429 if (cs == NULL) {
431 "xmlGlobalInitMutexLock: out of memory\n");
432 return;
433 }
435
436 /* Swap it into the global_init_lock */
437#ifdef InterlockedCompareExchangePointer
438 InterlockedCompareExchangePointer((void **) &global_init_lock,
439 cs, NULL);
440#else /* Use older void* version */
441 InterlockedCompareExchange((void **) &global_init_lock,
442 (void *) cs, NULL);
443#endif /* InterlockedCompareExchangePointer */
444
445 /* If another thread successfully recorded its critical
446 * section in the global_init_lock then discard the one
447 * allocated by this thread. */
448 if (global_init_lock != cs) {
450 free(cs);
451 }
452 }
453
454 /* Lock the chosen critical section */
455 EnterCriticalSection(global_init_lock);
456#elif defined HAVE_BEOS_THREADS
457 int32 sem;
458
459 /* Allocate a new semaphore */
460 sem = create_sem(1, "xmlGlobalinitMutex");
461
462 while (global_init_lock == -1) {
463 if (atomic_add(&global_init_count, 1) == 0) {
464 global_init_lock = sem;
465 } else {
466 snooze(1);
467 atomic_add(&global_init_count, -1);
468 }
469 }
470
471 /* If another thread successfully recorded its critical
472 * section in the global_init_lock then discard the one
473 * allocated by this thread. */
474 if (global_init_lock != sem)
475 delete_sem(sem);
476
477 /* Acquire the chosen semaphore */
478 if (acquire_sem(global_init_lock) != B_NO_ERROR) {
479#ifdef DEBUG_THREADS
481 "xmlGlobalInitMutexLock():BeOS:Couldn't acquire semaphore\n");
482#endif
483 }
484#endif
485}
static void atomic_add(int volatile i, atomic_t volatile *v)
Definition: atomic.h:43
#define malloc
Definition: debug_ros.c:4
long int32
Definition: platform.h:12
#define cs
Definition: i386-dis.c:442
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
#define InterlockedCompareExchange
Definition: interlocked.h:104
static HANDLE sem
Definition: sync.c:674
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:353
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:337
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

Referenced by xmlInitParser().

◆ __xmlGlobalInitMutexUnlock()

void __xmlGlobalInitMutexUnlock ( void  )

Definition at line 488 of file threads.c.

489{
490#ifdef HAVE_PTHREAD_H
491#ifdef XML_PTHREAD_WEAK
492 if (pthread_mutex_unlock == NULL)
493 return;
494#endif /* XML_PTHREAD_WEAK */
495 pthread_mutex_unlock(&global_init_lock);
496#elif defined HAVE_WIN32_THREADS
497 if (global_init_lock != NULL) {
498 LeaveCriticalSection(global_init_lock);
499 }
500#elif defined HAVE_BEOS_THREADS
501 release_sem(global_init_lock);
502#endif
503}
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by xmlInitParser().

◆ xmlCleanupThreads()

void xmlCleanupThreads ( void  )

xmlCleanupThreads:

DEPRECATED: This function will be made private. Call xmlCleanupParser to free global state but see the warnings there. xmlCleanupParser should be only called once at program exit. In most cases, you don't have call cleanup functions at all.

xmlCleanupThreads() is used to to cleanup all the thread related data of the libxml2 library once processing has ended.

WARNING: if your application is multithreaded or has plugin support calling this may crash the application if another thread or a plugin is still using libxml2. It's sometimes very hard to guess if libxml2 is in use in the application, some libraries or plugins may use it without notice. In case of doubt abstain from calling this function or do it just before calling exit() to avoid leak reports from valgrind !

Definition at line 900 of file threads.c.

901{
902#ifdef DEBUG_THREADS
903 xmlGenericError(xmlGenericErrorContext, "xmlCleanupThreads()\n");
904#endif
905#ifdef HAVE_PTHREAD_H
906 if (libxml_is_threaded != 0)
907 pthread_key_delete(globalkey);
908 once_control = once_control_init;
909#elif defined(HAVE_WIN32_THREADS)
910#if !defined(HAVE_COMPILER_TLS)
911 if (globalkey != TLS_OUT_OF_INDEXES) {
912#if !defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL)
913 xmlGlobalStateCleanupHelperParams *p;
914
915 EnterCriticalSection(&cleanup_helpers_cs);
916 p = cleanup_helpers_head;
917 while (p != NULL) {
918 xmlGlobalStateCleanupHelperParams *temp = p;
919
920 p = p->next;
921 xmlFreeGlobalState(temp->memory);
922 free(temp);
923 }
924 cleanup_helpers_head = 0;
925 LeaveCriticalSection(&cleanup_helpers_cs);
926#endif
927 TlsFree(globalkey);
928 globalkey = TLS_OUT_OF_INDEXES;
929 }
930#if !defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL)
931 DeleteCriticalSection(&cleanup_helpers_cs);
932#endif
933#endif
934 run_once.done = 0;
935 run_once.control = 0;
936#endif
937}
BOOL WINAPI TlsFree(IN DWORD Index)
Definition: thread.c:1166
GLfloat GLfloat p
Definition: glext.h:8902
static calc_node_t temp
Definition: rpn_ieee.c:38
#define TLS_OUT_OF_INDEXES
Definition: winbase.h:549

Referenced by xmlCleanupParser().

◆ xmlFreeMutex()

void xmlFreeMutex ( xmlMutexPtr  tok)

xmlFreeMutex: @tok: the simple mutex

xmlFreeMutex() is used to reclaim resources associated with a libxml2 token struct.

Definition at line 197 of file threads.c.

198{
199 if (tok == NULL)
200 return;
201
202#ifdef HAVE_PTHREAD_H
203 if (libxml_is_threaded != 0)
204 pthread_mutex_destroy(&tok->lock);
205#elif defined HAVE_WIN32_THREADS
206 DeleteCriticalSection(&tok->cs);
207#elif defined HAVE_BEOS_THREADS
208 delete_sem(tok->sem);
209#endif
210 free(tok);
211}

Referenced by xmlCleanupGlobals(), xmlCleanupMemory(), xmlDictCleanup(), xmlFreeRMutex(), and xsltCleanupGlobals().

◆ xmlFreeRMutex()

void xmlFreeRMutex ( xmlRMutexPtr tok  ATTRIBUTE_UNUSED)

xmlFreeRMutex: @tok: the reentrant mutex

xmlRFreeMutex() is used to reclaim resources associated with a reentrant mutex.

Definition at line 309 of file threads.c.

310{
311 if (tok == NULL)
312 return;
313#ifdef HAVE_PTHREAD_H
314 if (libxml_is_threaded != 0) {
315 pthread_mutex_destroy(&tok->lock);
316 pthread_cond_destroy(&tok->cv);
317 }
318#elif defined HAVE_WIN32_THREADS
319 DeleteCriticalSection(&tok->cs);
320#elif defined HAVE_BEOS_THREADS
321 xmlFreeMutex(tok->lock);
322#endif
323 free(tok);
324}
void xmlFreeMutex(xmlMutexPtr tok)
Definition: threads.c:197

Referenced by xsltUninit().

◆ xmlGetGlobalState()

xmlGlobalStatePtr xmlGetGlobalState ( void  )

xmlGetGlobalState:

xmlGetGlobalState() is called to retrieve the global state for a thread.

Returns the thread global state or NULL in case of error

Definition at line 640 of file threads.c.

641{
642#ifdef HAVE_PTHREAD_H
643 xmlGlobalState *globalval;
644
645 if (libxml_is_threaded == 0)
646 return (NULL);
647
648 pthread_once(&once_control, xmlOnceInit);
649
650 if ((globalval = (xmlGlobalState *)
651 pthread_getspecific(globalkey)) == NULL) {
652 xmlGlobalState *tsd = xmlNewGlobalState();
653 if (tsd == NULL)
654 return(NULL);
655
656 pthread_setspecific(globalkey, tsd);
657 return (tsd);
658 }
659 return (globalval);
660#elif defined HAVE_WIN32_THREADS
661#if defined(HAVE_COMPILER_TLS)
662 if (!tlstate_inited) {
663 tlstate_inited = 1;
664 xmlInitializeGlobalState(&tlstate);
665 }
666 return &tlstate;
667#else /* HAVE_COMPILER_TLS */
668 xmlGlobalState *globalval;
669 xmlGlobalStateCleanupHelperParams *p;
670
671 xmlOnceInit();
672#if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
673 globalval = (xmlGlobalState *) TlsGetValue(globalkey);
674#else
675 p = (xmlGlobalStateCleanupHelperParams *) TlsGetValue(globalkey);
676 globalval = (xmlGlobalState *) (p ? p->memory : NULL);
677#endif
678 if (globalval == NULL) {
679 xmlGlobalState *tsd = xmlNewGlobalState();
680
681 if (tsd == NULL)
682 return(NULL);
683 p = (xmlGlobalStateCleanupHelperParams *)
684 malloc(sizeof(xmlGlobalStateCleanupHelperParams));
685 if (p == NULL) {
687 "xmlGetGlobalState: out of memory\n");
688 xmlFreeGlobalState(tsd);
689 return(NULL);
690 }
691 p->memory = tsd;
692#if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
694 GetCurrentProcess(), &p->thread, 0, TRUE,
696 TlsSetValue(globalkey, tsd);
697 _beginthread(xmlGlobalStateCleanupHelper, 0, p);
698#else
699 EnterCriticalSection(&cleanup_helpers_cs);
700 if (cleanup_helpers_head != NULL) {
701 cleanup_helpers_head->prev = p;
702 }
703 p->next = cleanup_helpers_head;
704 p->prev = NULL;
705 cleanup_helpers_head = p;
706 TlsSetValue(globalkey, p);
707 LeaveCriticalSection(&cleanup_helpers_cs);
708#endif
709
710 return (tsd);
711 }
712 return (globalval);
713#endif /* HAVE_COMPILER_TLS */
714#elif defined HAVE_BEOS_THREADS
715 xmlGlobalState *globalval;
716
717 xmlOnceInit();
718
719 if ((globalval = (xmlGlobalState *) tls_get(globalkey)) == NULL) {
720 xmlGlobalState *tsd = xmlNewGlobalState();
721 if (tsd == NULL)
722 return (NULL);
723
724 tls_set(globalkey, tsd);
725 on_exit_thread(xmlGlobalStateCleanup, NULL);
726 return (tsd);
727 }
728 return (globalval);
729#else
730 return (NULL);
731#endif
732}
#define TRUE
Definition: types.h:120
#define GetCurrentProcess()
Definition: compat.h:759
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
Definition: handle.c:149
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1240
BOOL WINAPI TlsSetValue(IN DWORD Index, IN LPVOID Value)
Definition: thread.c:1276
_CRTIMP uintptr_t __cdecl _beginthread(_In_ void(__cdecl *_StartAddress)(void *), _In_ unsigned _StackSize, _In_opt_ void *_ArgList)
XMLPUBFUN void XMLCALL xmlInitializeGlobalState(xmlGlobalStatePtr gs)
Definition: globals.c:454
HANDLE WINAPI GetCurrentThread(void)
Definition: proc.c:1148
#define DUPLICATE_SAME_ACCESS

Referenced by __oldXMLWDcompatibility(), __xmlBufferAllocScheme(), __xmlDefaultBufferSize(), __xmlDefaultSAXLocator(), __xmlDeregisterNodeDefaultValue(), __xmlDoValidityCheckingDefaultValue(), __xmlGenericError(), __xmlGenericErrorContext(), __xmlGetWarningsDefaultValue(), __xmlIndentTreeOutput(), __xmlKeepBlanksDefaultValue(), __xmlLastError(), __xmlLineNumbersDefaultValue(), __xmlLoadExtDtdDefaultValue(), __xmlOutputBufferCreateFilenameValue(), __xmlParserDebugEntities(), __xmlParserInputBufferCreateFilenameValue(), __xmlParserVersion(), __xmlPedanticParserDefaultValue(), __xmlRegisterNodeDefaultValue(), __xmlSaveNoEmptyTags(), __xmlStructuredError(), __xmlStructuredErrorContext(), __xmlSubstituteEntitiesDefaultValue(), and __xmlTreeIndentString().

◆ xmlGetThreadId()

int xmlGetThreadId ( void  )

xmlGetThreadId:

xmlGetThreadId() find the current thread ID number Note that this is likely to be broken on some platforms using pthreads as the specification doesn't mandate pthread_t to be an integer type

Returns the current thread ID number

Definition at line 750 of file threads.c.

751{
752#ifdef HAVE_PTHREAD_H
753 pthread_t id;
754 int ret;
755
756 if (libxml_is_threaded == 0)
757 return (0);
758 id = pthread_self();
759 /* horrible but preserves compat, see warning above */
760 memcpy(&ret, &id, sizeof(ret));
761 return (ret);
762#elif defined HAVE_WIN32_THREADS
763 return GetCurrentThreadId();
764#elif defined HAVE_BEOS_THREADS
765 return find_thread(NULL);
766#else
767 return ((int) 0);
768#endif
769}
GLuint id
Definition: glext.h:5910
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition: utils.c:41
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
int ret
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459

Referenced by xmlInitializeGlobalState().

◆ xmlInitThreads()

void xmlInitThreads ( void  )

xmlInitThreads:

DEPRECATED: This function will be made private. Call xmlInitParser to initialize the library.

xmlInitThreads() is used to to initialize all the thread related data of the libxml2 library.

Definition at line 847 of file threads.c.

848{
849#ifdef HAVE_PTHREAD_H
850#ifdef XML_PTHREAD_WEAK
851 if (libxml_is_threaded == -1) {
852 if ((pthread_once != NULL) &&
853 (pthread_getspecific != NULL) &&
854 (pthread_setspecific != NULL) &&
855 (pthread_key_create != NULL) &&
856 (pthread_key_delete != NULL) &&
857 (pthread_mutex_init != NULL) &&
858 (pthread_mutex_destroy != NULL) &&
859 (pthread_mutex_lock != NULL) &&
860 (pthread_mutex_unlock != NULL) &&
861 (pthread_cond_init != NULL) &&
862 (pthread_cond_destroy != NULL) &&
863 (pthread_cond_wait != NULL) &&
864 (pthread_equal != NULL) &&
865 (pthread_self != NULL) &&
866 (pthread_cond_signal != NULL)) {
867 libxml_is_threaded = 1;
868
869/* fprintf(stderr, "Running multithreaded\n"); */
870 } else {
871
872/* fprintf(stderr, "Running without multithread\n"); */
873 libxml_is_threaded = 0;
874 }
875 }
876#endif /* XML_PTHREAD_WEAK */
877#endif
878}

Referenced by xmlInitParser(), and xmlIsMainThread().

◆ xmlIsMainThread()

int xmlIsMainThread ( void  )

xmlIsMainThread:

xmlIsMainThread() check whether the current thread is the main thread.

Returns 1 if the current thread is the main thread, 0 otherwise

Definition at line 779 of file threads.c.

780{
781#ifdef HAVE_PTHREAD_H
782 if (libxml_is_threaded == -1)
784 if (libxml_is_threaded == 0)
785 return (1);
786 pthread_once(&once_control, xmlOnceInit);
787#elif defined HAVE_WIN32_THREADS
788 xmlOnceInit();
789#elif defined HAVE_BEOS_THREADS
790 xmlOnceInit();
791#endif
792
793#ifdef DEBUG_THREADS
794 xmlGenericError(xmlGenericErrorContext, "xmlIsMainThread()\n");
795#endif
796#ifdef HAVE_PTHREAD_H
797 return (pthread_equal(mainthread,pthread_self()));
798#elif defined HAVE_WIN32_THREADS
799 return (mainthread == GetCurrentThreadId());
800#elif defined HAVE_BEOS_THREADS
801 return (mainthread == find_thread(NULL));
802#else
803 return (1);
804#endif
805}
void xmlInitThreads(void)
Definition: threads.c:847

◆ xmlLockLibrary()

void xmlLockLibrary ( void  )

xmlLockLibrary:

xmlLockLibrary() is used to take out a re-entrant lock on the libxml2 library.

Definition at line 814 of file threads.c.

815{
816#ifdef DEBUG_THREADS
817 xmlGenericError(xmlGenericErrorContext, "xmlLockLibrary()\n");
818#endif
820}
static xmlRMutexPtr xmlLibraryLock
Definition: threads.c:153
void xmlRMutexLock(xmlRMutexPtr tok)
Definition: threads.c:333

◆ xmlMutexLock()

void xmlMutexLock ( xmlMutexPtr  tok)

xmlMutexLock: @tok: the simple mutex

xmlMutexLock() is used to lock a libxml2 token.

Definition at line 220 of file threads.c.

221{
222 if (tok == NULL)
223 return;
224#ifdef HAVE_PTHREAD_H
225 if (libxml_is_threaded != 0)
226 pthread_mutex_lock(&tok->lock);
227#elif defined HAVE_WIN32_THREADS
228 EnterCriticalSection(&tok->cs);
229#elif defined HAVE_BEOS_THREADS
230 if (acquire_sem(tok->sem) != B_NO_ERROR) {
231#ifdef DEBUG_THREADS
233 "xmlMutexLock():BeOS:Couldn't acquire semaphore\n");
234#endif
235 }
236 tok->tid = find_thread(NULL);
237#endif
238
239}

Referenced by __xmlInitializeDict(), __xmlRandom(), xmlDictFree(), xmlDictReference(), xmlInitializeGlobalState(), xmlMallocAtomicLoc(), xmlMallocLoc(), xmlMemBlocks(), xmlMemDisplay(), xmlMemDisplayLast(), xmlMemFree(), xmlMemShow(), xmlMemStrdupLoc(), xmlMemUsed(), xmlReallocLoc(), xmlRMutexLock(), xmlThrDefBufferAllocScheme(), xmlThrDefDefaultBufferSize(), xmlThrDefDeregisterNodeDefault(), xmlThrDefDoValidityCheckingDefaultValue(), xmlThrDefGetWarningsDefaultValue(), xmlThrDefIndentTreeOutput(), xmlThrDefKeepBlanksDefaultValue(), xmlThrDefLineNumbersDefaultValue(), xmlThrDefLoadExtDtdDefaultValue(), xmlThrDefOutputBufferCreateFilenameDefault(), xmlThrDefParserDebugEntities(), xmlThrDefParserInputBufferCreateFilenameDefault(), xmlThrDefPedanticParserDefaultValue(), xmlThrDefRegisterNodeDefault(), xmlThrDefSaveNoEmptyTags(), xmlThrDefSetGenericErrorFunc(), xmlThrDefSetStructuredErrorFunc(), xmlThrDefSubstituteEntitiesDefaultValue(), xmlThrDefTreeIndentString(), xsltCleanupGlobals(), xsltDebugDumpExtensions(), xsltExtModuleElementLookup(), xsltExtModuleElementPreComputeLookup(), xsltExtModuleFunctionLookup(), xsltExtModuleTopLevelLookup(), xsltGetExtData(), xsltPreComputeExtModuleElement(), xsltRegisterExtModuleElement(), xsltRegisterExtModuleFull(), xsltRegisterExtModuleFunction(), xsltRegisterExtModuleTopLevel(), xsltRegisterExtPrefix(), xsltStyleInitializeStylesheetModule(), xsltUnregisterAllExtModuleElement(), xsltUnregisterAllExtModuleFunction(), xsltUnregisterAllExtModules(), xsltUnregisterAllExtModuleTopLevel(), xsltUnregisterExtModule(), xsltUnregisterExtModuleElement(), xsltUnregisterExtModuleFunction(), and xsltUnregisterExtModuleTopLevel().

◆ xmlMutexUnlock()

void xmlMutexUnlock ( xmlMutexPtr  tok)

xmlMutexUnlock: @tok: the simple mutex

xmlMutexUnlock() is used to unlock a libxml2 token.

Definition at line 248 of file threads.c.

249{
250 if (tok == NULL)
251 return;
252#ifdef HAVE_PTHREAD_H
253 if (libxml_is_threaded != 0)
254 pthread_mutex_unlock(&tok->lock);
255#elif defined HAVE_WIN32_THREADS
256 LeaveCriticalSection(&tok->cs);
257#elif defined HAVE_BEOS_THREADS
258 if (tok->tid == find_thread(NULL)) {
259 tok->tid = -1;
260 release_sem(tok->sem);
261 }
262#endif
263}

Referenced by __xmlInitializeDict(), __xmlRandom(), xmlDictFree(), xmlDictReference(), xmlInitializeGlobalState(), xmlMallocAtomicLoc(), xmlMallocLoc(), xmlMemBlocks(), xmlMemDisplay(), xmlMemDisplayLast(), xmlMemFree(), xmlMemShow(), xmlMemStrdupLoc(), xmlMemUsed(), xmlReallocLoc(), xmlRMutexUnlock(), xmlThrDefBufferAllocScheme(), xmlThrDefDefaultBufferSize(), xmlThrDefDeregisterNodeDefault(), xmlThrDefDoValidityCheckingDefaultValue(), xmlThrDefGetWarningsDefaultValue(), xmlThrDefIndentTreeOutput(), xmlThrDefKeepBlanksDefaultValue(), xmlThrDefLineNumbersDefaultValue(), xmlThrDefLoadExtDtdDefaultValue(), xmlThrDefOutputBufferCreateFilenameDefault(), xmlThrDefParserDebugEntities(), xmlThrDefParserInputBufferCreateFilenameDefault(), xmlThrDefPedanticParserDefaultValue(), xmlThrDefRegisterNodeDefault(), xmlThrDefSaveNoEmptyTags(), xmlThrDefSetGenericErrorFunc(), xmlThrDefSetStructuredErrorFunc(), xmlThrDefSubstituteEntitiesDefaultValue(), xmlThrDefTreeIndentString(), xsltCleanupGlobals(), xsltDebugDumpExtensions(), xsltExtModuleElementLookup(), xsltExtModuleElementPreComputeLookup(), xsltExtModuleFunctionLookup(), xsltExtModuleTopLevelLookup(), xsltGetExtData(), xsltPreComputeExtModuleElement(), xsltRegisterExtModuleElement(), xsltRegisterExtModuleFull(), xsltRegisterExtModuleFunction(), xsltRegisterExtModuleTopLevel(), xsltRegisterExtPrefix(), xsltStyleInitializeStylesheetModule(), xsltUnregisterAllExtModuleElement(), xsltUnregisterAllExtModuleFunction(), xsltUnregisterAllExtModules(), xsltUnregisterAllExtModuleTopLevel(), xsltUnregisterExtModule(), xsltUnregisterExtModuleElement(), xsltUnregisterExtModuleFunction(), and xsltUnregisterExtModuleTopLevel().

◆ xmlNewMutex()

xmlMutexPtr xmlNewMutex ( void  )

xmlNewMutex:

xmlNewMutex() is used to allocate a libxml2 token struct for use in synchronizing access to data.

Returns a new simple mutex pointer or NULL in case of error

Definition at line 168 of file threads.c.

169{
170 xmlMutexPtr tok;
171
172 if ((tok = malloc(sizeof(xmlMutex))) == NULL)
173 return (NULL);
174#ifdef HAVE_PTHREAD_H
175 if (libxml_is_threaded != 0)
176 pthread_mutex_init(&tok->lock, NULL);
177#elif defined HAVE_WIN32_THREADS
179#elif defined HAVE_BEOS_THREADS
180 if ((tok->sem = create_sem(1, "xmlMutex")) < B_OK) {
181 free(tok);
182 return NULL;
183 }
184 tok->tid = -1;
185#endif
186 return (tok);
187}

Referenced by __xmlInitializeDict(), xmlInitGlobals(), xmlInitMemory(), xmlNewRMutex(), and xsltInitGlobals().

◆ xmlNewRMutex()

xmlRMutexPtr xmlNewRMutex ( void  )

xmlNewRMutex:

xmlRNewMutex() is used to allocate a reentrant mutex for use in synchronizing access to data. token_r is a re-entrant lock and thus useful for synchronizing access to data structures that may be manipulated in a recursive fashion.

Returns the new reentrant mutex pointer or NULL in case of error

Definition at line 276 of file threads.c.

277{
278 xmlRMutexPtr tok;
279
280 if ((tok = malloc(sizeof(xmlRMutex))) == NULL)
281 return (NULL);
282#ifdef HAVE_PTHREAD_H
283 if (libxml_is_threaded != 0) {
284 pthread_mutex_init(&tok->lock, NULL);
285 tok->held = 0;
286 tok->waiters = 0;
287 pthread_cond_init(&tok->cv, NULL);
288 }
289#elif defined HAVE_WIN32_THREADS
291#elif defined HAVE_BEOS_THREADS
292 if ((tok->lock = xmlNewMutex()) == NULL) {
293 free(tok);
294 return NULL;
295 }
296 tok->count = 0;
297#endif
298 return (tok);
299}
xmlMutexPtr xmlNewMutex(void)
Definition: threads.c:168

Referenced by xsltInit().

◆ xmlRMutexLock()

void xmlRMutexLock ( xmlRMutexPtr  tok)

xmlRMutexLock: @tok: the reentrant mutex

xmlRMutexLock() is used to lock a libxml2 token_r.

Definition at line 333 of file threads.c.

334{
335 if (tok == NULL)
336 return;
337#ifdef HAVE_PTHREAD_H
338 if (libxml_is_threaded == 0)
339 return;
340
341 pthread_mutex_lock(&tok->lock);
342 if (tok->held) {
343 if (pthread_equal(tok->tid, pthread_self())) {
344 tok->held++;
345 pthread_mutex_unlock(&tok->lock);
346 return;
347 } else {
348 tok->waiters++;
349 while (tok->held)
350 pthread_cond_wait(&tok->cv, &tok->lock);
351 tok->waiters--;
352 }
353 }
354 tok->tid = pthread_self();
355 tok->held = 1;
356 pthread_mutex_unlock(&tok->lock);
357#elif defined HAVE_WIN32_THREADS
358 EnterCriticalSection(&tok->cs);
359#elif defined HAVE_BEOS_THREADS
360 if (tok->lock->tid == find_thread(NULL)) {
361 tok->count++;
362 return;
363 } else {
364 xmlMutexLock(tok->lock);
365 tok->count = 1;
366 }
367#endif
368}
void xmlMutexLock(xmlMutexPtr tok)
Definition: threads.c:220

Referenced by xmlLockLibrary(), and xsltFreeLocales().

◆ xmlRMutexUnlock()

void xmlRMutexUnlock ( xmlRMutexPtr tok  ATTRIBUTE_UNUSED)

xmlRMutexUnlock: @tok: the reentrant mutex

xmlRMutexUnlock() is used to unlock a libxml2 token_r.

Definition at line 377 of file threads.c.

378{
379 if (tok == NULL)
380 return;
381#ifdef HAVE_PTHREAD_H
382 if (libxml_is_threaded == 0)
383 return;
384
385 pthread_mutex_lock(&tok->lock);
386 tok->held--;
387 if (tok->held == 0) {
388 if (tok->waiters)
389 pthread_cond_signal(&tok->cv);
390 memset(&tok->tid, 0, sizeof(tok->tid));
391 }
392 pthread_mutex_unlock(&tok->lock);
393#elif defined HAVE_WIN32_THREADS
394 LeaveCriticalSection(&tok->cs);
395#elif defined HAVE_BEOS_THREADS
396 if (tok->lock->tid == find_thread(NULL)) {
397 tok->count--;
398 if (tok->count == 0) {
399 xmlMutexUnlock(tok->lock);
400 }
401 return;
402 }
403#endif
404}
#define memset(x, y, z)
Definition: compat.h:39
void xmlMutexUnlock(xmlMutexPtr tok)
Definition: threads.c:248

Referenced by xmlUnlockLibrary(), and xsltFreeLocales().

◆ xmlUnlockLibrary()

void xmlUnlockLibrary ( void  )

xmlUnlockLibrary:

xmlUnlockLibrary() is used to release a re-entrant lock on the libxml2 library.

Definition at line 829 of file threads.c.

830{
831#ifdef DEBUG_THREADS
832 xmlGenericError(xmlGenericErrorContext, "xmlUnlockLibrary()\n");
833#endif
835}
void xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
Definition: threads.c:377

Variable Documentation

◆ xmlLibraryLock

xmlRMutexPtr xmlLibraryLock = NULL
static

Definition at line 153 of file threads.c.

Referenced by xmlLockLibrary(), and xmlUnlockLibrary().