ReactOS  0.4.13-dev-544-gede3fdd
threads.c File Reference
#include "libxml.h"
#include <string.h>
#include <libxml/threads.h>
#include <libxml/globals.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include "elfgcchack.h"
Include dependency graph for threads.c:

Go to the source code of this file.

Classes

struct  _xmlMutex
 
struct  _xmlRMutex
 

Macros

#define IN_LIBXML
 
#define bottom_threads
 

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

◆ bottom_threads

#define bottom_threads

DllMain: @hinstDLL: handle to DLL instance @fdwReason: Reason code for entry @lpvReserved: generic pointer (depends upon reason code)

Entry point for Windows library. It is being used to free thread-specific storage.

Returns TRUE always

Definition at line 1047 of file threads.c.

◆ 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 526 of file threads.c.

527 {
528 #ifdef HAVE_PTHREAD_H
529 #elif defined HAVE_WIN32_THREADS
530  if (global_init_lock != NULL) {
531  DeleteCriticalSection(global_init_lock);
532  free(global_init_lock);
533  global_init_lock = NULL;
534  }
535 #endif
536 }
#define free
Definition: debug_ros.c:5
smooth NULL
Definition: ftsmooth.c:416
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 427 of file threads.c.

428 {
429  /* Make sure the global init lock is initialized and then lock it. */
430 #ifdef HAVE_PTHREAD_H
431  /* The mutex is statically initialized, so we just lock it. */
432 #ifdef XML_PTHREAD_WEAK
433  if (pthread_mutex_lock == NULL)
434  return;
435 #endif /* XML_PTHREAD_WEAK */
436  pthread_mutex_lock(&global_init_lock);
437 #elif defined HAVE_WIN32_THREADS
439 
440  /* Create a new critical section */
441  if (global_init_lock == NULL) {
442  cs = malloc(sizeof(CRITICAL_SECTION));
443  if (cs == NULL) {
445  "xmlGlobalInitMutexLock: out of memory\n");
446  return;
447  }
449 
450  /* Swap it into the global_init_lock */
451 #ifdef InterlockedCompareExchangePointer
452  InterlockedCompareExchangePointer((void **) &global_init_lock,
453  cs, NULL);
454 #else /* Use older void* version */
455  InterlockedCompareExchange((void **) &global_init_lock,
456  (void *) cs, NULL);
457 #endif /* InterlockedCompareExchangePointer */
458 
459  /* If another thread successfully recorded its critical
460  * section in the global_init_lock then discard the one
461  * allocated by this thread. */
462  if (global_init_lock != cs) {
464  free(cs);
465  }
466  }
467 
468  /* Lock the chosen critical section */
469  EnterCriticalSection(global_init_lock);
470 #elif defined HAVE_BEOS_THREADS
471  int32 sem;
472 
473  /* Allocate a new semaphore */
474  sem = create_sem(1, "xmlGlobalinitMutex");
475 
476  while (global_init_lock == -1) {
477  if (atomic_add(&global_init_count, 1) == 0) {
478  global_init_lock = sem;
479  } else {
480  snooze(1);
481  atomic_add(&global_init_count, -1);
482  }
483  }
484 
485  /* If another thread successfully recorded its critical
486  * section in the global_init_lock then discard the one
487  * allocated by this thread. */
488  if (global_init_lock != sem)
489  delete_sem(sem);
490 
491  /* Acquire the chosen semaphore */
492  if (acquire_sem(global_init_lock) != B_NO_ERROR) {
493 #ifdef DEBUG_THREADS
495  "xmlGlobalInitMutexLock():BeOS:Couldn't acquire semaphore\n");
496 #endif
497  }
498 #endif
499 }
#define free
Definition: debug_ros.c:5
#define InterlockedCompareExchange
Definition: interlocked.h:104
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
uint32_t cs
Definition: isohybrid.c:75
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
smooth NULL
Definition: ftsmooth.c:416
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
static void atomic_add(int volatile i, atomic_t volatile *v)
Definition: atomic.h:43
static HANDLE sem
Definition: sync.c:677
long int32
Definition: platform.h:12
#define malloc
Definition: debug_ros.c:4
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

Referenced by xmlInitParser().

◆ __xmlGlobalInitMutexUnlock()

void __xmlGlobalInitMutexUnlock ( void  )

Definition at line 502 of file threads.c.

503 {
504 #ifdef HAVE_PTHREAD_H
505 #ifdef XML_PTHREAD_WEAK
506  if (pthread_mutex_unlock == NULL)
507  return;
508 #endif /* XML_PTHREAD_WEAK */
509  pthread_mutex_unlock(&global_init_lock);
510 #elif defined HAVE_WIN32_THREADS
511  if (global_init_lock != NULL) {
512  LeaveCriticalSection(global_init_lock);
513  }
514 #elif defined HAVE_BEOS_THREADS
515  release_sem(global_init_lock);
516 #endif
517 }
smooth NULL
Definition: ftsmooth.c:416
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by xmlInitParser().

◆ xmlCleanupThreads()

void xmlCleanupThreads ( void  )

xmlCleanupThreads:

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 908 of file threads.c.

909 {
910 #ifdef DEBUG_THREADS
911  xmlGenericError(xmlGenericErrorContext, "xmlCleanupThreads()\n");
912 #endif
913 #ifdef HAVE_PTHREAD_H
914  if (libxml_is_threaded != 0)
915  pthread_key_delete(globalkey);
916  once_control = once_control_init;
917 #elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
918  if (globalkey != TLS_OUT_OF_INDEXES) {
919  xmlGlobalStateCleanupHelperParams *p;
920 
921  EnterCriticalSection(&cleanup_helpers_cs);
922  p = cleanup_helpers_head;
923  while (p != NULL) {
924  xmlGlobalStateCleanupHelperParams *temp = p;
925 
926  p = p->next;
927  xmlFreeGlobalState(temp->memory);
928  free(temp);
929  }
930  cleanup_helpers_head = 0;
931  LeaveCriticalSection(&cleanup_helpers_cs);
932  TlsFree(globalkey);
933  globalkey = TLS_OUT_OF_INDEXES;
934  }
935  DeleteCriticalSection(&cleanup_helpers_cs);
936 #endif
937 }
#define free
Definition: debug_ros.c:5
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI TlsFree(IN DWORD Index)
Definition: thread.c:1116
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
#define TLS_OUT_OF_INDEXES
Definition: winbase.h:530
static calc_node_t temp
Definition: rpn_ieee.c:38
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
GLfloat GLfloat p
Definition: glext.h:8902
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

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 206 of file threads.c.

207 {
208  if (tok == NULL)
209  return;
210 
211 #ifdef HAVE_PTHREAD_H
212  if (libxml_is_threaded != 0)
213  pthread_mutex_destroy(&tok->lock);
214 #elif defined HAVE_WIN32_THREADS
215  CloseHandle(tok->mutex);
216 #elif defined HAVE_BEOS_THREADS
217  delete_sem(tok->sem);
218 #endif
219  free(tok);
220 }
#define CloseHandle
Definition: compat.h:398
#define free
Definition: debug_ros.c:5
smooth NULL
Definition: ftsmooth.c:416

Referenced by xmlCleanupGlobals(), xmlCleanupMemory(), 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 319 of file threads.c.

320 {
321  if (tok == NULL)
322  return;
323 #ifdef HAVE_PTHREAD_H
324  if (libxml_is_threaded != 0) {
325  pthread_mutex_destroy(&tok->lock);
326  pthread_cond_destroy(&tok->cv);
327  }
328 #elif defined HAVE_WIN32_THREADS
329  DeleteCriticalSection(&tok->cs);
330 #elif defined HAVE_BEOS_THREADS
331  xmlFreeMutex(tok->lock);
332 #endif
333  free(tok);
334 }
#define free
Definition: debug_ros.c:5
smooth NULL
Definition: ftsmooth.c:416
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
void xmlFreeMutex(xmlMutexPtr tok)
Definition: threads.c:206

Referenced by xmlDictCleanup(), and 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 654 of file threads.c.

655 {
656 #ifdef HAVE_PTHREAD_H
657  xmlGlobalState *globalval;
658 
659  if (libxml_is_threaded == 0)
660  return (NULL);
661 
662  pthread_once(&once_control, xmlOnceInit);
663 
664  if ((globalval = (xmlGlobalState *)
665  pthread_getspecific(globalkey)) == NULL) {
666  xmlGlobalState *tsd = xmlNewGlobalState();
667  if (tsd == NULL)
668  return(NULL);
669 
670  pthread_setspecific(globalkey, tsd);
671  return (tsd);
672  }
673  return (globalval);
674 #elif defined HAVE_WIN32_THREADS
675 #if defined(HAVE_COMPILER_TLS)
676  if (!tlstate_inited) {
677  tlstate_inited = 1;
678  xmlInitializeGlobalState(&tlstate);
679  }
680  return &tlstate;
681 #else /* HAVE_COMPILER_TLS */
682  xmlGlobalState *globalval;
683  xmlGlobalStateCleanupHelperParams *p;
684 
685  xmlOnceInit();
686 #if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
687  globalval = (xmlGlobalState *) TlsGetValue(globalkey);
688 #else
689  p = (xmlGlobalStateCleanupHelperParams *) TlsGetValue(globalkey);
690  globalval = (xmlGlobalState *) (p ? p->memory : NULL);
691 #endif
692  if (globalval == NULL) {
693  xmlGlobalState *tsd = xmlNewGlobalState();
694 
695  if (tsd == NULL)
696  return(NULL);
697  p = (xmlGlobalStateCleanupHelperParams *)
698  malloc(sizeof(xmlGlobalStateCleanupHelperParams));
699  if (p == NULL) {
701  "xmlGetGlobalState: out of memory\n");
702  xmlFreeGlobalState(tsd);
703  return(NULL);
704  }
705  p->memory = tsd;
706 #if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
708  GetCurrentProcess(), &p->thread, 0, TRUE,
710  TlsSetValue(globalkey, tsd);
711  _beginthread(xmlGlobalStateCleanupHelper, 0, p);
712 #else
713  EnterCriticalSection(&cleanup_helpers_cs);
714  if (cleanup_helpers_head != NULL) {
715  cleanup_helpers_head->prev = p;
716  }
717  p->next = cleanup_helpers_head;
718  p->prev = NULL;
719  cleanup_helpers_head = p;
720  TlsSetValue(globalkey, p);
721  LeaveCriticalSection(&cleanup_helpers_cs);
722 #endif
723 
724  return (tsd);
725  }
726  return (globalval);
727 #endif /* HAVE_COMPILER_TLS */
728 #elif defined HAVE_BEOS_THREADS
729  xmlGlobalState *globalval;
730 
731  xmlOnceInit();
732 
733  if ((globalval = (xmlGlobalState *) tls_get(globalkey)) == NULL) {
734  xmlGlobalState *tsd = xmlNewGlobalState();
735  if (tsd == NULL)
736  return (NULL);
737 
738  tls_set(globalkey, tsd);
739  on_exit_thread(xmlGlobalStateCleanup, NULL);
740  return (tsd);
741  }
742  return (globalval);
743 #else
744  return (NULL);
745 #endif
746 }
#define TRUE
Definition: types.h:120
BOOL WINAPI TlsSetValue(IN DWORD Index, IN LPVOID Value)
Definition: thread.c:1226
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define DUPLICATE_SAME_ACCESS
HANDLE WINAPI GetCurrentThread(VOID)
Definition: proc.c:1178
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
smooth NULL
Definition: ftsmooth.c:416
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1168
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1190
_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:506
#define malloc
Definition: debug_ros.c:4
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
GLfloat GLfloat p
Definition: glext.h:8902
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
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

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 764 of file threads.c.

765 {
766 #ifdef HAVE_PTHREAD_H
767  pthread_t id;
768  int ret;
769 
770  if (libxml_is_threaded == 0)
771  return (0);
772  id = pthread_self();
773  /* horrible but preserves compat, see warning above */
774  memcpy(&ret, &id, sizeof(ret));
775  return (ret);
776 #elif defined HAVE_WIN32_THREADS
777  return GetCurrentThreadId();
778 #elif defined HAVE_BEOS_THREADS
779  return find_thread(NULL);
780 #else
781  return ((int) 0);
782 #endif
783 }
smooth NULL
Definition: ftsmooth.c:416
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition: utils.c:41
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:420
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLuint id
Definition: glext.h:5579

Referenced by xmlInitializeGlobalState().

◆ xmlInitThreads()

void xmlInitThreads ( void  )

xmlInitThreads:

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

Definition at line 858 of file threads.c.

859 {
860 #ifdef HAVE_PTHREAD_H
861 #ifdef XML_PTHREAD_WEAK
862  if (libxml_is_threaded == -1) {
863  if ((pthread_once != NULL) &&
864  (pthread_getspecific != NULL) &&
865  (pthread_setspecific != NULL) &&
866  (pthread_key_create != NULL) &&
867  (pthread_key_delete != NULL) &&
868  (pthread_mutex_init != NULL) &&
869  (pthread_mutex_destroy != NULL) &&
870  (pthread_mutex_lock != NULL) &&
871  (pthread_mutex_unlock != NULL) &&
872  (pthread_cond_init != NULL) &&
873  (pthread_cond_destroy != NULL) &&
874  (pthread_cond_wait != NULL) &&
875  (pthread_equal != NULL) &&
876  (pthread_self != NULL) &&
877  (pthread_cond_signal != NULL)) {
878  libxml_is_threaded = 1;
879 
880 /* fprintf(stderr, "Running multithreaded\n"); */
881  } else {
882 
883 /* fprintf(stderr, "Running without multithread\n"); */
884  libxml_is_threaded = 0;
885  }
886  }
887 #endif /* XML_PTHREAD_WEAK */
888 #elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
889  InitializeCriticalSection(&cleanup_helpers_cs);
890 #endif
891 }
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
smooth NULL
Definition: ftsmooth.c:416

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 793 of file threads.c.

794 {
795 #ifdef HAVE_PTHREAD_H
796  if (libxml_is_threaded == -1)
797  xmlInitThreads();
798  if (libxml_is_threaded == 0)
799  return (1);
800  pthread_once(&once_control, xmlOnceInit);
801 #elif defined HAVE_WIN32_THREADS
802  xmlOnceInit();
803 #elif defined HAVE_BEOS_THREADS
804  xmlOnceInit();
805 #endif
806 
807 #ifdef DEBUG_THREADS
808  xmlGenericError(xmlGenericErrorContext, "xmlIsMainThread()\n");
809 #endif
810 #ifdef HAVE_PTHREAD_H
811  return (pthread_equal(mainthread,pthread_self()));
812 #elif defined HAVE_WIN32_THREADS
813  return (mainthread == GetCurrentThreadId());
814 #elif defined HAVE_BEOS_THREADS
815  return (mainthread == find_thread(NULL));
816 #else
817  return (1);
818 #endif
819 }
void xmlInitThreads(void)
Definition: threads.c:858
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
smooth NULL
Definition: ftsmooth.c:416
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition: utils.c:41
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:420
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

◆ xmlLockLibrary()

void xmlLockLibrary ( void  )

xmlLockLibrary:

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

Definition at line 828 of file threads.c.

829 {
830 #ifdef DEBUG_THREADS
831  xmlGenericError(xmlGenericErrorContext, "xmlLockLibrary()\n");
832 #endif
834 }
void xmlRMutexLock(xmlRMutexPtr tok)
Definition: threads.c:343
static xmlRMutexPtr xmlLibraryLock
Definition: threads.c:162
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

◆ xmlMutexLock()

void xmlMutexLock ( xmlMutexPtr  tok)

xmlMutexLock: @tok: the simple mutex

xmlMutexLock() is used to lock a libxml2 token.

Definition at line 229 of file threads.c.

230 {
231  if (tok == NULL)
232  return;
233 #ifdef HAVE_PTHREAD_H
234  if (libxml_is_threaded != 0)
235  pthread_mutex_lock(&tok->lock);
236 #elif defined HAVE_WIN32_THREADS
237  WaitForSingleObject(tok->mutex, INFINITE);
238 #elif defined HAVE_BEOS_THREADS
239  if (acquire_sem(tok->sem) != B_NO_ERROR) {
240 #ifdef DEBUG_THREADS
242  "xmlMutexLock():BeOS:Couldn't aquire semaphore\n");
243 #endif
244  }
245  tok->tid = find_thread(NULL);
246 #endif
247 
248 }
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
smooth NULL
Definition: ftsmooth.c:416
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition: utils.c:41
#define INFINITE
Definition: serial.h:102
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

Referenced by 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 257 of file threads.c.

258 {
259  if (tok == NULL)
260  return;
261 #ifdef HAVE_PTHREAD_H
262  if (libxml_is_threaded != 0)
263  pthread_mutex_unlock(&tok->lock);
264 #elif defined HAVE_WIN32_THREADS
265  ReleaseMutex(tok->mutex);
266 #elif defined HAVE_BEOS_THREADS
267  if (tok->tid == find_thread(NULL)) {
268  tok->tid = -1;
269  release_sem(tok->sem);
270  }
271 #endif
272 }
smooth NULL
Definition: ftsmooth.c:416
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition: utils.c:41
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:564

Referenced by 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 177 of file threads.c.

178 {
179  xmlMutexPtr tok;
180 
181  if ((tok = malloc(sizeof(xmlMutex))) == NULL)
182  return (NULL);
183 #ifdef HAVE_PTHREAD_H
184  if (libxml_is_threaded != 0)
185  pthread_mutex_init(&tok->lock, NULL);
186 #elif defined HAVE_WIN32_THREADS
187  tok->mutex = CreateMutex(NULL, FALSE, NULL);
188 #elif defined HAVE_BEOS_THREADS
189  if ((tok->sem = create_sem(1, "xmlMutex")) < B_OK) {
190  free(tok);
191  return NULL;
192  }
193  tok->tid = -1;
194 #endif
195  return (tok);
196 }
#define free
Definition: debug_ros.c:5
smooth NULL
Definition: ftsmooth.c:416
#define CreateMutex
Definition: winbase.h:3570
#define malloc
Definition: debug_ros.c:4

Referenced by 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 285 of file threads.c.

286 {
287  xmlRMutexPtr tok;
288 
289  if ((tok = malloc(sizeof(xmlRMutex))) == NULL)
290  return (NULL);
291 #ifdef HAVE_PTHREAD_H
292  if (libxml_is_threaded != 0) {
293  pthread_mutex_init(&tok->lock, NULL);
294  tok->held = 0;
295  tok->waiters = 0;
296  pthread_cond_init(&tok->cv, NULL);
297  }
298 #elif defined HAVE_WIN32_THREADS
299  InitializeCriticalSection(&tok->cs);
300  tok->count = 0;
301 #elif defined HAVE_BEOS_THREADS
302  if ((tok->lock = xmlNewMutex()) == NULL) {
303  free(tok);
304  return NULL;
305  }
306  tok->count = 0;
307 #endif
308  return (tok);
309 }
#define free
Definition: debug_ros.c:5
xmlMutexPtr xmlNewMutex(void)
Definition: threads.c:177
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
smooth NULL
Definition: ftsmooth.c:416
#define malloc
Definition: debug_ros.c:4

Referenced by __xmlInitializeDict(), and xsltInit().

◆ xmlRMutexLock()

void xmlRMutexLock ( xmlRMutexPtr  tok)

xmlRMutexLock: @tok: the reentrant mutex

xmlRMutexLock() is used to lock a libxml2 token_r.

Definition at line 343 of file threads.c.

344 {
345  if (tok == NULL)
346  return;
347 #ifdef HAVE_PTHREAD_H
348  if (libxml_is_threaded == 0)
349  return;
350 
351  pthread_mutex_lock(&tok->lock);
352  if (tok->held) {
353  if (pthread_equal(tok->tid, pthread_self())) {
354  tok->held++;
355  pthread_mutex_unlock(&tok->lock);
356  return;
357  } else {
358  tok->waiters++;
359  while (tok->held)
360  pthread_cond_wait(&tok->cv, &tok->lock);
361  tok->waiters--;
362  }
363  }
364  tok->tid = pthread_self();
365  tok->held = 1;
366  pthread_mutex_unlock(&tok->lock);
367 #elif defined HAVE_WIN32_THREADS
368  EnterCriticalSection(&tok->cs);
369  tok->count++;
370 #elif defined HAVE_BEOS_THREADS
371  if (tok->lock->tid == find_thread(NULL)) {
372  tok->count++;
373  return;
374  } else {
375  xmlMutexLock(tok->lock);
376  tok->count = 1;
377  }
378 #endif
379 }
void xmlMutexLock(xmlMutexPtr tok)
Definition: threads.c:229
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
smooth NULL
Definition: ftsmooth.c:416
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition: utils.c:41

Referenced by __xmlInitializeDict(), __xmlRandom(), xmlDictFree(), xmlDictReference(), 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 388 of file threads.c.

389 {
390  if (tok == NULL)
391  return;
392 #ifdef HAVE_PTHREAD_H
393  if (libxml_is_threaded == 0)
394  return;
395 
396  pthread_mutex_lock(&tok->lock);
397  tok->held--;
398  if (tok->held == 0) {
399  if (tok->waiters)
400  pthread_cond_signal(&tok->cv);
401  memset(&tok->tid, 0, sizeof(tok->tid));
402  }
403  pthread_mutex_unlock(&tok->lock);
404 #elif defined HAVE_WIN32_THREADS
405  if (tok->count > 0) {
406  tok->count--;
407  LeaveCriticalSection(&tok->cs);
408  }
409 #elif defined HAVE_BEOS_THREADS
410  if (tok->lock->tid == find_thread(NULL)) {
411  tok->count--;
412  if (tok->count == 0) {
413  xmlMutexUnlock(tok->lock);
414  }
415  return;
416  }
417 #endif
418 }
smooth NULL
Definition: ftsmooth.c:416
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition: utils.c:41
void xmlMutexUnlock(xmlMutexPtr tok)
Definition: threads.c:257
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define memset(x, y, z)
Definition: compat.h:39

Referenced by __xmlInitializeDict(), __xmlRandom(), xmlDictFree(), xmlDictReference(), xmlUnlockLibrary(), and xsltFreeLocales().

◆ xmlUnlockLibrary()

void xmlUnlockLibrary ( void  )

xmlUnlockLibrary:

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

Definition at line 843 of file threads.c.

844 {
845 #ifdef DEBUG_THREADS
846  xmlGenericError(xmlGenericErrorContext, "xmlUnlockLibrary()\n");
847 #endif
849 }
static xmlRMutexPtr xmlLibraryLock
Definition: threads.c:162
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
void xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
Definition: threads.c:388
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

Variable Documentation

◆ xmlLibraryLock

xmlRMutexPtr xmlLibraryLock = NULL
static

Definition at line 162 of file threads.c.

Referenced by xmlLockLibrary(), and xmlUnlockLibrary().