shared: add nm_gbytes_get_empty() singleton getter

(cherry picked from commit 32664c72a5)
This commit is contained in:
Thomas Haller 2020-04-27 08:02:40 +02:00
parent 616c18a612
commit 24b2fbbfc7
2 changed files with 20 additions and 0 deletions

View file

@ -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

View file

@ -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)
{