[0.11] gstreamer: multiqueue: Increment unique item counter with atomic operations
Edward Hervey
bilboed at kemper.freedesktop.org
Wed Mar 30 12:33:37 PDT 2011
Module: gstreamer
Branch: 0.11
Commit: 383cac91b103fa4b133428cc6196f35a1cd7904d
URL: http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=383cac91b103fa4b133428cc6196f35a1cd7904d
Author: Sebastian Dröge <sebastian.droege at collabora.co.uk>
Date: Mon Mar 21 17:52:13 2011 +0100
multiqueue: Increment unique item counter with atomic operations
Before it was only protected by the stream lock but every pad
has its own stream lock, making the protection rather useless.
---
plugins/elements/gstmultiqueue.c | 7 +++----
plugins/elements/gstmultiqueue.h | 2 +-
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/plugins/elements/gstmultiqueue.c b/plugins/elements/gstmultiqueue.c
index f1956da..3f1eef5 100644
--- a/plugins/elements/gstmultiqueue.c
+++ b/plugins/elements/gstmultiqueue.c
@@ -1229,7 +1229,7 @@ gst_multi_queue_chain (GstPad * pad, GstBuffer * buffer)
goto was_eos;
/* Get a unique incrementing id */
- curid = mq->counter++;
+ curid = g_atomic_int_exchange_and_add ((gint *) & mq->counter, 1);
GST_LOG_OBJECT (mq, "SingleQueue %d : about to enqueue buffer %p with id %d",
sq->id, buffer, curid);
@@ -1334,9 +1334,8 @@ gst_multi_queue_sink_event (GstPad * pad, GstEvent * event)
if (sq->is_eos)
goto was_eos;
- /* Get an unique incrementing id. protected with the STREAM_LOCK, unserialized
- * events already got pushed and don't end up in the queue. */
- curid = mq->counter++;
+ /* Get an unique incrementing id. */
+ curid = g_atomic_int_exchange_and_add ((gint *) & mq->counter, 1);
item = gst_multi_queue_event_item_new ((GstMiniObject *) event, curid);
diff --git a/plugins/elements/gstmultiqueue.h b/plugins/elements/gstmultiqueue.h
index ec47601..60262b7 100644
--- a/plugins/elements/gstmultiqueue.h
+++ b/plugins/elements/gstmultiqueue.h
@@ -63,7 +63,7 @@ struct _GstMultiQueue {
gboolean buffering;
gint percent;
- guint32 counter; /* incoming object counter, protected with STREAM_LOCK */
+ guint32 counter; /* incoming object counter, use atomic accesses */
guint32 highid; /* contains highest id of last outputted object */
GMutex * qlock; /* Global queue lock (vs object lock or individual */
More information about the gstreamer-commits
mailing list