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.
This commit is contained in:
Olivier Crête 2010-09-30 16:26:19 -04:00
parent 0af7cc8ba7
commit 9246ed081e
2 changed files with 10 additions and 35 deletions

View file

@ -153,9 +153,7 @@ gst_valve_set_property (GObject * object,
switch (prop_id) { switch (prop_id) {
case ARG_DROP: case ARG_DROP:
GST_OBJECT_LOCK (object); g_atomic_int_set (&valve->drop, g_value_get_boolean (value));
valve->drop = g_value_get_boolean (value);
GST_OBJECT_UNLOCK (object);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -171,9 +169,7 @@ gst_valve_get_property (GObject * object,
switch (prop_id) { switch (prop_id) {
case ARG_DROP: case ARG_DROP:
GST_OBJECT_LOCK (object); g_value_set_boolean (value, g_atomic_int_get (&valve->drop));
g_value_set_boolean (value, valve->drop);
GST_OBJECT_UNLOCK (object);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); 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)); GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad));
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
gboolean drop;
GST_OBJECT_LOCK (valve); if (g_atomic_int_get (&valve->drop)) {
drop = valve->drop;
GST_OBJECT_UNLOCK (valve);
if (drop) {
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
valve->discont = TRUE; valve->discont = TRUE;
} else { } else {
@ -208,10 +199,8 @@ gst_valve_chain (GstPad * pad, GstBuffer * buffer)
/* Ignore errors if "drop" was changed while the thread was blocked /* Ignore errors if "drop" was changed while the thread was blocked
* downwards * downwards
*/ */
GST_OBJECT_LOCK (valve); if (g_atomic_int_get (&valve->drop))
if (valve->drop)
ret = GST_FLOW_OK; ret = GST_FLOW_OK;
GST_OBJECT_UNLOCK (valve);
gst_object_unref (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)); GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad));
gboolean ret = TRUE; gboolean ret = TRUE;
gboolean drop;
GST_OBJECT_LOCK (valve); if (g_atomic_int_get (&valve->drop))
drop = valve->drop;
GST_OBJECT_UNLOCK (valve);
if (drop)
gst_event_unref (event); gst_event_unref (event);
else else
ret = gst_pad_push_event (valve->srcpad, event); 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 /* Ignore errors if "drop" was changed while the thread was blocked
* downwards. * downwards.
*/ */
GST_OBJECT_LOCK (valve); if (g_atomic_int_get (&valve->drop))
if (valve->drop)
ret = TRUE; ret = TRUE;
GST_OBJECT_UNLOCK (valve);
gst_object_unref (valve); gst_object_unref (valve);
return ret; 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)); GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad));
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
gboolean drop;
GST_OBJECT_LOCK (valve); if (g_atomic_int_get (&valve->drop))
drop = valve->drop;
GST_OBJECT_UNLOCK (valve);
if (drop)
*buf = NULL; *buf = NULL;
else else
ret = gst_pad_alloc_buffer (valve->srcpad, offset, size, caps, buf); 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 /* Ignore errors if "drop" was changed while the thread was blocked
* downwards * downwards
*/ */
GST_OBJECT_LOCK (valve); if (g_atomic_int_get (&valve->drop))
if (valve->drop)
ret = GST_FLOW_OK; ret = GST_FLOW_OK;
GST_OBJECT_UNLOCK (valve);
gst_object_unref (valve); gst_object_unref (valve);

View file

@ -55,8 +55,8 @@ struct _GstValve
/*< private >*/ /*< private >*/
GstElement parent; GstElement parent;
/* Protected by the object lock */ /* atomic boolean */
gboolean drop; volatile gint drop;
/* Protected by the stream lock */ /* Protected by the stream lock */
gboolean discont; gboolean discont;