mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-19 11:30:42 +01:00
libnm: make NMRange ref/unref thread-safe
Like for our other immutable/sealable types, make ref/unref thread safe.
That is important, as the boxed types only increase the ref-count on
copy. If ref/unref is not thread-safe, it means you cannot copy a boxed
type, and operate on the copy on another thread.
Fixes: 041e38b151 ('libnm: add NMRange')
This commit is contained in:
parent
71454ae4cd
commit
9bd833da6b
1 changed files with 6 additions and 6 deletions
|
|
@ -4167,6 +4167,7 @@ nm_range_new(guint64 start, guint64 end)
|
|||
* @range: the #NMRange
|
||||
*
|
||||
* Increases the reference count of the object.
|
||||
* This is thread-safe.
|
||||
*
|
||||
* Returns: the input argument @range object.
|
||||
*
|
||||
|
|
@ -4177,9 +4178,9 @@ nm_range_ref(const NMRange *range)
|
|||
{
|
||||
g_return_val_if_fail(NM_IS_RANGE(range), NULL);
|
||||
|
||||
nm_assert(range->refcount < G_MAXUINT);
|
||||
nm_assert(range->refcount < G_MAXINT);
|
||||
|
||||
((NMRange *) range)->refcount++;
|
||||
g_atomic_int_inc(&((NMRange *) range)->refcount);
|
||||
return (NMRange *) range;
|
||||
}
|
||||
|
||||
|
|
@ -4189,6 +4190,7 @@ nm_range_ref(const NMRange *range)
|
|||
*
|
||||
* Decreases the reference count of the object. If the reference count
|
||||
* reaches zero the object will be destroyed.
|
||||
* This is thread-safe.
|
||||
*
|
||||
* Since: 1.42
|
||||
**/
|
||||
|
|
@ -4197,10 +4199,8 @@ nm_range_unref(const NMRange *range)
|
|||
{
|
||||
g_return_if_fail(NM_IS_RANGE(range));
|
||||
|
||||
nm_assert(range->refcount != 0);
|
||||
|
||||
if (--((NMRange *) range)->refcount == 0)
|
||||
g_slice_free(NMRange, (NMRange *) range);
|
||||
if (g_atomic_int_dec_and_test(&((NMRange *) range)->refcount))
|
||||
nm_g_slice_free((NMRange *) range);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue