[gtk/wip/ebassi/shortcut: 196/203] Use gatomicrefcount
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/ebassi/shortcut: 196/203] Use gatomicrefcount
- Date: Mon, 10 Feb 2020 11:44:23 +0000 (UTC)
commit 3841f8cac7a7dfa29c05a54589a510d61f5a2226
Author: Emmanuele Bassi <ebassi gnome org>
Date: Thu Feb 6 18:22:41 2020 +0000
Use gatomicrefcount
Instead of unchecked atomic operations on integers.
gtk/gtkshortcutaction.c | 9 ++++-----
gtk/gtkshortcuttrigger.c | 9 ++++-----
2 files changed, 8 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkshortcutaction.c b/gtk/gtkshortcutaction.c
index 6ecccb9ed2..8f1b38b8a6 100644
--- a/gtk/gtkshortcutaction.c
+++ b/gtk/gtkshortcutaction.c
@@ -50,7 +50,7 @@ struct _GtkShortcutAction
{
const GtkShortcutActionClass *action_class;
- volatile int ref_count;
+ gatomicrefcount ref_count;
};
struct _GtkShortcutActionClass
@@ -94,11 +94,10 @@ gtk_shortcut_action_new (const GtkShortcutActionClass *action_class)
g_return_val_if_fail (action_class != NULL, NULL);
self = g_malloc0 (action_class->struct_size);
+ g_atomic_ref_count_init (&self->ref_count);
self->action_class = action_class;
- self->ref_count = 1;
-
return self;
}
@@ -115,7 +114,7 @@ gtk_shortcut_action_ref (GtkShortcutAction *action)
{
g_return_val_if_fail (GTK_IS_SHORTCUT_ACTION (action), NULL);
- g_atomic_int_inc (&action->ref_count);
+ g_atomic_ref_count_inc (&action->ref_count);
return action;
}
@@ -134,7 +133,7 @@ gtk_shortcut_action_unref (GtkShortcutAction *action)
{
g_return_if_fail (GTK_IS_SHORTCUT_ACTION (action));
- if (g_atomic_int_dec_and_test (&action->ref_count))
+ if (g_atomic_ref_count_dec (&action->ref_count))
gtk_shortcut_action_finalize (action);
}
diff --git a/gtk/gtkshortcuttrigger.c b/gtk/gtkshortcuttrigger.c
index 43a9e77c1e..d57f526e94 100644
--- a/gtk/gtkshortcuttrigger.c
+++ b/gtk/gtkshortcuttrigger.c
@@ -49,7 +49,7 @@ struct _GtkShortcutTrigger
{
const GtkShortcutTriggerClass *trigger_class;
- volatile int ref_count;
+ gatomicrefcount ref_count;
};
struct _GtkShortcutTriggerClass
@@ -98,11 +98,10 @@ gtk_shortcut_trigger_new (const GtkShortcutTriggerClass *trigger_class)
g_return_val_if_fail (trigger_class != NULL, NULL);
self = g_malloc0 (trigger_class->struct_size);
+ g_atomic_ref_count_init (&self->ref_count);
self->trigger_class = trigger_class;
- self->ref_count = 1;
-
return self;
}
@@ -119,7 +118,7 @@ gtk_shortcut_trigger_ref (GtkShortcutTrigger *trigger)
{
g_return_val_if_fail (GTK_IS_SHORTCUT_TRIGGER (trigger), NULL);
- g_atomic_int_inc (&trigger->ref_count);
+ g_atomic_ref_count_inc (&trigger->ref_count);
return trigger;
}
@@ -138,7 +137,7 @@ gtk_shortcut_trigger_unref (GtkShortcutTrigger *trigger)
{
g_return_if_fail (GTK_IS_SHORTCUT_TRIGGER (trigger));
- if (g_atomic_int_dec_and_test (&trigger->ref_count))
+ if (g_atomic_ref_count_dec (&trigger->ref_count))
gtk_shortcut_trigger_finalize (trigger);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]