diff --git a/gobject/gobject.c b/gobject/gobject.c
index 56e6f9e..bbccc48 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -2130,6 +2130,49 @@ g_object_remove_weak_pointer (GObject  *object,
                        weak_pointer_location);
 }
 
+#define LOCK_BIT (sizeof (guint) * 8 - 1)
+void
+g_object_lock (gpointer _object)
+{
+  GObject *object = _object;
+
+  g_return_val_if_fail (G_IS_OBJECT (object), NULL);
+  g_return_val_if_fail (object->ref_count > 0, NULL);
+
+  g_bit_lock (&object->ref_count, LOCK_BIT);
+}
+
+gboolean
+g_object_trylock (gpointer _object)
+{
+  GObject *object = _object;
+
+  g_return_val_if_fail (G_IS_OBJECT (object), NULL);
+  g_return_val_if_fail (object->ref_count > 0, NULL);
+
+  return g_bit_trylock (&object->ref_count, LOCK_BIT);
+}
+
+void g_object_unlock (gpointer _object)
+{
+  GObject *object = _object;
+  gint old_ref;
+  gboolean is_zero;
+
+  g_return_if_fail (G_IS_OBJECT (object));
+  g_return_if_fail (object->ref_count & (1 << LOCK_BIT));
+
+  g_bit_unlock (&object->ref_count, LOCK_BIT);
+
+  old_ref = g_atomic_int_get (&object->ref_count);
+  if (old_ref == 0) {
+    /* Do proper disposal */
+    g_atomic_int_inc ((int *) &object->ref_count);
+    g_object_unref (object);
+  }
+}
+
+
 static guint
 object_floating_flag_handler (GObject        *object,
                               gint            job)
@@ -2425,7 +2468,7 @@ g_object_unref (gpointer _object)
   gboolean is_zero;
   
   g_return_if_fail (G_IS_OBJECT (object));
-  g_return_if_fail (object->ref_count > 0);
+  g_return_if_fail ((object->ref_count & ~(1 << LOCK_BIT)) > 0);
   
 #ifdef  G_ENABLE_DEBUG
   if (g_trap_object_ref == object)
diff --git a/gobject/gobject.h b/gobject/gobject.h
index 751e5f2..bdb2907 100644
--- a/gobject/gobject.h
+++ b/gobject/gobject.h
@@ -450,6 +450,9 @@ void        g_object_add_weak_pointer         (GObject        *object,
                                                gpointer       *weak_pointer_location);
 void        g_object_remove_weak_pointer      (GObject        *object, 
                                                gpointer       *weak_pointer_location);
+void        g_object_lock                     (gpointer        object);
+gboolean    g_object_trylock                  (gpointer        object);
+void        g_object_unlock                   (gpointer        object);
 
 /**
  * GToggleNotify:
