ReactOS 0.4.16-dev-2132-g3885311
threads.h File Reference
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 int xmlCheckThreadLocalStorage (void)
 
XMLPUBFUN xmlMutexPtr xmlNewMutex (void)
 
XMLPUBFUN void xmlMutexLock (xmlMutexPtr tok)
 
XMLPUBFUN void xmlMutexUnlock (xmlMutexPtr tok)
 
XMLPUBFUN void xmlFreeMutex (xmlMutexPtr tok)
 
XMLPUBFUN xmlRMutexPtr xmlNewRMutex (void)
 
XMLPUBFUN void xmlRMutexLock (xmlRMutexPtr tok)
 
XMLPUBFUN void xmlRMutexUnlock (xmlRMutexPtr tok)
 
XMLPUBFUN void xmlFreeRMutex (xmlRMutexPtr tok)
 
XML_DEPRECATED XMLPUBFUN void xmlInitThreads (void)
 
XMLPUBFUN void xmlLockLibrary (void)
 
XMLPUBFUN void xmlUnlockLibrary (void)
 
XML_DEPRECATED XMLPUBFUN int xmlGetThreadId (void)
 
XML_DEPRECATED XMLPUBFUN int xmlIsMainThread (void)
 
XML_DEPRECATED XMLPUBFUN void xmlCleanupThreads (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

◆ xmlCheckThreadLocalStorage()

XMLPUBFUN int xmlCheckThreadLocalStorage ( void  )

xmlCheckThreadLocalStorage:

Check whether thread-local storage could be allocated.

In cross-platform code running in multithreaded environments, this function should be called once in each thread before calling other library functions to make sure that thread-local storage was allocated properly.

Returns 0 on success or -1 if a memory allocation failed. A failed allocation signals a typically fatal and irrecoverable out-of-memory situation. Don't call any library functions in this case.

This function never fails if the library is compiled with support for thread-local storage.

This function never fails for the "main" thread which is the first thread calling xmlInitParser.

Available since v2.12.0.

Definition at line 945 of file globals.c.

945 {
946#if defined(LIBXML_THREAD_ENABLED) && !defined(USE_TLS)
947 if ((!xmlIsMainThreadInternal()) && (xmlGetThreadLocalStorage(1) == NULL))
948 return(-1);
949#endif
950 return(0);
951}
#define NULL
Definition: types.h:112
static int xmlIsMainThreadInternal(void)
Definition: globals.c:665

◆ xmlCleanupThreads()

XML_DEPRECATED XMLPUBFUN void xmlCleanupThreads ( void  )

xmlCleanupThreads:

DEPRECATED: This function is a no-op. 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.

Definition at line 435 of file threads.c.

436{
437}

◆ xmlFreeMutex()

XMLPUBFUN void xmlFreeMutex ( xmlMutexPtr  tok)

xmlFreeMutex: @tok: the simple mutex

Free a mutex.

Definition at line 185 of file threads.c.

186{
187 if (tok == NULL)
188 return;
189
190 xmlCleanupMutex(tok);
191 free(tok);
192}
#define free
Definition: debug_ros.c:5
void xmlCleanupMutex(xmlMutexPtr mutex)
Definition: threads.c:166

Referenced by xsltCleanupGlobals().

◆ xmlFreeRMutex()

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

276{
277 if (tok == NULL)
278 return;
279#ifdef HAVE_POSIX_THREADS
280 if (XML_IS_NEVER_THREADED() == 0) {
281 pthread_mutex_destroy(&tok->lock);
282 pthread_cond_destroy(&tok->cv);
283 }
284#elif defined HAVE_WIN32_THREADS
285 DeleteCriticalSection(&tok->cs);
286#endif
287 free(tok);
288}
#define XML_IS_NEVER_THREADED()
Definition: threads.c:92
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

Referenced by xsltUninit().

◆ xmlGetThreadId()

XML_DEPRECATED XMLPUBFUN int xmlGetThreadId ( void  )

xmlGetThreadId:

DEPRECATED: Internal function, do not use.

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

373{
374#ifdef HAVE_POSIX_THREADS
375 pthread_t id;
376 int ret;
377
378 if (XML_IS_THREADED() == 0)
379 return (0);
380 id = pthread_self();
381 /* horrible but preserves compat, see warning above */
382 memcpy(&ret, &id, sizeof(ret));
383 return (ret);
384#elif defined HAVE_WIN32_THREADS
385 return GetCurrentThreadId();
386#else
387 return ((int) 0);
388#endif
389}
return ret
Definition: mutex.c:146
GLuint id
Definition: glext.h:5910
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define XML_IS_THREADED()
Definition: threads.c:91
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459

◆ xmlInitThreads()

XML_DEPRECATED XMLPUBFUN void xmlInitThreads ( void  )

xmlInitThreads:

DEPRECATED: Alias for xmlInitParser.

Definition at line 421 of file threads.c.

422{
424}
void xmlInitParser(void)
Definition: threads.c:569

◆ xmlIsMainThread()

XML_DEPRECATED XMLPUBFUN int xmlIsMainThread ( void  )

xmlIsMainThread:

DEPRECATED: Internal function, do not use.

Check whether the current thread is the main thread.

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

Definition at line 694 of file globals.c.

694 {
695 return(xmlIsMainThreadInternal());
696}

◆ xmlLockLibrary()

XMLPUBFUN void xmlLockLibrary ( void  )

xmlLockLibrary:

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

Definition at line 398 of file threads.c.

399{
401}
static xmlRMutexPtr xmlLibraryLock
Definition: threads.c:119
void xmlRMutexLock(xmlRMutexPtr tok)
Definition: threads.c:297

◆ xmlMutexLock()

XMLPUBFUN void xmlMutexLock ( xmlMutexPtr  tok)

xmlMutexLock: @tok: the simple mutex

xmlMutexLock() is used to lock a libxml2 token.

Definition at line 201 of file threads.c.

202{
203 if (tok == NULL)
204 return;
205#ifdef HAVE_POSIX_THREADS
206 /*
207 * This assumes that __libc_single_threaded won't change while the
208 * lock is held.
209 */
210 if (XML_IS_THREADED() != 0)
211 pthread_mutex_lock(&tok->lock);
212#elif defined HAVE_WIN32_THREADS
213 EnterCriticalSection(&tok->cs);
214#endif
215
216}
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

Referenced by xmlDictFree(), xmlDictReference(), xmlMallocAtomicLoc(), xmlMallocLoc(), xmlMemBlocks(), xmlMemDisplay(), xmlMemDisplayLast(), xmlMemFree(), xmlMemShow(), xmlMemStrdupLoc(), xmlRandom(), xmlReallocLoc(), xmlThrDefBufferAllocScheme(), xmlThrDefDefaultBufferSize(), xmlThrDefDeregisterNodeDefault(), xmlThrDefDoValidityCheckingDefaultValue(), xmlThrDefGetWarningsDefaultValue(), xmlThrDefKeepBlanksDefaultValue(), xmlThrDefLineNumbersDefaultValue(), xmlThrDefLoadExtDtdDefaultValue(), xmlThrDefOutputBufferCreateFilenameDefault(), xmlThrDefParserDebugEntities(), xmlThrDefParserInputBufferCreateFilenameDefault(), xmlThrDefPedanticParserDefaultValue(), xmlThrDefRegisterNodeDefault(), xmlThrDefSetGenericErrorFunc(), xmlThrDefSetStructuredErrorFunc(), xmlThrDefSubstituteEntitiesDefaultValue(), 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 xmlMutexUnlock ( xmlMutexPtr  tok)

xmlMutexUnlock: @tok: the simple mutex

xmlMutexUnlock() is used to unlock a libxml2 token.

Definition at line 225 of file threads.c.

226{
227 if (tok == NULL)
228 return;
229#ifdef HAVE_POSIX_THREADS
230 if (XML_IS_THREADED() != 0)
231 pthread_mutex_unlock(&tok->lock);
232#elif defined HAVE_WIN32_THREADS
233 LeaveCriticalSection(&tok->cs);
234#endif
235}
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by xmlDictFree(), xmlDictReference(), xmlMallocAtomicLoc(), xmlMallocLoc(), xmlMemBlocks(), xmlMemDisplay(), xmlMemDisplayLast(), xmlMemFree(), xmlMemShow(), xmlMemStrdupLoc(), xmlRandom(), xmlReallocLoc(), xmlThrDefBufferAllocScheme(), xmlThrDefDefaultBufferSize(), xmlThrDefDeregisterNodeDefault(), xmlThrDefDoValidityCheckingDefaultValue(), xmlThrDefGetWarningsDefaultValue(), xmlThrDefKeepBlanksDefaultValue(), xmlThrDefLineNumbersDefaultValue(), xmlThrDefLoadExtDtdDefaultValue(), xmlThrDefOutputBufferCreateFilenameDefault(), xmlThrDefParserDebugEntities(), xmlThrDefParserInputBufferCreateFilenameDefault(), xmlThrDefPedanticParserDefaultValue(), xmlThrDefRegisterNodeDefault(), xmlThrDefSetGenericErrorFunc(), xmlThrDefSetStructuredErrorFunc(), xmlThrDefSubstituteEntitiesDefaultValue(), 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 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 149 of file threads.c.

150{
151 xmlMutexPtr tok;
152
153 if ((tok = malloc(sizeof(xmlMutex))) == NULL)
154 return (NULL);
155 xmlInitMutex(tok);
156 return (tok);
157}
#define malloc
Definition: debug_ros.c:4
void xmlInitMutex(xmlMutexPtr mutex)
Definition: threads.c:128

Referenced by xsltInitGlobals().

◆ xmlNewRMutex()

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

249{
250 xmlRMutexPtr tok;
251
252 if ((tok = malloc(sizeof(xmlRMutex))) == NULL)
253 return (NULL);
254#ifdef HAVE_POSIX_THREADS
255 if (XML_IS_NEVER_THREADED() == 0) {
256 pthread_mutex_init(&tok->lock, NULL);
257 tok->held = 0;
258 tok->waiters = 0;
259 pthread_cond_init(&tok->cv, NULL);
260 }
261#elif defined HAVE_WIN32_THREADS
263#endif
264 return (tok);
265}
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751

Referenced by xsltInit().

◆ xmlRMutexLock()

XMLPUBFUN void xmlRMutexLock ( xmlRMutexPtr  tok)

xmlRMutexLock: @tok: the reentrant mutex

xmlRMutexLock() is used to lock a libxml2 token_r.

Definition at line 297 of file threads.c.

298{
299 if (tok == NULL)
300 return;
301#ifdef HAVE_POSIX_THREADS
302 if (XML_IS_THREADED() == 0)
303 return;
304
305 pthread_mutex_lock(&tok->lock);
306 if (tok->held) {
307 if (pthread_equal(tok->tid, pthread_self())) {
308 tok->held++;
309 pthread_mutex_unlock(&tok->lock);
310 return;
311 } else {
312 tok->waiters++;
313 while (tok->held)
314 pthread_cond_wait(&tok->cv, &tok->lock);
315 tok->waiters--;
316 }
317 }
318 tok->tid = pthread_self();
319 tok->held = 1;
320 pthread_mutex_unlock(&tok->lock);
321#elif defined HAVE_WIN32_THREADS
322 EnterCriticalSection(&tok->cs);
323#endif
324}

Referenced by xmlLockLibrary(), and xsltFreeLocales().

◆ xmlRMutexUnlock()

XMLPUBFUN void xmlRMutexUnlock ( xmlRMutexPtr tok  ATTRIBUTE_UNUSED)

xmlRMutexUnlock: @tok: the reentrant mutex

xmlRMutexUnlock() is used to unlock a libxml2 token_r.

Definition at line 333 of file threads.c.

334{
335 if (tok == NULL)
336 return;
337#ifdef HAVE_POSIX_THREADS
338 if (XML_IS_THREADED() == 0)
339 return;
340
341 pthread_mutex_lock(&tok->lock);
342 tok->held--;
343 if (tok->held == 0) {
344 if (tok->waiters)
345 pthread_cond_signal(&tok->cv);
346 memset(&tok->tid, 0, sizeof(tok->tid));
347 }
348 pthread_mutex_unlock(&tok->lock);
349#elif defined HAVE_WIN32_THREADS
350 LeaveCriticalSection(&tok->cs);
351#endif
352}
#define memset(x, y, z)
Definition: compat.h:39

Referenced by xmlUnlockLibrary(), and xsltFreeLocales().

◆ xmlUnlockLibrary()

XMLPUBFUN void xmlUnlockLibrary ( void  )

xmlUnlockLibrary:

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

Definition at line 410 of file threads.c.

411{
413}
void xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
Definition: threads.c:333