[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gstreamer-cvs
Subject:    [gst-cvs] gst-plugins-bad: valve: Make the drop variable into an
From:       tester () kemper ! freedesktop ! org (Olivier Crête)
Date:       2010-09-30 21:45:04
Message-ID: 20100930214504.AD30810058 () kemper ! freedesktop ! org
[Download RAW message or body]

Module: gst-plugins-bad
Branch: master
Commit: 9246ed081e470d2bd2d56ab9bfe747e1edf018ca
URL:    http://cgit.freedesktop.org/gstreamer/gst-plugins-bad/commit/?id=9246ed081e470d2bd2d56ab9bfe747e1edf018ca


Author: Olivier Crête <olivier.crete@collabora.co.uk>
Date:   Thu Sep 30 16:26:19 2010 -0400

valve: Make the drop variable into an atomic.

Using an atomic allows us to avoid locking the whole object all time time.
As suggested by Stefan Kost.

---

 gst/valve/gstvalve.c |   41 ++++++++---------------------------------
 gst/valve/gstvalve.h |    4 ++--
 2 files changed, 10 insertions(+), 35 deletions(-)

diff --git a/gst/valve/gstvalve.c b/gst/valve/gstvalve.c
index 8754abd..4192074 100644
--- a/gst/valve/gstvalve.c
+++ b/gst/valve/gstvalve.c
@@ -153,9 +153,7 @@ gst_valve_set_property (GObject * object,
 
   switch (prop_id) {
     case ARG_DROP:
-      GST_OBJECT_LOCK (object);
-      valve->drop = g_value_get_boolean (value);
-      GST_OBJECT_UNLOCK (object);
+      g_atomic_int_set (&valve->drop, g_value_get_boolean (value));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -171,9 +169,7 @@ gst_valve_get_property (GObject * object,
 
   switch (prop_id) {
     case ARG_DROP:
-      GST_OBJECT_LOCK (object);
-      g_value_set_boolean (value, valve->drop);
-      GST_OBJECT_UNLOCK (object);
+      g_value_set_boolean (value, g_atomic_int_get (&valve->drop));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -186,13 +182,8 @@ gst_valve_chain (GstPad * pad, GstBuffer * buffer)
 {
   GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad));
   GstFlowReturn ret = GST_FLOW_OK;
-  gboolean drop;
 
-  GST_OBJECT_LOCK (valve);
-  drop = valve->drop;
-  GST_OBJECT_UNLOCK (valve);
-
-  if (drop) {
+  if (g_atomic_int_get (&valve->drop)) {
     gst_buffer_unref (buffer);
     valve->discont = TRUE;
   } else {
@@ -208,10 +199,8 @@ gst_valve_chain (GstPad * pad, GstBuffer * buffer)
   /* Ignore errors if "drop" was changed while the thread was blocked
    * downwards
    */
-  GST_OBJECT_LOCK (valve);
-  if (valve->drop)
+  if (g_atomic_int_get (&valve->drop))
     ret = GST_FLOW_OK;
-  GST_OBJECT_UNLOCK (valve);
 
   gst_object_unref (valve);
 
@@ -224,13 +213,8 @@ gst_valve_event (GstPad * pad, GstEvent * event)
 {
   GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad));
   gboolean ret = TRUE;
-  gboolean drop;
-
-  GST_OBJECT_LOCK (valve);
-  drop = valve->drop;
-  GST_OBJECT_UNLOCK (valve);
 
-  if (drop)
+  if (g_atomic_int_get (&valve->drop))
     gst_event_unref (event);
   else
     ret = gst_pad_push_event (valve->srcpad, event);
@@ -238,10 +222,8 @@ gst_valve_event (GstPad * pad, GstEvent * event)
   /* Ignore errors if "drop" was changed while the thread was blocked
    * downwards.
    */
-  GST_OBJECT_LOCK (valve);
-  if (valve->drop)
+  if (g_atomic_int_get (&valve->drop))
     ret = TRUE;
-  GST_OBJECT_UNLOCK (valve);
 
   gst_object_unref (valve);
   return ret;
@@ -253,13 +235,8 @@ gst_valve_buffer_alloc (GstPad * pad, guint64 offset, guint \
size,  {
   GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad));
   GstFlowReturn ret = GST_FLOW_OK;
-  gboolean drop;
-
-  GST_OBJECT_LOCK (valve);
-  drop = valve->drop;
-  GST_OBJECT_UNLOCK (valve);
 
-  if (drop)
+  if (g_atomic_int_get (&valve->drop))
     *buf = NULL;
   else
     ret = gst_pad_alloc_buffer (valve->srcpad, offset, size, caps, buf);
@@ -267,10 +244,8 @@ gst_valve_buffer_alloc (GstPad * pad, guint64 offset, guint \
size,  /* Ignore errors if "drop" was changed while the thread was blocked
    * downwards
    */
-  GST_OBJECT_LOCK (valve);
-  if (valve->drop)
+  if (g_atomic_int_get (&valve->drop))
     ret = GST_FLOW_OK;
-  GST_OBJECT_UNLOCK (valve);
 
   gst_object_unref (valve);
 
diff --git a/gst/valve/gstvalve.h b/gst/valve/gstvalve.h
index cc7cd38..9e15df5 100644
--- a/gst/valve/gstvalve.h
+++ b/gst/valve/gstvalve.h
@@ -55,8 +55,8 @@ struct _GstValve
   /*< private >*/
   GstElement parent;
 
-  /* Protected by the object lock */
-  gboolean drop;
+  /* atomic boolean */
+  volatile gint drop;
 
   /* Protected by the stream lock */
   gboolean discont;



------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev

_______________________________________________
gstreamer-cvs mailing list
gstreamer-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gstreamer-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic