structure: add gst_structure_take

(╯°□°)╯︵ ┻━┻
This commit is contained in:
Havard Graff 2019-11-03 12:55:13 +01:00 committed by GStreamer Merge Bot
parent a11f53e131
commit 7b38def8e0
2 changed files with 44 additions and 0 deletions

View file

@ -418,6 +418,47 @@ gst_clear_structure (GstStructure ** structure_ptr)
g_clear_pointer (structure_ptr, gst_structure_free);
}
/**
* gst_structure_take:
* @oldstr_ptr: (inout) (transfer full) (nullable): pointer to a place of
* a #GstStructure to take
* @newstr: (transfer full) (allow-none): a new #GstStructure
*
* Atomically modifies a pointer to point to a new object.
* The #GstStructure @oldstr_ptr is pointing to is freed and
* @newstr is taken ownership over.
*
* Either @newstr and the value pointed to by @oldstr_ptr may be %NULL.
*
* Returns: %TRUE if @newstr was different from @oldstr_ptr
*
* Since: 1.18
*/
gboolean
gst_structure_take (GstStructure ** oldstr_ptr, GstStructure * newstr)
{
GstStructure *oldstr;
g_return_val_if_fail (oldstr_ptr != NULL, FALSE);
oldstr = g_atomic_pointer_get ((gpointer *) oldstr_ptr);
if (G_UNLIKELY (oldstr == newstr))
return FALSE;
while (G_UNLIKELY (!g_atomic_pointer_compare_and_exchange ((gpointer *)
oldstr_ptr, oldstr, newstr))) {
oldstr = g_atomic_pointer_get ((gpointer *) oldstr_ptr);
if (G_UNLIKELY (oldstr == newstr))
break;
}
if (oldstr)
gst_structure_free (oldstr);
return oldstr != newstr;
}
/**
* gst_structure_get_name:
* @structure: a #GstStructure

View file

@ -137,6 +137,9 @@ GST_API
void gst_clear_structure (GstStructure **structure_ptr);
#define gst_clear_structure(structure_ptr) g_clear_pointer ((structure_ptr), gst_structure_free)
GST_API
gboolean gst_structure_take (GstStructure ** oldstr_ptr,
GstStructure * newstr);
GST_API
const gchar * gst_structure_get_name (const GstStructure * structure);