Index: glib/gobject/gobject.c
===================================================================
--- glib.orig/gobject/gobject.c
+++ glib/gobject/gobject.c
@@ -2376,11 +2376,12 @@ g_object_unref (gpointer _object)
   old_ref = g_atomic_int_get (&object->ref_count);
   if (old_ref > 1)
     {
+      gboolean do_toggle_ref_notify = (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object));
       if (!g_atomic_int_compare_and_exchange (&object->ref_count, old_ref, old_ref - 1))
 	goto retry_atomic_decrement1;
 
       /* if we went from 2->1 we need to notify toggle refs if any */
-      if (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object))
+      if (do_toggle_ref_notify)
 	toggle_refs_notify (object, TRUE);
     }
   else
@@ -2393,11 +2394,12 @@ g_object_unref (gpointer _object)
       old_ref = g_atomic_int_get (&object->ref_count);
       if (old_ref > 1)
         {
+          gboolean do_toggle_ref_notify = (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object));
           if (!g_atomic_int_compare_and_exchange (&object->ref_count, old_ref, old_ref - 1))
 	    goto retry_atomic_decrement2;
 
           /* if we went from 2->1 we need to notify toggle refs if any */
-          if (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object))
+          if (do_toggle_ref_notify)
 	    toggle_refs_notify (object, TRUE);
           
 	  return;
