[balsa/wip/gtk4] mime-stream-shared: Use g_atomic_ref_count
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/wip/gtk4] mime-stream-shared: Use g_atomic_ref_count
- Date: Wed, 13 Jun 2018 03:07:18 +0000 (UTC)
commit aba0beba80f380922c237c5659fc31c32b7cf172
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Tue Jun 12 23:05:16 2018 -0400
mime-stream-shared: Use g_atomic_ref_count
to ref-count the shared stream lock.
libbalsa/mime-stream-shared.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
---
diff --git a/libbalsa/mime-stream-shared.c b/libbalsa/mime-stream-shared.c
index be366bff2..fe90ff668 100644
--- a/libbalsa/mime-stream-shared.c
+++ b/libbalsa/mime-stream-shared.c
@@ -102,7 +102,7 @@ libbalsa_mime_stream_shared_class_init(LibBalsaMimeStreamSharedClass *klass)
struct _LibBalsaMimeStreamSharedLock {
GThread *thread;
guint count;
- guint ref_count;
+ gatomicrefcount ref_count;
};
static LibBalsaMimeStreamSharedLock *
@@ -110,10 +110,10 @@ lbmss_lock_new(void)
{
LibBalsaMimeStreamSharedLock *lock;
- lock = g_new(LibBalsaMimeStreamSharedLock, 1);
- lock->thread = 0;
- lock->count = 0;
- lock->ref_count = 1;
+ lock = g_new(LibBalsaMimeStreamSharedLock, 1);
+ lock->thread = 0;
+ lock->count = 0;
+ g_atomic_ref_count_init(&lock->ref_count);
return lock;
}
@@ -122,7 +122,7 @@ lbmss_lock_new(void)
static LibBalsaMimeStreamSharedLock *
lbmss_lock_ref(LibBalsaMimeStreamSharedLock *lock)
{
- ++lock->ref_count;
+ g_atomic_ref_count_inc(&lock->ref_count);
return lock;
}
@@ -131,9 +131,7 @@ lbmss_lock_ref(LibBalsaMimeStreamSharedLock *lock)
static void
lbmss_lock_unref(LibBalsaMimeStreamSharedLock *lock)
{
- g_assert(lock->ref_count > 0);
-
- if (--lock->ref_count == 0)
+ if (g_atomic_ref_count_dec(&lock->ref_count))
g_free(lock);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]