+2004-02-27 Sebastian Wilhelmi <seppi@seppi.de>
+
+ * glib/gasyncqueue.c, glib/gasyncqueue.h: Use
+ g_atomic_int_(inc|dec_and_test) for reference
+ counting. g_async_queue_unref_and_unlock and
+ g_async_queue_ref_locked is deprecated, but still there to
+ preserve ABI.
+
Fri Feb 27 02:00:34 2004 Matthias Clasen <maclas@gmx.de>
* acglib.m4: quote AC_DEFUN macro names so automake
+2004-02-27 Sebastian Wilhelmi <seppi@seppi.de>
+
+ * glib/gasyncqueue.c, glib/gasyncqueue.h: Use
+ g_atomic_int_(inc|dec_and_test) for reference
+ counting. g_async_queue_unref_and_unlock and
+ g_async_queue_ref_locked is deprecated, but still there to
+ preserve ABI.
+
Fri Feb 27 02:00:34 2004 Matthias Clasen <maclas@gmx.de>
* acglib.m4: quote AC_DEFUN macro names so automake
+2004-02-27 Sebastian Wilhelmi <seppi@seppi.de>
+
+ * glib/gasyncqueue.c, glib/gasyncqueue.h: Use
+ g_atomic_int_(inc|dec_and_test) for reference
+ counting. g_async_queue_unref_and_unlock and
+ g_async_queue_ref_locked is deprecated, but still there to
+ preserve ABI.
+
Fri Feb 27 02:00:34 2004 Matthias Clasen <maclas@gmx.de>
* acglib.m4: quote AC_DEFUN macro names so automake
+2004-02-27 Sebastian Wilhelmi <seppi@seppi.de>
+
+ * glib/gasyncqueue.c, glib/gasyncqueue.h: Use
+ g_atomic_int_(inc|dec_and_test) for reference
+ counting. g_async_queue_unref_and_unlock and
+ g_async_queue_ref_locked is deprecated, but still there to
+ preserve ABI.
+
Fri Feb 27 02:00:34 2004 Matthias Clasen <maclas@gmx.de>
* acglib.m4: quote AC_DEFUN macro names so automake
+2004-02-27 Sebastian Wilhelmi <seppi@seppi.de>
+
+ * glib/gasyncqueue.c, glib/gasyncqueue.h: Use
+ g_atomic_int_(inc|dec_and_test) for reference
+ counting. g_async_queue_unref_and_unlock and
+ g_async_queue_ref_locked is deprecated, but still there to
+ preserve ABI.
+
Fri Feb 27 02:00:34 2004 Matthias Clasen <maclas@gmx.de>
* acglib.m4: quote AC_DEFUN macro names so automake
+2004-02-27 Sebastian Wilhelmi <seppi@seppi.de>
+
+ * glib/gasyncqueue.c, glib/gasyncqueue.h: Use
+ g_atomic_int_(inc|dec_and_test) for reference
+ counting. g_async_queue_unref_and_unlock and
+ g_async_queue_ref_locked is deprecated, but still there to
+ preserve ABI.
+
Fri Feb 27 02:00:34 2004 Matthias Clasen <maclas@gmx.de>
* acglib.m4: quote AC_DEFUN macro names so automake
GCond *cond;
GQueue *queue;
guint waiting_threads;
- guint ref_count;
+ gint32 ref_count;
};
/**
* g_async_queue_ref:
* @queue: a #GAsyncQueue.
*
- * Increases the reference count of the asynchronous @queue by 1.
+ * Increases the reference count of the asynchronous @queue by 1. You
+ * do not need to hold the lock to call this function.
**/
void
g_async_queue_ref (GAsyncQueue *queue)
g_return_if_fail (queue);
g_return_if_fail (queue->ref_count > 0);
- g_mutex_lock (queue->mutex);
- queue->ref_count++;
- g_mutex_unlock (queue->mutex);
+ g_atomic_int_inc (&queue->ref_count);
}
/**
* g_async_queue_ref_unlocked:
* @queue: a #GAsyncQueue.
*
- * Increases the reference count of the asynchronous @queue by 1. This
- * function must be called while holding the @queue's lock.
+ * Increases the reference count of the asynchronous @queue by 1.
**/
void
g_async_queue_ref_unlocked (GAsyncQueue *queue)
g_return_if_fail (queue);
g_return_if_fail (queue->ref_count > 0);
- queue->ref_count++;
+ g_atomic_int_inc (&queue->ref_count);
}
/**
* Decreases the reference count of the asynchronous @queue by 1 and
* releases the lock. This function must be called while holding the
* @queue's lock. If the reference count went to 0, the @queue will be
- * destroyed and the memory allocated will be freed. So you are not
- * allowed to use the @queue afterwards, as it might have disappeared.
- * The obvious asymmetry (it is not named
- * g_async_queue_unref_unlocked(<!-- -->)) is because the queue can't be
- * unlocked after unreffing it, as it might already have disappeared.
+ * destroyed and the memory allocated will be freed.
**/
void
g_async_queue_unref_and_unlock (GAsyncQueue *queue)
{
- gboolean stop;
-
g_return_if_fail (queue);
g_return_if_fail (queue->ref_count > 0);
- queue->ref_count--;
- stop = (queue->ref_count == 0);
g_mutex_unlock (queue->mutex);
-
- if (stop)
- {
- g_return_if_fail (queue->waiting_threads == 0);
- g_mutex_free (queue->mutex);
- if (queue->cond)
- g_cond_free (queue->cond);
- g_queue_free (queue->queue);
- g_free (queue);
- }
+ g_async_queue_unref (queue);
}
/**
* Decreases the reference count of the asynchronous @queue by 1. If
* the reference count went to 0, the @queue will be destroyed and the
* memory allocated will be freed. So you are not allowed to use the
- * @queue afterwards, as it might have disappeared.
+ * @queue afterwards, as it might have disappeared. You do not need to
+ * hold the lock to call this function.
**/
void
g_async_queue_unref (GAsyncQueue *queue)
{
g_return_if_fail (queue);
g_return_if_fail (queue->ref_count > 0);
-
- g_mutex_lock (queue->mutex);
- g_async_queue_unref_and_unlock (queue);
+
+ if (g_atomic_int_dec_and_test (&queue->ref_count))
+ {
+ g_return_if_fail (queue->waiting_threads == 0);
+ g_mutex_free (queue->mutex);
+ if (queue->cond)
+ g_cond_free (queue->cond);
+ g_queue_free (queue->queue);
+ g_free (queue);
+ }
}
/**
void g_async_queue_lock (GAsyncQueue *queue);
void g_async_queue_unlock (GAsyncQueue *queue);
-/* Ref and unref the GAsyncQueue. g_async_queue_unref_unlocked makes
- * no sense, as after the unreffing the Queue might be gone and can't
- * be unlocked. So you have a function to call, if you don't hold the
- * lock (g_async_queue_unref) and one to call, when you already hold
- * the lock (g_async_queue_unref_and_unlock). After that however, you
- * don't hold the lock anymore and the Queue might in fact be
- * destroyed, if you unrefed to zero. */
+/* Ref and unref the GAsyncQueue. */
void g_async_queue_ref (GAsyncQueue *queue);
-void g_async_queue_ref_unlocked (GAsyncQueue *queue);
void g_async_queue_unref (GAsyncQueue *queue);
+#ifndef G_DISABLE_DEPRECATED
+/* You don't have to hold the lock for calling *_ref and *_unref anymore. */
+void g_async_queue_ref_unlocked (GAsyncQueue *queue);
void g_async_queue_unref_and_unlock (GAsyncQueue *queue);
+#endif /* !G_DISABLE_DEPRECATED */
/* Push data into the async queue. Must not be NULL. */
void g_async_queue_push (GAsyncQueue *queue,