[761/906] x11: Protect event display connection with a mutex
authorSebastian Dröge <slomo@circular-chaos.org>
Tue, 16 Jul 2013 11:28:19 +0000 (13:28 +0200)
committerMatthew Waters <ystreet00@gmail.com>
Sat, 15 Mar 2014 17:36:59 +0000 (18:36 +0100)
We use it from different threads and need to serialize the
accesses to it.

gst-libs/gst/gl/x11/gstglwindow_x11.c
gst-libs/gst/gl/x11/gstglwindow_x11.h

index 7dc1cdb..5bcde3e 100644 (file)
@@ -121,6 +121,20 @@ gst_gl_window_x11_get_property (GObject * object, guint prop_id,
 }
 
 static void
+gst_gl_window_x11_finalize (GObject * object)
+{
+  GstGLWindowX11 *window_x11;
+
+  g_return_if_fail (GST_GL_IS_WINDOW_X11 (object));
+
+  window_x11 = GST_GL_WINDOW_X11 (object);
+
+  g_mutex_clear (&window_x11->disp_send_lock);
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
 gst_gl_window_x11_class_init (GstGLWindowX11Class * klass)
 {
   GObjectClass *obj_class = G_OBJECT_CLASS (klass);
@@ -130,6 +144,7 @@ gst_gl_window_x11_class_init (GstGLWindowX11Class * klass)
 
   obj_class->set_property = gst_gl_window_x11_set_property;
   obj_class->get_property = gst_gl_window_x11_get_property;
+  obj_class->finalize = gst_gl_window_x11_finalize;
 
   g_object_class_install_property (obj_class, ARG_DISPLAY,
       g_param_spec_string ("display", "Display", "X Display name", NULL,
@@ -157,6 +172,8 @@ static void
 gst_gl_window_x11_init (GstGLWindowX11 * window)
 {
   window->priv = GST_GL_WINDOW_X11_GET_PRIVATE (window);
+
+  g_mutex_init (&window->disp_send_lock);
 }
 
 /* Must be called in the gl thread */
@@ -398,7 +415,9 @@ gst_gl_window_x11_close (GstGLWindow * window)
     //XCloseDisplay (window_x11->device);
 
     GST_DEBUG ("display receiver closed");
+    g_mutex_lock (&window_x11->disp_send_lock);
     XCloseDisplay (window_x11->disp_send);
+    g_mutex_unlock (&window_x11->disp_send_lock);
     GST_DEBUG ("display sender closed");
   }
 
@@ -468,6 +487,7 @@ gst_gl_window_x11_set_window_handle (GstGLWindow * window, guintptr id)
   if (window_x11->running) {
     GST_LOG ("set parent window id: %lud", id);
 
+    g_mutex_lock (&window_x11->disp_send_lock);
     XGetWindowAttributes (window_x11->disp_send, window_x11->parent_win, &attr);
 
     XResizeWindow (window_x11->disp_send, window_x11->internal_win_id,
@@ -477,6 +497,7 @@ gst_gl_window_x11_set_window_handle (GstGLWindow * window, guintptr id)
         window_x11->parent_win, 0, 0);
 
     XSync (window_x11->disp_send, FALSE);
+    g_mutex_unlock (&window_x11->disp_send_lock);
   }
 }
 
@@ -524,6 +545,8 @@ gst_gl_window_x11_draw (GstGLWindow * window, guint width, guint height)
     XEvent event;
     XWindowAttributes attr;
 
+    g_mutex_lock (&window_x11->disp_send_lock);
+
     XGetWindowAttributes (window_x11->disp_send, window_x11->internal_win_id,
         &attr);
 
@@ -572,6 +595,8 @@ gst_gl_window_x11_draw (GstGLWindow * window, guint width, guint height)
     XSendEvent (window_x11->disp_send, window_x11->internal_win_id, FALSE,
         ExposureMask, &event);
     XSync (window_x11->disp_send, FALSE);
+
+    g_mutex_unlock (&window_x11->disp_send_lock);
   }
 }
 
index 54f66b7..9e5f04a 100644 (file)
@@ -65,6 +65,7 @@ struct _GstGLWindowX11 {
 
   /* We use a specific connection to send events */
   Display      *disp_send;
+  GMutex        disp_send_lock;
 
   /* X window */
   Window        internal_win_id;