diff options
author | Alessandro Decina <alessandro.d@gmail.com> | 2016-04-11 08:02:45 +1000 |
---|---|---|
committer | Alessandro Decina <alessandro.d@gmail.com> | 2016-04-11 08:40:03 +1000 |
commit | 38cb69279b118b587d0aca943df4f6610f481b28 (patch) | |
tree | d8fe07f7bf03e17756f4140d162804d8985d94f2 /gst-libs/gst | |
parent | 519c942eb37debe58d818805f80144a9f039d73d (diff) | |
download | gstreamer-plugins-bad-38cb69279b118b587d0aca943df4f6610f481b28.tar.gz |
glwindow: reduce the number of GMutexes and GConds in send_message()
Don't create many short lived locks/conds in gst_gl_window_send_message. This is
a micro optimization to save a bunch of pthread_* calls which are expensive on
OSX/iOS and possibly other platforms.
Diffstat (limited to 'gst-libs/gst')
-rw-r--r-- | gst-libs/gst/gl/gstglwindow.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/gst-libs/gst/gl/gstglwindow.c b/gst-libs/gst/gl/gstglwindow.c index 695f4c45d..410bc86a6 100644 --- a/gst-libs/gst/gl/gstglwindow.c +++ b/gst-libs/gst/gl/gstglwindow.c @@ -102,6 +102,8 @@ struct _GstGLWindowPrivate GMutex nav_lock; GCond nav_create_cond; gboolean nav_alive; + GMutex sync_message_lock; + GCond sync_message_cond; }; static void gst_gl_window_finalize (GObject * object); @@ -197,6 +199,9 @@ gst_gl_window_init (GstGLWindow * window) g_weak_ref_init (&window->context_ref, NULL); + g_mutex_init (&window->priv->sync_message_lock); + g_cond_init (&window->priv->sync_message_cond); + priv->main_context = g_main_context_new (); priv->loop = g_main_loop_new (priv->main_context, FALSE); priv->navigation_loop = NULL; @@ -348,6 +353,8 @@ gst_gl_window_finalize (GObject * object) g_mutex_clear (&window->lock); g_mutex_clear (&window->priv->nav_lock); g_cond_clear (&window->priv->nav_create_cond); + g_mutex_clear (&window->priv->sync_message_lock); + g_cond_clear (&window->priv->sync_message_cond); gst_object_unref (window->display); G_OBJECT_CLASS (gst_gl_window_parent_class)->finalize (object); @@ -590,8 +597,7 @@ gst_gl_window_quit (GstGLWindow * window) typedef struct _GstGLSyncMessage { - GMutex lock; - GCond cond; + GstGLWindow *window; gboolean fired; GstGLWindowCB callback; @@ -601,14 +607,14 @@ typedef struct _GstGLSyncMessage static void _run_message_sync (GstGLSyncMessage * message) { - g_mutex_lock (&message->lock); if (message->callback) message->callback (message->data); + g_mutex_lock (&message->window->priv->sync_message_lock); message->fired = TRUE; - g_cond_signal (&message->cond); - g_mutex_unlock (&message->lock); + g_cond_broadcast (&message->window->priv->sync_message_cond); + g_mutex_unlock (&message->window->priv->sync_message_lock); } void @@ -617,24 +623,21 @@ gst_gl_window_default_send_message (GstGLWindow * window, { GstGLSyncMessage message; + message.window = window; message.callback = callback; message.data = data; message.fired = FALSE; - g_mutex_init (&message.lock); - g_cond_init (&message.cond); gst_gl_window_send_message_async (window, (GstGLWindowCB) _run_message_sync, &message, NULL); - g_mutex_lock (&message.lock); + g_mutex_lock (&window->priv->sync_message_lock); /* block until opengl calls have been executed in the gl thread */ while (!message.fired) - g_cond_wait (&message.cond, &message.lock); - g_mutex_unlock (&message.lock); - - g_mutex_clear (&message.lock); - g_cond_clear (&message.cond); + g_cond_wait (&window->priv->sync_message_cond, + &window->priv->sync_message_lock); + g_mutex_unlock (&window->priv->sync_message_lock); } /** |