[glib/wip/ebassi/rc-new: 84/86] Port GAsyncQueue to gatomicrefcount
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/ebassi/rc-new: 84/86] Port GAsyncQueue to gatomicrefcount
- Date: Fri, 16 Feb 2018 13:05:07 +0000 (UTC)
commit 97be2c19acf6a1351c6e7a0a0f24ee1aff906567
Author: Emmanuele Bassi <ebassi gnome org>
Date: Fri Feb 16 12:34:41 2018 +0000
Port GAsyncQueue to gatomicrefcount
Use the newly added API for reference counting instead of rolling our
own.
glib/gasyncqueue.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/glib/gasyncqueue.c b/glib/gasyncqueue.c
index 8529beb8b..ccabd88c1 100644
--- a/glib/gasyncqueue.c
+++ b/glib/gasyncqueue.c
@@ -30,6 +30,7 @@
#include "gmain.h"
#include "gmem.h"
#include "gqueue.h"
+#include "grefcount.h"
#include "gtestutils.h"
#include "gtimer.h"
#include "gthread.h"
@@ -99,7 +100,7 @@ struct _GAsyncQueue
GQueue queue;
GDestroyNotify item_free_func;
guint waiting_threads;
- gint ref_count;
+ gatomicrefcount ref_count;
};
typedef struct
@@ -142,8 +143,8 @@ g_async_queue_new_full (GDestroyNotify item_free_func)
g_mutex_init (&queue->mutex);
g_cond_init (&queue->cond);
g_queue_init (&queue->queue);
+ g_atomic_ref_count_init (&queue->ref_count);
queue->waiting_threads = 0;
- queue->ref_count = 1;
queue->item_free_func = item_free_func;
return queue;
@@ -163,7 +164,7 @@ g_async_queue_ref (GAsyncQueue *queue)
{
g_return_val_if_fail (queue, NULL);
- g_atomic_int_inc (&queue->ref_count);
+ g_atomic_ref_count_inc (&queue->ref_count);
return queue;
}
@@ -183,7 +184,7 @@ g_async_queue_ref_unlocked (GAsyncQueue *queue)
{
g_return_if_fail (queue);
- g_atomic_int_inc (&queue->ref_count);
+ g_atomic_ref_count_inc (&queue->ref_count);
}
/**
@@ -224,7 +225,7 @@ g_async_queue_unref (GAsyncQueue *queue)
{
g_return_if_fail (queue);
- if (g_atomic_int_dec_and_test (&queue->ref_count))
+ if (g_atomic_ref_count_dec (&queue->ref_count))
{
g_return_if_fail (queue->waiting_threads == 0);
g_mutex_clear (&queue->mutex);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]