[cairo-commit] src/cairo-xlib-surface-shm.c

Chris Wilson ickle at kemper.freedesktop.org
Sat Aug 18 00:39:08 PDT 2012


 src/cairo-xlib-surface-shm.c |    6 ++++++
 1 file changed, 6 insertions(+)

New commits:
commit ec01c71ecab46e0252d295f8d1f24f261b3f52af
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sat Aug 18 08:02:42 2012 +0100

    xlib/shm: Wrap the detection of shm with locking
    
    As we access a global error variable, we need to hold a mutex against
    simultaneous checking of multiple Displays. This should already be true
    as we hold our display mutex to serialize initialisation, so just add an
    assertion. As the client may mix use of cairo in one thread with X from
    another, we need to hold the Display lock and serialise whilst
    manipulating the low-level state of the Display.
    
    Suggested-by: Uli Schlachter <psychon at znc.in>
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/cairo-xlib-surface-shm.c b/src/cairo-xlib-surface-shm.c
index ad36ce1..2d20127 100644
--- a/src/cairo-xlib-surface-shm.c
+++ b/src/cairo-xlib-surface-shm.c
@@ -231,6 +231,7 @@ _pqueue_pop (struct pqueue *pq)
 }
 
 static cairo_bool_t _x_error_occurred;
+
 static int
 _check_error_handler (Display     *display,
 		     XErrorEvent *event)
@@ -263,7 +264,11 @@ can_use_shm (Display *dpy, int *has_pixmap)
 	return FALSE;
     }
 
+    assert (CAIRO_MUTEX_IS_LOCKED (_cairo_xlib_display_mutex));
     _x_error_occurred = FALSE;
+
+    XLockDisplay (dpy);
+    XSync (dpy, False);
     old_handler = XSetErrorHandler (_check_error_handler);
 
     success = XShmAttach (dpy, &shm);
@@ -272,6 +277,7 @@ can_use_shm (Display *dpy, int *has_pixmap)
 
     XSync (dpy, False);
     XSetErrorHandler (old_handler);
+    XUnlockDisplay (dpy);
 
     shmctl (shm.shmid, IPC_RMID, NULL);
     shmdt (shm.shmaddr);


More information about the cairo-commit mailing list