ReactOS  0.4.14-dev-50-g13bb5e2
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)
 
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)
 
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()

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

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 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()

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 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()

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 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:1264
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define DUPLICATE_SAME_ACCESS
HANDLE WINAPI GetCurrentThread(VOID)
Definition: proc.c:1148
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
smooth NULL
Definition: ftsmooth.c:416
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1228
_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()

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 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:458
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLuint id
Definition: glext.h:5579

Referenced by xmlInitializeGlobalState().

◆ xmlInitThreads()

XMLPUBFUN void XMLCALL 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:751
smooth NULL
Definition: ftsmooth.c:416

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 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:458
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

◆ xmlLockLibrary()

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

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

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

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()

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 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:3573
#define malloc
Definition: debug_ros.c:4

Referenced by 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 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:751
smooth NULL
Definition: ftsmooth.c:416
#define malloc
Definition: debug_ros.c:4

Referenced by __xmlInitializeDict(), and 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 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()

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 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()

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