[glib] signals: No need to use atomics for Handler refcount



commit 3e274423bacfa1b702fea93fba9d6d44c650db44
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Feb 21 16:06:24 2013 +0100

    signals: No need to use atomics for Handler refcount
    
    handler_ref and handler_unref_R are always called with the signal
    lock held. This is obvious for handler_unref_R as it even sometimes
    drops this lock, and can be verified quickly for handler_ref by looking
    at all call sites.
    
    This improves the performace about 6% on the emit-handled and the
    emit-handled-generic tests.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=694253

 gobject/gsignal.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
---
diff --git a/gobject/gsignal.c b/gobject/gsignal.c
index cf3aacd..061f16f 100644
--- a/gobject/gsignal.c
+++ b/gobject/gsignal.c
@@ -596,7 +596,7 @@ handler_ref (Handler *handler)
 {
   g_return_if_fail (handler->ref_count > 0);
   
-  g_atomic_int_inc ((int *)&handler->ref_count);
+  handler->ref_count++;
 }
 
 static inline void
@@ -604,13 +604,11 @@ handler_unref_R (guint    signal_id,
                 gpointer instance,
                 Handler *handler)
 {
-  gboolean is_zero;
-
   g_return_if_fail (handler->ref_count > 0);
-  
-  is_zero = g_atomic_int_dec_and_test ((int *)&handler->ref_count);
 
-  if (G_UNLIKELY (is_zero))
+  handler->ref_count--;
+
+  if (G_UNLIKELY (handler->ref_count == 0))
     {
       HandlerList *hlist = NULL;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]