1234757.patch revision 851
###############################################################################
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, provided that the above
# copyright notice(s) and this permission notice appear in all copies of
# the Software and that both the above copyright notice(s) and this
# permission notice appear in supporting documentation.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
# INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Except as contained in this notice, the name of a copyright holder
# shall not be used in advertising or otherwise to promote the sale, use
# or other dealings in this Software without prior written authorization
# of the copyright holder.
#
1234757: XInitThreads needs to be made less restrictive
This is a RFE to enhance XInitThreads so that it may be called:
* By libraries used by the client, (without the client's intervention)
* At a later time, after other Xlib calls have already been made.
Currently, XInitThreads *Must* be the first Xlib call that the client
makes.
For Example, in order for XIL 1.3 to be MT HOT, it must be able to
make the call to XInitThreads, even if the client has already made
other Xlib calls.
diff -urp -x '*~' -x '*.orig' include/X11/Xlibint.h include/X11/Xlibint.h
--- include/X11/Xlibint.h 2009-02-20 15:17:13.000000000 -0800
+++ include/X11/Xlibint.h 2009-04-08 00:17:31.818676000 -0700
@@ -187,6 +187,29 @@ struct _XDisplay
struct _X11XCBPrivate *xcb; /* XCB glue private data */
};
+#if defined(XTHREADS) && defined(SUNSOFT)
+struct _DisplayPtrLink {
+ Display *dpy;
+ struct _DisplayPtrLink *next;
+};
+
+typedef struct _DisplayPtrLink DisplayPtrLink;
+
+int InitDisplayArrayLock();
+
+void RemoveFromDisplayLink(
+#if NeedFunctionPrototypes
+ Display * /*dpy */
+#endif /* NeedFunctionPrototypes */
+);
+
+int AddToDisplayLink(
+#if NeedFunctionPrototypes
+ Display * /*dpy */
+#endif /* NeedFunctionPrototypes */
+);
+#endif /* XTHREADS && SUNSOFT */
+
#define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n)
/*
diff -urp -x '*~' -x '*.orig' src/OpenDis.c src/OpenDis.c
--- src/OpenDis.c 2009-04-06 16:48:55.000000000 -0700
+++ src/OpenDis.c 2009-04-08 00:17:31.819345000 -0700
@@ -62,6 +62,11 @@ typedef struct {
} _XBigReqState;
#endif /* !USE_XCB */
+#if defined(XTHREADS) && defined(SUNSOFT)
+DisplayPtrLink *HeadDisplay=NULL;
+DisplayPtrLink *LastDisplay=NULL;
+#endif /* XTHREADS && SUNSOFT */
+
#ifdef XTHREADS
#include "locking.h"
int (*_XInitDisplayLock_fn)(Display *dpy) = NULL;
@@ -261,6 +266,13 @@ XOpenDisplay (
return(NULL);
}
+#ifdef XTHREADS
+ if (AddToDisplayLink(dpy) == 0) {
+ OutOfMemory (dpy, setup);
+ return(NULL);
+ }
+#endif XTHREADS
+
if (!_XPollfdCacheInit(dpy)) {
OutOfMemory (dpy, setup);
return(NULL);
@@ -790,5 +802,9 @@ _XBigReqHandler(
void _XFreeDisplayStructure(Display *dpy)
{
+#ifdef XTHREADS
+ RemoveFromDisplayLink(dpy);
+#endif XTHREADS
+
/* move all cookies in the EQ to the jar, then free them. */
if (dpy->qfree) {
@@ -910,6 +926,107 @@ void _XFreeDisplayStructure(Display *dpy
Xfree ((char *)dpy);
}
+#if defined(XTHREADS) && defined(SUNSOFT)
+int
+AddToDisplayLink(dpy)
+Display *dpy;
+{
+ if ( dpy->lock )
+ return 1;
+
+/*
+ * Attempt to allocate a display array. Return NULL if allocation fails.
+ */
+ if ( !HeadDisplay ) {
+ if ((HeadDisplay = (DisplayPtrLink *) Xcalloc
+ (1, sizeof(struct _DisplayPtrLink))) == NULL ) {
+ return 0;
+ }
+
+ HeadDisplay->dpy = dpy;
+ HeadDisplay->next = NULL;
+ LastDisplay = HeadDisplay;
+ return 1;
+ }
+
+ if ((LastDisplay->next = (DisplayPtrLink *) Xcalloc
+ (1, sizeof(struct _DisplayPtrLink))) == NULL ) {
+ return 0;
+ }
+
+ LastDisplay = LastDisplay->next;
+ LastDisplay->dpy = dpy;
+ LastDisplay->next = NULL;
+ return 1;
+}
+
+void
+RemoveFromDisplayLink(dpy)
+Display *dpy;
+{
+ DisplayPtrLink *tmp_display = HeadDisplay;
+ DisplayPtrLink *prev_display = HeadDisplay;
+
+ if ( dpy->lock )
+ return;
+
+ while ( tmp_display ) {
+ if ((tmp_display->dpy == dpy) && (tmp_display->dpy->fd == dpy->fd)){
+ break;
+ }
+
+ prev_display = tmp_display;
+ tmp_display = tmp_display->next;
+ }
+
+ /* Node not found */
+ if ( !tmp_display )
+ return;
+
+ /* If tmp_display is the first node */
+ if ( tmp_display == HeadDisplay ) {
+ if ( HeadDisplay->next )
+ HeadDisplay = HeadDisplay->next;
+ else {
+ HeadDisplay = NULL;
+ LastDisplay = NULL;
+ }
+ }
+ /* If tmp_display is the last node */
+ else if ( tmp_display == LastDisplay ) {
+ LastDisplay = prev_display;
+ LastDisplay->next = NULL;
+ }
+ /* tmp_display is in the middle of list*/
+ else
+ prev_display->next = tmp_display->next;
+
+ Xfree(tmp_display);
+ return;
+}
+
+int
+InitDisplayArrayLock()
+{
+ DisplayPtrLink *tmp_display = HeadDisplay;
+ DisplayPtrLink *prev_display = HeadDisplay;
+
+ while ( tmp_display ) {
+ if ((tmp_display->dpy) && (!tmp_display->dpy->lock)) {
+ /* Initialize the display lock */
+ if (_XInitDisplayLock_fn(tmp_display->dpy) != 0) {
+ OutOfMemory (tmp_display->dpy, NULL);
+ return 0;
+ }
+ }
+ tmp_display = tmp_display->next;
+ }
+
+ return 1;
+}
+
+#endif /* XTHREADS && SUNSOFT */
+
/* OutOfMemory is called if malloc fails. XOpenDisplay returns NULL
after this returns. */
diff -urp -x '*~' -x '*.orig' src/locking.c src/locking.c
--- src/locking.c 2009-04-06 16:29:10.000000000 -0700
+++ src/locking.c 2009-04-08 00:17:31.819992000 -0700
@@ -611,6 +611,11 @@ Status XInitThreads(void)
#endif
#endif
+#ifdef SUNSOFT
+ if (InitDisplayArrayLock() == 0)
+ return 0;
+#endif
+
return 1;
}