utils: fix element leak in find_common_root()
[platform/upstream/gstreamer.git] / gst / gstminiobject.c
index 2537164..4812f31 100644 (file)
@@ -15,8 +15,8 @@
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 /**
  * SECTION:gstminiobject
@@ -47,8 +47,6 @@
  *
  * A weak reference can be added and remove with gst_mini_object_weak_ref()
  * and gst_mini_object_weak_unref() respectively.
- *
- * Last reviewed on 2012-06-15 (0.11.93)
  */
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -104,10 +102,11 @@ _priv_gst_mini_object_initialize (void)
 /**
  * gst_mini_object_init: (skip)
  * @mini_object: a #GstMiniObject
+ * @flags: initial #GstMiniObjectFlags
  * @type: the #GType of the mini-object to create
- * @copy_func: the copy function, or NULL
- * @dispose_func: the dispose function, or NULL
- * @free_func: the free function or NULL
+ * @copy_func: (allow-none): the copy function, or %NULL
+ * @dispose_func: (allow-none): the dispose function, or %NULL
+ * @free_func: (allow-none): the free function or %NULL
  *
  * Initializes a mini-object with the desired type and copy/dispose/free
  * functions.
@@ -120,8 +119,7 @@ gst_mini_object_init (GstMiniObject * mini_object, guint flags, GType type,
 {
   mini_object->type = type;
   mini_object->refcount = 1;
-  mini_object->lockstate =
-      (flags & GST_MINI_OBJECT_FLAG_LOCK_READONLY ? GST_LOCK_FLAG_READ : 0);
+  mini_object->lockstate = 0;
   mini_object->flags = flags;
 
   mini_object->copy = copy_func;
@@ -137,7 +135,7 @@ gst_mini_object_init (GstMiniObject * mini_object, guint flags, GType type,
 }
 
 /**
- * gst_mini_object_copy:
+ * gst_mini_object_copy: (skip)
  * @mini_object: the mini-object to copy
  *
  * Creates a copy of the mini-object.
@@ -178,6 +176,10 @@ gst_mini_object_lock (GstMiniObject * object, GstLockFlags flags)
   g_return_val_if_fail (object != NULL, FALSE);
   g_return_val_if_fail (GST_MINI_OBJECT_IS_LOCKABLE (object), FALSE);
 
+  if (G_UNLIKELY (object->flags & GST_MINI_OBJECT_FLAG_LOCK_READONLY &&
+          flags & GST_LOCK_FLAG_WRITE))
+    return FALSE;
+
   do {
     access_mode = flags & FLAG_MASK;
     newstate = state = g_atomic_int_get (&object->lockstate);
@@ -191,11 +193,13 @@ gst_mini_object_lock (GstMiniObject * object, GstLockFlags flags)
       access_mode &= ~GST_LOCK_FLAG_EXCLUSIVE;
     }
 
-    if (access_mode) {
-      /* shared counter > 1 and write access is not allowed */
-      if (access_mode & GST_LOCK_FLAG_WRITE && IS_SHARED (state))
-        goto lock_failed;
+    /* shared counter > 1 and write access is not allowed */
+    if (((state & GST_LOCK_FLAG_WRITE) != 0
+            || (access_mode & GST_LOCK_FLAG_WRITE) != 0)
+        && IS_SHARED (newstate))
+      goto lock_failed;
 
+    if (access_mode) {
       if ((state & LOCK_FLAG_MASK) == 0) {
         /* nothing mapped, set access_mode */
         newstate |= access_mode;
@@ -277,7 +281,7 @@ gst_mini_object_unlock (GstMiniObject * object, GstLockFlags flags)
  * Modification of a mini-object should only be done after verifying that it
  * is writable.
  *
- * Returns: TRUE if the object is writable.
+ * Returns: %TRUE if the object is writable.
  */
 gboolean
 gst_mini_object_is_writable (const GstMiniObject * mini_object)
@@ -295,7 +299,7 @@ gst_mini_object_is_writable (const GstMiniObject * mini_object)
 }
 
 /**
- * gst_mini_object_make_writable:
+ * gst_mini_object_make_writable: (skip)
  * @mini_object: (transfer full): the mini-object to make writable
  *
  * Checks if a mini-object is writable.  If not, a writable copy is made and
@@ -327,12 +331,12 @@ gst_mini_object_make_writable (GstMiniObject * mini_object)
 }
 
 /**
- * gst_mini_object_ref:
+ * gst_mini_object_ref: (skip)
  * @mini_object: the mini-object
  *
  * Increase the reference count of the mini-object.
  *
- * Note that the refcount affects the writeability
+ * Note that the refcount affects the writability
  * of @mini-object, see gst_mini_object_is_writable(). It is
  * important to note that keeping additional references to
  * GstMiniObject instances can potentially increase the number
@@ -419,7 +423,7 @@ call_finalize_notify (GstMiniObject * obj)
 }
 
 /**
- * gst_mini_object_unref:
+ * gst_mini_object_unref: (skip)
  * @mini_object: the mini-object
  *
  * Decreases the reference count of the mini-object, possibly freeing
@@ -467,17 +471,17 @@ gst_mini_object_unref (GstMiniObject * mini_object)
 
 /**
  * gst_mini_object_replace:
- * @olddata: (inout) (transfer full): pointer to a pointer to a mini-object to
- *     be replaced
- * @newdata: pointer to new mini-object
+ * @olddata: (inout) (transfer full) (nullable): pointer to a pointer to a
+ *     mini-object to be replaced
+ * @newdata: (allow-none): pointer to new mini-object
  *
  * Atomically modifies a pointer to point to a new mini-object.
  * The reference count of @olddata is decreased and the reference count of
  * @newdata is increased.
  *
- * Either @newdata and the value pointed to by @olddata may be NULL.
+ * Either @newdata and the value pointed to by @olddata may be %NULL.
  *
- * Returns: TRUE if @newdata was different from @olddata
+ * Returns: %TRUE if @newdata was different from @olddata
  */
 gboolean
 gst_mini_object_replace (GstMiniObject ** olddata, GstMiniObject * newdata)
@@ -512,11 +516,11 @@ gst_mini_object_replace (GstMiniObject ** olddata, GstMiniObject * newdata)
 }
 
 /**
- * gst_mini_object_steal:
+ * gst_mini_object_steal: (skip)
  * @olddata: (inout) (transfer full): pointer to a pointer to a mini-object to
  *     be stolen
  *
- * Replace the current #GstMiniObject pointer to by @olddata with NULL and
+ * Replace the current #GstMiniObject pointer to by @olddata with %NULL and
  * return the old value.
  *
  * Returns: the #GstMiniObject at @oldata
@@ -552,9 +556,9 @@ gst_mini_object_steal (GstMiniObject ** olddata)
  * except that it does not increase the refcount of @newdata and thus
  * takes ownership of @newdata.
  *
- * Either @newdata and the value pointed to by @olddata may be NULL.
+ * Either @newdata and the value pointed to by @olddata may be %NULL.
  *
- * Returns: TRUE if @newdata was different from @olddata
+ * Returns: %TRUE if @newdata was different from @olddata
  */
 gboolean
 gst_mini_object_take (GstMiniObject ** olddata, GstMiniObject * newdata)
@@ -641,12 +645,12 @@ gst_mini_object_weak_unref (GstMiniObject * object,
  *           needs to be freed
  *
  * This sets an opaque, named pointer on a miniobject.
- * The name is specified through a #GQuark (retrived e.g. via
+ * The name is specified through a #GQuark (retrieved e.g. via
  * g_quark_from_static_string()), and the pointer
  * can be gotten back from the @object with gst_mini_object_get_qdata()
  * until the @object is disposed.
  * Setting a previously set user data pointer, overrides (frees)
- * the old pointer set, using #NULL as pointer essentially
+ * the old pointer set, using %NULL as pointer essentially
  * removes the data stored.
  *
  * @destroy may be specified which is called with @data as argument
@@ -689,7 +693,8 @@ gst_mini_object_set_qdata (GstMiniObject * object, GQuark quark,
  * This function gets back user data pointers stored via
  * gst_mini_object_set_qdata().
  *
- * Returns: (transfer none): The user data pointer set, or %NULL
+ * Returns: (transfer none) (nullable): The user data pointer set, or
+ * %NULL
  */
 gpointer
 gst_mini_object_get_qdata (GstMiniObject * object, GQuark quark)
@@ -719,7 +724,8 @@ gst_mini_object_get_qdata (GstMiniObject * object, GQuark quark)
  * and removes the data from @object without invoking its destroy() function (if
  * any was set).
  *
- * Returns: (transfer full): The user data pointer set, or %NULL
+ * Returns: (transfer full) (nullable): The user data pointer set, or
+ * %NULL
  */
 gpointer
 gst_mini_object_steal_qdata (GstMiniObject * object, GQuark quark)