summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.c18
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h2
2 files changed, 20 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c
index 61e3e26716..5dd099a7c9 100644
--- a/shared/nm-glib-aux/nm-shared-utils.c
+++ b/shared/nm-glib-aux/nm-shared-utils.c
@@ -397,6 +397,24 @@ truncate:
/*****************************************************************************/
+GBytes *
+nm_gbytes_get_empty (void)
+{
+ static GBytes *bytes = NULL;
+ GBytes *b;
+
+again:
+ b = g_atomic_pointer_get (&bytes);
+ if (G_UNLIKELY (!b)) {
+ b = g_bytes_new_static ("", 0);
+ if (!g_atomic_pointer_compare_and_exchange (&bytes, NULL, b)) {
+ g_bytes_unref (b);
+ goto again;
+ }
+ }
+ return b;
+}
+
/**
* nm_utils_gbytes_equals:
* @bytes: (allow-none): a #GBytes array to compare. Note that
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index 9200f80fdf..d5990c2d54 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -389,6 +389,8 @@ nm_utils_is_separator (const char c)
/*****************************************************************************/
+GBytes *nm_gbytes_get_empty (void);
+
static inline gboolean
nm_gbytes_equal0 (GBytes *a, GBytes *b)
{