mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-23 22:16:16 +01:00
Use g_atomic_int_(inc|dec_and_test) for reference counting.
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.
This commit is contained in:
parent
a4d564c592
commit
4054cc5979
@ -1,3 +1,11 @@
|
||||
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
|
||||
|
@ -1,3 +1,11 @@
|
||||
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
|
||||
|
@ -1,3 +1,11 @@
|
||||
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
|
||||
|
@ -1,3 +1,11 @@
|
||||
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
|
||||
|
@ -1,3 +1,11 @@
|
||||
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
|
||||
|
@ -1,3 +1,11 @@
|
||||
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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user