mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
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.
This commit is contained in:
parent
519c942eb3
commit
38cb69279b
1 changed files with 16 additions and 13 deletions
|
@ -102,6 +102,8 @@ struct _GstGLWindowPrivate
|
||||||
GMutex nav_lock;
|
GMutex nav_lock;
|
||||||
GCond nav_create_cond;
|
GCond nav_create_cond;
|
||||||
gboolean nav_alive;
|
gboolean nav_alive;
|
||||||
|
GMutex sync_message_lock;
|
||||||
|
GCond sync_message_cond;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void gst_gl_window_finalize (GObject * object);
|
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_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->main_context = g_main_context_new ();
|
||||||
priv->loop = g_main_loop_new (priv->main_context, FALSE);
|
priv->loop = g_main_loop_new (priv->main_context, FALSE);
|
||||||
priv->navigation_loop = NULL;
|
priv->navigation_loop = NULL;
|
||||||
|
@ -348,6 +353,8 @@ gst_gl_window_finalize (GObject * object)
|
||||||
g_mutex_clear (&window->lock);
|
g_mutex_clear (&window->lock);
|
||||||
g_mutex_clear (&window->priv->nav_lock);
|
g_mutex_clear (&window->priv->nav_lock);
|
||||||
g_cond_clear (&window->priv->nav_create_cond);
|
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);
|
gst_object_unref (window->display);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gst_gl_window_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gst_gl_window_parent_class)->finalize (object);
|
||||||
|
@ -590,8 +597,7 @@ gst_gl_window_quit (GstGLWindow * window)
|
||||||
|
|
||||||
typedef struct _GstGLSyncMessage
|
typedef struct _GstGLSyncMessage
|
||||||
{
|
{
|
||||||
GMutex lock;
|
GstGLWindow *window;
|
||||||
GCond cond;
|
|
||||||
gboolean fired;
|
gboolean fired;
|
||||||
|
|
||||||
GstGLWindowCB callback;
|
GstGLWindowCB callback;
|
||||||
|
@ -601,14 +607,14 @@ typedef struct _GstGLSyncMessage
|
||||||
static void
|
static void
|
||||||
_run_message_sync (GstGLSyncMessage * message)
|
_run_message_sync (GstGLSyncMessage * message)
|
||||||
{
|
{
|
||||||
g_mutex_lock (&message->lock);
|
|
||||||
|
|
||||||
if (message->callback)
|
if (message->callback)
|
||||||
message->callback (message->data);
|
message->callback (message->data);
|
||||||
|
|
||||||
|
g_mutex_lock (&message->window->priv->sync_message_lock);
|
||||||
message->fired = TRUE;
|
message->fired = TRUE;
|
||||||
g_cond_signal (&message->cond);
|
g_cond_broadcast (&message->window->priv->sync_message_cond);
|
||||||
g_mutex_unlock (&message->lock);
|
g_mutex_unlock (&message->window->priv->sync_message_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -617,24 +623,21 @@ gst_gl_window_default_send_message (GstGLWindow * window,
|
||||||
{
|
{
|
||||||
GstGLSyncMessage message;
|
GstGLSyncMessage message;
|
||||||
|
|
||||||
|
message.window = window;
|
||||||
message.callback = callback;
|
message.callback = callback;
|
||||||
message.data = data;
|
message.data = data;
|
||||||
message.fired = FALSE;
|
message.fired = FALSE;
|
||||||
g_mutex_init (&message.lock);
|
|
||||||
g_cond_init (&message.cond);
|
|
||||||
|
|
||||||
gst_gl_window_send_message_async (window, (GstGLWindowCB) _run_message_sync,
|
gst_gl_window_send_message_async (window, (GstGLWindowCB) _run_message_sync,
|
||||||
&message, NULL);
|
&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 */
|
/* block until opengl calls have been executed in the gl thread */
|
||||||
while (!message.fired)
|
while (!message.fired)
|
||||||
g_cond_wait (&message.cond, &message.lock);
|
g_cond_wait (&window->priv->sync_message_cond,
|
||||||
g_mutex_unlock (&message.lock);
|
&window->priv->sync_message_lock);
|
||||||
|
g_mutex_unlock (&window->priv->sync_message_lock);
|
||||||
g_mutex_clear (&message.lock);
|
|
||||||
g_cond_clear (&message.cond);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue