mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 07:56:14 +01:00
Port GArray and friends to gatomicrefcount
Use the newly added API for reference counting instead of rolling our own.
This commit is contained in:
parent
09e2247d3f
commit
439ee4822e
@ -41,7 +41,7 @@
|
|||||||
#include "gthread.h"
|
#include "gthread.h"
|
||||||
#include "gmessages.h"
|
#include "gmessages.h"
|
||||||
#include "gqsort.h"
|
#include "gqsort.h"
|
||||||
|
#include "grefcount.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:arrays
|
* SECTION:arrays
|
||||||
@ -106,7 +106,7 @@ struct _GRealArray
|
|||||||
guint elt_size;
|
guint elt_size;
|
||||||
guint zero_terminated : 1;
|
guint zero_terminated : 1;
|
||||||
guint clear : 1;
|
guint clear : 1;
|
||||||
gint ref_count;
|
gatomicrefcount ref_count;
|
||||||
GDestroyNotify clear_func;
|
GDestroyNotify clear_func;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -199,9 +199,10 @@ g_array_sized_new (gboolean zero_terminated,
|
|||||||
array->zero_terminated = (zero_terminated ? 1 : 0);
|
array->zero_terminated = (zero_terminated ? 1 : 0);
|
||||||
array->clear = (clear ? 1 : 0);
|
array->clear = (clear ? 1 : 0);
|
||||||
array->elt_size = elt_size;
|
array->elt_size = elt_size;
|
||||||
array->ref_count = 1;
|
|
||||||
array->clear_func = NULL;
|
array->clear_func = NULL;
|
||||||
|
|
||||||
|
g_atomic_ref_count_init (&array->ref_count);
|
||||||
|
|
||||||
if (array->zero_terminated || reserved_size != 0)
|
if (array->zero_terminated || reserved_size != 0)
|
||||||
{
|
{
|
||||||
g_array_maybe_expand (array, reserved_size);
|
g_array_maybe_expand (array, reserved_size);
|
||||||
@ -257,7 +258,7 @@ g_array_ref (GArray *array)
|
|||||||
GRealArray *rarray = (GRealArray*) array;
|
GRealArray *rarray = (GRealArray*) array;
|
||||||
g_return_val_if_fail (array, NULL);
|
g_return_val_if_fail (array, NULL);
|
||||||
|
|
||||||
g_atomic_int_inc (&rarray->ref_count);
|
g_atomic_ref_count_inc (&rarray->ref_count);
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
@ -287,7 +288,7 @@ g_array_unref (GArray *array)
|
|||||||
GRealArray *rarray = (GRealArray*) array;
|
GRealArray *rarray = (GRealArray*) array;
|
||||||
g_return_if_fail (array);
|
g_return_if_fail (array);
|
||||||
|
|
||||||
if (g_atomic_int_dec_and_test (&rarray->ref_count))
|
if (g_atomic_ref_count_dec (&rarray->ref_count))
|
||||||
array_free (rarray, FREE_SEGMENT);
|
array_free (rarray, FREE_SEGMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +347,7 @@ g_array_free (GArray *farray,
|
|||||||
flags = (free_segment ? FREE_SEGMENT : 0);
|
flags = (free_segment ? FREE_SEGMENT : 0);
|
||||||
|
|
||||||
/* if others are holding a reference, preserve the wrapper but do free/return the data */
|
/* if others are holding a reference, preserve the wrapper but do free/return the data */
|
||||||
if (!g_atomic_int_dec_and_test (&array->ref_count))
|
if (!g_atomic_ref_count_dec (&array->ref_count))
|
||||||
flags |= PRESERVE_WRAPPER;
|
flags |= PRESERVE_WRAPPER;
|
||||||
|
|
||||||
return array_free (array, flags);
|
return array_free (array, flags);
|
||||||
@ -882,7 +883,7 @@ struct _GRealPtrArray
|
|||||||
gpointer *pdata;
|
gpointer *pdata;
|
||||||
guint len;
|
guint len;
|
||||||
guint alloc;
|
guint alloc;
|
||||||
gint ref_count;
|
gatomicrefcount ref_count;
|
||||||
GDestroyNotify element_free_func;
|
GDestroyNotify element_free_func;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -936,9 +937,10 @@ g_ptr_array_sized_new (guint reserved_size)
|
|||||||
array->pdata = NULL;
|
array->pdata = NULL;
|
||||||
array->len = 0;
|
array->len = 0;
|
||||||
array->alloc = 0;
|
array->alloc = 0;
|
||||||
array->ref_count = 1;
|
|
||||||
array->element_free_func = NULL;
|
array->element_free_func = NULL;
|
||||||
|
|
||||||
|
g_atomic_ref_count_init (&array->ref_count);
|
||||||
|
|
||||||
if (reserved_size != 0)
|
if (reserved_size != 0)
|
||||||
g_ptr_array_maybe_expand (array, reserved_size);
|
g_ptr_array_maybe_expand (array, reserved_size);
|
||||||
|
|
||||||
@ -1041,7 +1043,7 @@ g_ptr_array_ref (GPtrArray *array)
|
|||||||
|
|
||||||
g_return_val_if_fail (array, NULL);
|
g_return_val_if_fail (array, NULL);
|
||||||
|
|
||||||
g_atomic_int_inc (&rarray->ref_count);
|
g_atomic_ref_count_inc (&rarray->ref_count);
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
@ -1066,7 +1068,7 @@ g_ptr_array_unref (GPtrArray *array)
|
|||||||
|
|
||||||
g_return_if_fail (array);
|
g_return_if_fail (array);
|
||||||
|
|
||||||
if (g_atomic_int_dec_and_test (&rarray->ref_count))
|
if (g_atomic_ref_count_dec (&rarray->ref_count))
|
||||||
ptr_array_free (array, FREE_SEGMENT);
|
ptr_array_free (array, FREE_SEGMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1107,7 +1109,7 @@ g_ptr_array_free (GPtrArray *array,
|
|||||||
/* if others are holding a reference, preserve the wrapper but
|
/* if others are holding a reference, preserve the wrapper but
|
||||||
* do free/return the data
|
* do free/return the data
|
||||||
*/
|
*/
|
||||||
if (!g_atomic_int_dec_and_test (&rarray->ref_count))
|
if (!g_atomic_ref_count_dec (&rarray->ref_count))
|
||||||
flags |= PRESERVE_WRAPPER;
|
flags |= PRESERVE_WRAPPER;
|
||||||
|
|
||||||
return ptr_array_free (array, flags);
|
return ptr_array_free (array, flags);
|
||||||
|
Loading…
Reference in New Issue
Block a user