summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Hervey <bilboed@bilboed.com>2010-10-20 13:08:08 +0200
committerEdward Hervey <bilboed@bilboed.com>2010-12-02 19:04:56 +0100
commit606e59468dd176a5352961576d4c937751f66b58 (patch)
treebc0c67fe3e6fb5e20eddcda7836a957ceec36f1b
parent0c2086a4750d077eb3b3f40cd039b33d904c966f (diff)
basesink: Switch enable_last_buffer to an atomic int
Avoids having to take a lock to read/write it. https://bugzilla.gnome.org/show_bug.cgi?id=632778
-rw-r--r--libs/gst/base/gstbasesink.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c
index 951940e12..4216fa0cc 100644
--- a/libs/gst/base/gstbasesink.c
+++ b/libs/gst/base/gstbasesink.c
@@ -236,7 +236,7 @@ struct _GstBaseSinkPrivate
gboolean have_latency;
/* the last buffer we prerolled or rendered. Useful for making snapshots */
- gboolean enable_last_buffer;
+ gint enable_last_buffer; /* atomic */
GstBuffer *last_buffer;
/* caps for pull based scheduling */
@@ -670,7 +670,7 @@ gst_base_sink_init (GstBaseSink * basesink, gpointer g_class)
priv->ts_offset = DEFAULT_TS_OFFSET;
priv->render_delay = DEFAULT_RENDER_DELAY;
priv->blocksize = DEFAULT_BLOCKSIZE;
- priv->enable_last_buffer = DEFAULT_ENABLE_LAST_BUFFER;
+ g_atomic_int_set (&priv->enable_last_buffer, DEFAULT_ENABLE_LAST_BUFFER);
GST_OBJECT_FLAG_SET (basesink, GST_ELEMENT_IS_SINK);
}
@@ -976,13 +976,11 @@ gst_base_sink_set_last_buffer_unlocked (GstBaseSink * sink, GstBuffer * buffer)
static void
gst_base_sink_set_last_buffer (GstBaseSink * sink, GstBuffer * buffer)
{
- GST_OBJECT_LOCK (sink);
- if (sink->priv->enable_last_buffer == FALSE)
- goto out;
+ if (!g_atomic_int_get (&sink->priv->enable_last_buffer))
+ return;
+ GST_OBJECT_LOCK (sink);
gst_base_sink_set_last_buffer_unlocked (sink, buffer);
-
-out:
GST_OBJECT_UNLOCK (sink);
}
@@ -1001,13 +999,13 @@ gst_base_sink_set_last_buffer_enabled (GstBaseSink * sink, gboolean enabled)
{
g_return_if_fail (GST_IS_BASE_SINK (sink));
- GST_OBJECT_LOCK (sink);
- if (enabled != sink->priv->enable_last_buffer) {
- sink->priv->enable_last_buffer = enabled;
- if (!enabled)
- gst_base_sink_set_last_buffer_unlocked (sink, NULL);
+ /* Only take lock if we change the value */
+ if (g_atomic_int_compare_and_exchange (&sink->priv->enable_last_buffer,
+ !enabled, enabled) && !enabled) {
+ GST_OBJECT_LOCK (sink);
+ gst_base_sink_set_last_buffer_unlocked (sink, NULL);
+ GST_OBJECT_UNLOCK (sink);
}
- GST_OBJECT_UNLOCK (sink);
}
/**
@@ -1024,15 +1022,9 @@ gst_base_sink_set_last_buffer_enabled (GstBaseSink * sink, gboolean enabled)
gboolean
gst_base_sink_is_last_buffer_enabled (GstBaseSink * sink)
{
- gboolean res;
-
g_return_val_if_fail (GST_IS_BASE_SINK (sink), FALSE);
- GST_OBJECT_LOCK (sink);
- res = sink->priv->enable_last_buffer;
- GST_OBJECT_UNLOCK (sink);
-
- return res;
+ return g_atomic_int_get (&sink->priv->enable_last_buffer);
}
/**