Re: [xml] windows multi-threading
- From: Rob Richards <rrichards ctindustries net>
- To: Rich Salz <rsalz datapower com>
- Cc: "xml gnome org" <xml gnome org>, "veillard redhat com" <veillard redhat com>
- Subject: Re: [xml] windows multi-threading
- Date: Thu, 24 Feb 2005 12:25:55 -0500
Here's the revised patch.
Rob
Rich Salz wrote:
Both fixes are correct. (I thought II returned the old value)
Can you post a revised patch so Daniel can commit it?
thanks for debugging my code. :)
Index: threads.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/threads.c,v
retrieving revision 1.29
diff -c -r1.29 threads.c
*** threads.c 22 Oct 2004 13:16:10 -0000 1.29
--- threads.c 24 Feb 2005 17:13:47 -0000
***************
*** 107,113 ****
static DWORD globalkey = TLS_OUT_OF_INDEXES;
#endif /* HAVE_COMPILER_TLS */
static DWORD mainthread;
! static int run_once_init = 1;
/* endif HAVE_WIN32_THREADS */
#elif defined HAVE_BEOS_THREADS
int32 globalkey = 0;
--- 107,117 ----
static DWORD globalkey = TLS_OUT_OF_INDEXES;
#endif /* HAVE_COMPILER_TLS */
static DWORD mainthread;
! static struct
! {
! DWORD done;
! DWORD control;
! } run_once = { 0, 0 };
/* endif HAVE_WIN32_THREADS */
#elif defined HAVE_BEOS_THREADS
int32 globalkey = 0;
***************
*** 487,496 ****
xmlGlobalState *globalval;
xmlGlobalStateCleanupHelperParams * p;
! if (run_once_init) {
! run_once_init = 0;
! xmlOnceInit();
! }
#if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
globalval = (xmlGlobalState *)TlsGetValue(globalkey);
#else
--- 491,497 ----
xmlGlobalState *globalval;
xmlGlobalStateCleanupHelperParams * p;
! xmlOnceInit();
#if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
globalval = (xmlGlobalState *)TlsGetValue(globalkey);
#else
***************
*** 581,592 ****
#ifdef HAVE_PTHREAD_H
pthread_once(&once_control, xmlOnceInit);
#elif defined HAVE_WIN32_THREADS
! if (run_once_init) {
! run_once_init = 0;
! xmlOnceInit ();
! }
#elif defined HAVE_BEOS_THREADS
! xmlOnceInit();
#endif
#ifdef DEBUG_THREADS
--- 582,590 ----
#ifdef HAVE_PTHREAD_H
pthread_once(&once_control, xmlOnceInit);
#elif defined HAVE_WIN32_THREADS
! xmlOnceInit ();
#elif defined HAVE_BEOS_THREADS
! xmlOnceInit();
#endif
#ifdef DEBUG_THREADS
***************
*** 700,709 ****
#endif
#if defined(HAVE_WIN32_THREADS)
#if !defined(HAVE_COMPILER_TLS)
! globalkey = TlsAlloc();
#endif
! mainthread = GetCurrentThreadId();
#endif
#ifdef HAVE_BEOS_THREADS
--- 698,719 ----
#endif
#if defined(HAVE_WIN32_THREADS)
+ if (!run_once.done) {
+ if (InterlockedIncrement(&run_once.control) == 1)
+ {
#if !defined(HAVE_COMPILER_TLS)
! globalkey = TlsAlloc();
#endif
! mainthread = GetCurrentThreadId();
! run_once.done = 1;
! }
! else {
! /* Another thread is working; give up our slice and
! * wait until they're done. */
! while (!run_once.done)
! Sleep(0);
! }
! }
#endif
#ifdef HAVE_BEOS_THREADS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]