mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
patch from Gary Pennington fixing a possible problem at initialization
* threads.c: patch from Gary Pennington fixing a possible problem at initialization time. Daniel
This commit is contained in:
@ -1,7 +1,12 @@
|
|||||||
|
Thu Dec 6 09:06:08 EST 2001 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* threads.c: patch from Gary Pennington fixing a possible
|
||||||
|
problem at initialization time.
|
||||||
|
|
||||||
Wed Dec 5 13:01:37 CET 2001 Daniel Veillard <daniel@veillard.com>
|
Wed Dec 5 13:01:37 CET 2001 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
* configure.in libxml.h parser.c testThreads.c macos/: integrated
|
* configure.in libxml.h parser.c testThreads.c macos/: integrated
|
||||||
Eric Lavigne (sp???) contribution to build libxml2 on MacOS using
|
Eric Lavigne contribution to build libxml2 on MacOS using
|
||||||
CodeWarrior.
|
CodeWarrior.
|
||||||
|
|
||||||
Tue Dec 4 14:13:44 CET 2001 Daniel Veillard <daniel@veillard.com>
|
Tue Dec 4 14:13:44 CET 2001 Daniel Veillard <daniel@veillard.com>
|
||||||
|
62
threads.c
62
threads.c
@ -68,22 +68,15 @@ struct _xmlRMutex {
|
|||||||
* This module still has some internal static data.
|
* This module still has some internal static data.
|
||||||
* - xmlLibraryLock a global lock
|
* - xmlLibraryLock a global lock
|
||||||
* - globalkey used for per-thread data
|
* - globalkey used for per-thread data
|
||||||
* - keylock protecting globalkey
|
|
||||||
* - keyonce to mark initialization of globalkey
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int initialized = 0;
|
|
||||||
#ifdef HAVE_PTHREAD_H
|
#ifdef HAVE_PTHREAD_H
|
||||||
static pthread_mutex_t keylock = PTHREAD_MUTEX_INITIALIZER;
|
|
||||||
static pthread_key_t globalkey;
|
static pthread_key_t globalkey;
|
||||||
static int keyonce = 0;
|
|
||||||
static pthread_t mainthread;
|
static pthread_t mainthread;
|
||||||
|
static pthread_once_t once_control = PTHREAD_ONCE_INIT;
|
||||||
#endif
|
#endif
|
||||||
static xmlRMutexPtr xmlLibraryLock = NULL;
|
static xmlRMutexPtr xmlLibraryLock = NULL;
|
||||||
|
static void xmlOnceInit(void);
|
||||||
#if defined(SOLARIS)
|
|
||||||
NOTE(DATA_READABLE_WITHOUT_LOCK(keyonce))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlMutexPtr:
|
* xmlMutexPtr:
|
||||||
@ -291,11 +284,6 @@ xmlNewGlobalState(void)
|
|||||||
* xmlGetGlobalState:
|
* xmlGetGlobalState:
|
||||||
*
|
*
|
||||||
* xmlGetGlobalState() is called to retrieve the global state for a thread.
|
* xmlGetGlobalState() is called to retrieve the global state for a thread.
|
||||||
* keyonce will only be set once during a library invocation and is used
|
|
||||||
* to create globalkey, the key used to store each thread's TSD.
|
|
||||||
*
|
|
||||||
* Note: it should not be called for the "main" thread as this thread uses
|
|
||||||
* the existing global variables defined in the library.
|
|
||||||
*
|
*
|
||||||
* Returns the thread global state or NULL in case of error
|
* Returns the thread global state or NULL in case of error
|
||||||
*/
|
*/
|
||||||
@ -305,14 +293,8 @@ xmlGetGlobalState(void)
|
|||||||
#ifdef HAVE_PTHREAD_H
|
#ifdef HAVE_PTHREAD_H
|
||||||
xmlGlobalState *globalval;
|
xmlGlobalState *globalval;
|
||||||
|
|
||||||
if (keyonce == 0) {
|
pthread_once(&once_control, xmlOnceInit);
|
||||||
(void) pthread_mutex_lock(&keylock);
|
|
||||||
if (keyonce == 0) {
|
|
||||||
keyonce++;
|
|
||||||
(void) pthread_key_create(&globalkey, xmlFreeGlobalState);
|
|
||||||
}
|
|
||||||
(void) pthread_mutex_unlock(&keylock);
|
|
||||||
}
|
|
||||||
if ((globalval = (xmlGlobalState *)
|
if ((globalval = (xmlGlobalState *)
|
||||||
pthread_getspecific(globalkey)) == NULL) {
|
pthread_getspecific(globalkey)) == NULL) {
|
||||||
xmlGlobalState *tsd = xmlNewGlobalState();
|
xmlGlobalState *tsd = xmlNewGlobalState();
|
||||||
@ -360,8 +342,9 @@ xmlGetThreadId(void)
|
|||||||
int
|
int
|
||||||
xmlIsMainThread(void)
|
xmlIsMainThread(void)
|
||||||
{
|
{
|
||||||
if (!initialized)
|
#ifdef HAVE_PTHREAD_H
|
||||||
xmlInitThreads();
|
pthread_once(&once_control, xmlOnceInit);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG_THREADS
|
#ifdef DEBUG_THREADS
|
||||||
xmlGenericError(xmlGenericErrorContext, "xmlIsMainThread()\n");
|
xmlGenericError(xmlGenericErrorContext, "xmlIsMainThread()\n");
|
||||||
@ -412,18 +395,9 @@ xmlUnlockLibrary(void)
|
|||||||
void
|
void
|
||||||
xmlInitThreads(void)
|
xmlInitThreads(void)
|
||||||
{
|
{
|
||||||
if (initialized != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
#ifdef DEBUG_THREADS
|
#ifdef DEBUG_THREADS
|
||||||
xmlGenericError(xmlGenericErrorContext, "xmlInitThreads()\n");
|
xmlGenericError(xmlGenericErrorContext, "xmlInitThreads()\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_PTHREAD_H
|
|
||||||
mainthread = pthread_self();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
initialized = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -435,12 +409,24 @@ xmlInitThreads(void)
|
|||||||
void
|
void
|
||||||
xmlCleanupThreads(void)
|
xmlCleanupThreads(void)
|
||||||
{
|
{
|
||||||
if (initialized == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
#ifdef DEBUG_THREADS
|
#ifdef DEBUG_THREADS
|
||||||
xmlGenericError(xmlGenericErrorContext, "xmlCleanupThreads()\n");
|
xmlGenericError(xmlGenericErrorContext, "xmlCleanupThreads()\n");
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
initialized = 0;
|
|
||||||
|
/**
|
||||||
|
* xmlOnceInit
|
||||||
|
*
|
||||||
|
* xmlOnceInit() is used to initialize the value of mainthread for use
|
||||||
|
* in other routines. This function should only be called using
|
||||||
|
* pthread_once() in association with the once_control variable to ensure
|
||||||
|
* that the function is only called once. See man pthread_once for more
|
||||||
|
* details.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
xmlOnceInit(void) {
|
||||||
|
#ifdef HAVE_PTHREAD_H
|
||||||
|
(void) pthread_key_create(&globalkey, xmlFreeGlobalState);
|
||||||
|
mainthread = pthread_self();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user