diff --git a/ChangeLog b/ChangeLog index 91f163f56..1b2898f82 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-02-27 Sebastian Wilhelmi + + * 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 * acglib.m4: quote AC_DEFUN macro names so automake diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 91f163f56..1b2898f82 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +2004-02-27 Sebastian Wilhelmi + + * 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 * acglib.m4: quote AC_DEFUN macro names so automake diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 91f163f56..1b2898f82 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +2004-02-27 Sebastian Wilhelmi + + * 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 * acglib.m4: quote AC_DEFUN macro names so automake diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 91f163f56..1b2898f82 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,11 @@ +2004-02-27 Sebastian Wilhelmi + + * 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 * acglib.m4: quote AC_DEFUN macro names so automake diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 91f163f56..1b2898f82 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +2004-02-27 Sebastian Wilhelmi + + * 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 * acglib.m4: quote AC_DEFUN macro names so automake diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 91f163f56..1b2898f82 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +2004-02-27 Sebastian Wilhelmi + + * 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 * acglib.m4: quote AC_DEFUN macro names so automake diff --git a/glib/gasyncqueue.c b/glib/gasyncqueue.c index 3ed3eb893..71dde1259 100644 --- a/glib/gasyncqueue.c +++ b/glib/gasyncqueue.c @@ -35,7 +35,7 @@ struct _GAsyncQueue GCond *cond; GQueue *queue; guint waiting_threads; - guint ref_count; + gint32 ref_count; }; /** @@ -61,7 +61,8 @@ g_async_queue_new () * 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) @@ -69,17 +70,14 @@ 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) @@ -87,7 +85,7 @@ 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); } /** @@ -97,33 +95,16 @@ g_async_queue_ref_unlocked (GAsyncQueue *queue) * 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); } /** @@ -133,16 +114,24 @@ g_async_queue_unref_and_unlock (GAsyncQueue *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); + } } /** diff --git a/glib/gasyncqueue.h b/glib/gasyncqueue.h index bfc7b69e9..80044e0bc 100644 --- a/glib/gasyncqueue.h +++ b/glib/gasyncqueue.h @@ -46,17 +46,14 @@ GAsyncQueue* g_async_queue_new (void); 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,