summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-04-27 08:02:40 +0200
committerThomas Haller <thaller@redhat.com>2020-04-28 18:35:59 +0200
commit32664c72a5a61e1b2a156436d9132cbbc928b9c0 (patch)
treec89e417323d46c8d5b819e6a06104056889a6252
parent2a26562ec8c1d824dc0f64397b1e1b452baded50 (diff)
downloadNetworkManager-32664c72a5a61e1b2a156436d9132cbbc928b9c0.tar.gz
shared: add nm_gbytes_get_empty() singleton getter
-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)
{