I've attached to this message a slightly updated version of my patch to
provide support for sproc() based multiprocessing under IRIX.  Since I
have to support a library and applications that require this support,
I'd really like to see this support integrated into the xerces-c
repository.  

If any commiters interested in the platform-specific code would like to
apply this patch, or have concerns about it they'd like addressed,
please let me know.

The patch does not change the default behavior of the library under IRIX
in any way; it simply adds another threading option in runConfigure.

For the curious, sproc is an IRIX variant of fork() which creates
separate processes that use a shared memory space.  It is used by many
important IRIX software packages, including most versions of OpenGL
Performer.  It is, unfortunately, completely incompatible with pthreads
- including the pthreads mutexes in IRIXPlatformUtils.cpp.

The patch replaces the pthread-based mutex code in IRIXPlatformUtils
with equivalent code using usinitsema() and related functions.  I have
been using this version for several weeks and it appears to be quite
stable.  The patch is against the current CVS of xerces.

--
Christopher [EMAIL PROTECTED]
                                 http://www.public.iastate.edu/~coronax
"Let us not go gently to the endless winter night"
                              -Rush
diff -u -r -x CVS xml-xerces/c/src/runConfigure my-xml-xerces/c/src/runConfigure
--- xml-xerces/c/src/runConfigure       Wed Jul 25 16:33:55 2001
+++ my-xml-xerces/c/src/runConfigure    Tue Aug 28 11:42:24 2001
@@ -86,7 +86,7 @@
     echo "       -m <message loader> can be 'inmem', 'icu', 'MsgFile' or 'iconv'"
     echo "       -n <net accessor> can be 'fileonly', 'libwww', 'socket' or 'native'"
     echo "       -t <transcoder> can be 'icu', 'Iconv400', 'Iconv390' or 'native'"
-    echo "       -r <thread option> can be 'pthread' or 'dce' (only used on aix, 
HP-11 and solaris) or 'none'"
+    echo "       -r <thread option> can be 'pthread' or 'dce' (only used on aix, 
+HP-11 and solaris) or 'sproc' (only on IRIX) or 'none'"
     echo "       -l <extra linker options>"
     echo "       -z <extra compiler options>"
     echo "       -P <install-prefix>"
@@ -313,6 +313,20 @@
            *)
                echo "I do not recognize the thread option '$thread'. Please type 
'${0} -h' for help."
                exit ${ERROR_EXIT_CODE};;
+        esac
+        fi
+    elif test $platform = "irix"; then
+        if test $thread; then
+        case $thread in
+        pthread)
+            ;;
+
+        sproc)
+            threadingLibs=" ";
+            threadingDefines="-DXML_USE_SPROC" ;;
+        *)
+           echo "I do not recognize the thread option '$thread'. Please type '${0} 
+-h' for help."
+            exit ${ERROR_EXIT_CODE};;
         esac
         fi
     fi
diff -u -r -x CVS xml-xerces/c/src/util/Platforms/IRIX/IRIXPlatformUtils.cpp 
my-xml-xerces/c/src/util/Platforms/IRIX/IRIXPlatformUtils.cpp
--- xml-xerces/c/src/util/Platforms/IRIX/IRIXPlatformUtils.cpp  Wed Jul 25 16:03:17 
2001
+++ my-xml-xerces/c/src/util/Platforms/IRIX/IRIXPlatformUtils.cpp       Tue Aug 28 
+11:42:39 2001
@@ -105,8 +105,12 @@
 // ---------------------------------------------------------------------------
 
 #if !defined(APP_NO_THREADS)
+#ifdef XML_USE_SPROC
+#include    <ulocks.h>
+#else
 #include    <pthread.h>
 #endif
+#endif
 
 #include    <unistd.h>
 #include    <stdio.h>
@@ -537,6 +541,102 @@
 
 #if !defined(APP_NO_THREADS)
 
+static XMLMutex atomicOpsMutex;
+
+#ifdef XML_USE_SPROC
+// ---------------------------------------------------------------------------
+//  XMLPlatformUtils: Platform init method
+// ---------------------------------------------------------------------------
+
+static char* arenaName = 0;
+static usptr_t* arena = 0;
+
+void XMLPlatformUtils::platformInit()
+{
+    //
+    // The atomicOps mutex needs to be created early.
+    // Normally, mutexes are created on first use, but there is a
+    // circular dependency between compareAndExchange() and
+    // mutex creation that must be broken.
+
+    // need a shared memory space
+    usconfig(CONF_INITUSERS, 128);
+    usconfig(CONF_INITSIZE, 16000);
+    usconfig(CONF_AUTOGROW, 1);   // Default, but we set anyway
+
+    arenaName = strdup ("/var/tmp/xerces-sharedmemXXXXXX");
+    arena = usinit (mktemp (arenaName));
+
+    atomicOpsMutex.fHandle = XMLPlatformUtils::makeMutex();
+}
+
+void XMLPlatformUtils::platformTerm()
+{
+    usdetach (arena);
+    unlink (arenaName);
+    free (arenaName);
+    // We don't have any termination requirements at this time
+}
+
+
+void* XMLPlatformUtils::makeMutex()
+{
+    if (arena) {
+        usema_t* sema = usnewsema (arena, 1);
+        if (sema && (usctlsema (sema, CS_RECURSIVEON) != -1)) {
+            return (void*)sema;
+        }
+        else
+            ThrowXML (XMLPlatformUtilsException,
+                      XMLExcepts::Mutex_CouldNotCreate);
+    }
+    else {
+        // arena==0; therefore platformInit hasn't been called. 
+        // it's important that we fail quietly here so that we don't
+        // throw an exception when trying to initizlize the 
+        // atomicOpsMutex, which we re-initizlize in platformInit anyay.
+        return 0;
+    }
+}
+
+
+void XMLPlatformUtils::closeMutex(void* const mtxHandle)
+{
+
+    if (mtxHandle != NULL) {
+        usfreesema (mtxHandle, arena);
+        // never returns anything testable for failure, so nothing
+        // to throw an exception about.
+    }
+}
+
+
+void XMLPlatformUtils::lockMutex(void* const mtxHandle)
+{
+
+    if (mtxHandle != NULL) {
+        if (uspsema (mtxHandle) != 1)
+            ThrowXML(XMLPlatformUtilsException,
+                     XMLExcepts::Mutex_CouldNotLock);
+    }
+
+}
+
+
+void XMLPlatformUtils::unlockMutex(void* const mtxHandle)
+{
+    if (mtxHandle != NULL)
+    {
+        if (usvsema(mtxHandle) == -1)
+        {
+            ThrowXML(XMLPlatformUtilsException,
+                     XMLExcepts::Mutex_CouldNotUnlock);
+        }
+    }
+}
+
+#else
+
 // ---------------------------------------------------------------------------
 //  XMLPlatformUtils: Platform init method
 // ---------------------------------------------------------------------------
@@ -553,6 +653,10 @@
     atomicOpsMutex.fHandle = XMLPlatformUtils::makeMutex();
 }
 
+void XMLPlatformUtils::platformTerm()
+{
+    // We don't have any termination requirements at this time
+}
 
 void* XMLPlatformUtils::makeMutex()
 {
@@ -610,6 +714,7 @@
     }
 }
 
+#endif   // XML_USE_SPROC
 
 // -----------------------------------------------------------------------
 //  Miscellaneous synchronization methods
@@ -685,10 +790,15 @@
     return --location;
 }
 
-#endif // APP_NO_THREADS
-
 void XMLPlatformUtils::platformTerm()
 {
     // We don't have any termination requirements at this time
 }
+
+#endif // APP_NO_THREADS
+
+//void XMLPlatformUtils::platformTerm()
+//{
+    // We don't have any termination requirements at this time
+//}
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to