summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian.droege@collabora.co.uk>2010-03-28 19:13:22 +0200
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2010-03-28 19:49:00 +0200
commite305e49ef4178514937910cc0ad2c56a1d8fbd92 (patch)
treea5a7bc580da92a94586f5b2096bcb7ea61a5d40b
parentad230b07f6ae7931dc04800ee6756fed9fb9ff65 (diff)
structure: Make structure abbreviations array one-time initialization threadsafe
-rw-r--r--gst/gststructure.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/gst/gststructure.c b/gst/gststructure.c
index 83eb96b37d..2c4e0e9842 100644
--- a/gst/gststructure.c
+++ b/gst/gststructure.c
@@ -1505,10 +1505,11 @@ static GstStructureAbbreviation *
gst_structure_get_abbrs (gint * n_abbrs)
{
static GstStructureAbbreviation *abbrs = NULL;
- static gint num = 0;
+ static volatile gsize num = 0;
- if (abbrs == NULL) {
+ if (g_once_init_enter (&num)) {
/* dynamically generate the array */
+ gsize _num;
GstStructureAbbreviation dyn_abbrs[] = {
{"int", G_TYPE_INT}
,
@@ -1548,10 +1549,11 @@ gst_structure_get_abbrs (gint * n_abbrs)
,
{"structure", GST_TYPE_STRUCTURE}
};
- num = G_N_ELEMENTS (dyn_abbrs);
+ _num = G_N_ELEMENTS (dyn_abbrs);
/* permanently allocate and copy the array now */
- abbrs = g_new0 (GstStructureAbbreviation, num);
- memcpy (abbrs, dyn_abbrs, sizeof (GstStructureAbbreviation) * num);
+ abbrs = g_new0 (GstStructureAbbreviation, _num);
+ memcpy (abbrs, dyn_abbrs, sizeof (GstStructureAbbreviation) * _num);
+ g_once_init_leave (&num, _num);
}
*n_abbrs = num;