ReactOS 0.4.15-dev-7681-g776c3a3
threads.h File Reference
#include <libxml/xmlversion.h>
#include <libxml/globals.h>
Include dependency graph for threads.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct _xmlMutex xmlMutex
 
typedef xmlMutexxmlMutexPtr
 
typedef struct _xmlRMutex xmlRMutex
 
typedef xmlRMutexxmlRMutexPtr
 

Functions

XMLPUBFUN xmlMutexPtr XMLCALL xmlNewMutex (void)
 
XMLPUBFUN void XMLCALL xmlMutexLock (xmlMutexPtr tok)
 
XMLPUBFUN void XMLCALL xmlMutexUnlock (xmlMutexPtr tok)
 
XMLPUBFUN void XMLCALL xmlFreeMutex (xmlMutexPtr tok)
 
XMLPUBFUN xmlRMutexPtr XMLCALL xmlNewRMutex (void)
 
XMLPUBFUN void XMLCALL xmlRMutexLock (xmlRMutexPtr tok)
 
XMLPUBFUN void XMLCALL xmlRMutexUnlock (xmlRMutexPtr tok)
 
XMLPUBFUN void XMLCALL xmlFreeRMutex (xmlRMutexPtr tok)
 
XML_DEPRECATED XMLPUBFUN void XMLCALL xmlInitThreads (void)
 
XMLPUBFUN void XMLCALL xmlLockLibrary (void)
 
XMLPUBFUN void XMLCALL xmlUnlockLibrary (void)
 
XMLPUBFUN int XMLCALL xmlGetThreadId (void)
 
XMLPUBFUN int XMLCALL xmlIsMainThread (void)
 
XML_DEPRECATED XMLPUBFUN void XMLCALL xmlCleanupThreads (void)
 
XMLPUBFUN xmlGlobalStatePtr XMLCALL xmlGetGlobalState (void)
 

Typedef Documentation

◆ xmlMutex

Summary: interfaces for thread handling Description: set of generic threading related routines should work with pthreads, Windows native or TLS threads

Copy: See Copyright for the status of this software.

Author: Daniel Veillard

Definition at line 23 of file threads.h.

◆ xmlMutexPtr

Definition at line 24 of file threads.h.

◆ xmlRMutex

Definition at line 29 of file threads.h.

◆ xmlRMutexPtr

Definition at line 30 of file threads.h.

Function Documentation

◆ xmlCleanupThreads()

XML_DEPRECATED XMLPUBFUN void XMLCALL 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}
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
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
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:353
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:337
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define TLS_OUT_OF_INDEXES
Definition: winbase.h:549
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

Referenced by xmlCleanupParser().

◆ xmlFreeMutex()

XMLPUBFUN void XMLCALL 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()

XMLPUBFUN void XMLCALL 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()

XMLPUBFUN xmlGlobalStatePtr XMLCALL 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 malloc
Definition: debug_ros.c:4
#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()

XMLPUBFUN int XMLCALL 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()

XML_DEPRECATED XMLPUBFUN void XMLCALL 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()

XMLPUBFUN int XMLCALL 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()

XMLPUBFUN void XMLCALL 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()

XMLPUBFUN void XMLCALL 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()

XMLPUBFUN void XMLCALL 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()

XMLPUBFUN xmlMutexPtr XMLCALL 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}
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751

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

◆ xmlNewRMutex()

XMLPUBFUN xmlRMutexPtr XMLCALL 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()

XMLPUBFUN void XMLCALL 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()

XMLPUBFUN void XMLCALL 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()

XMLPUBFUN void XMLCALL 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