--- OpenDis.c.orig Sat Jun 18 20:43:10 2005 +++ OpenDis.c Sat Jun 18 20:43:26 2005 @@ -64,6 +64,11 @@ int *_Xdebug_p = &_Xdebug; #endif +#if defined(XTHREADS) && defined(SUNSOFT) +DisplayPtrLink *HeadDisplay=NULL; +DisplayPtrLink *LastDisplay=NULL; +#endif /* XTHREADS && SUNSOFT */ + #ifdef XTHREADS int (*_XInitDisplayLock_fn)() = NULL; void (*_XFreeDisplayLock_fn)() = NULL; @@ -268,6 +273,13 @@ return(NULL); } +#ifdef XTHREADS + if (AddToDisplayLink(dpy) == 0) { + OutOfMemory (dpy, setup); + return(NULL); + } +#endif XTHREADS + if (!_XPollfdCacheInit(dpy)) { OutOfMemory (dpy, setup); return(NULL); @@ -699,6 +711,10 @@ void _XFreeDisplayStructure(dpy) register Display *dpy; { +#ifdef XTHREADS + RemoveFromDisplayLink(dpy); +#endif XTHREADS + while (dpy->ext_procs) { _XExtension *ext = dpy->ext_procs; dpy->ext_procs = ext->next; @@ -931,4 +947,105 @@ #undef X_SmeConn } #endif /* SME */ + +#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 */ ------- locking.c ------- --- /tmp/geta26957 Sat Jun 18 20:45:07 2005 +++ /tmp/getb26957 Sat Jun 18 20:45:07 2005 @@ -655,10 +655,15 @@ #ifdef XTHREADS_DEBUG setlinebuf(stdout); /* for debugging messages */ #endif #endif +#ifdef SUNSOFT + if (InitDisplayArrayLock() == 0) + return 0; +#endif + return 1; } #else /* XTHREADS */ Status XInitThreads()