mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-27 18:40:09 +01:00
shared: add nm_gbytes_get_empty() singleton getter
(cherry picked from commit 32664c72a5)
This commit is contained in:
parent
616c18a612
commit
24b2fbbfc7
2 changed files with 20 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue