[glib] GAsyncQueue: Remove excessive atomic operations



commit a33abe9c21c3c749c787619e6a661ca2a12f9b45
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat May 28 21:43:45 2011 -0400

    GAsyncQueue: Remove excessive atomic operations
    
    Almost every function was double-checking the ref count,
    unnecessarily.

 glib/gasyncqueue.c |   17 -----------------
 1 files changed, 0 insertions(+), 17 deletions(-)
---
diff --git a/glib/gasyncqueue.c b/glib/gasyncqueue.c
index ff4ad09..faca3c5 100644
--- a/glib/gasyncqueue.c
+++ b/glib/gasyncqueue.c
@@ -156,7 +156,6 @@ GAsyncQueue *
 g_async_queue_ref (GAsyncQueue *queue)
 {
   g_return_val_if_fail (queue, NULL);
-  g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
   
   g_atomic_int_inc (&queue->ref_count);
 
@@ -177,7 +176,6 @@ void
 g_async_queue_ref_unlocked (GAsyncQueue *queue)
 {
   g_return_if_fail (queue);
-  g_return_if_fail (g_atomic_int_get (&queue->ref_count) > 0);
   
   g_atomic_int_inc (&queue->ref_count);
 }
@@ -199,7 +197,6 @@ void
 g_async_queue_unref_and_unlock (GAsyncQueue *queue)
 {
   g_return_if_fail (queue);
-  g_return_if_fail (g_atomic_int_get (&queue->ref_count) > 0);
 
   g_mutex_unlock (queue->mutex);
   g_async_queue_unref (queue);
@@ -219,7 +216,6 @@ void
 g_async_queue_unref (GAsyncQueue *queue)
 {
   g_return_if_fail (queue);
-  g_return_if_fail (g_atomic_int_get (&queue->ref_count) > 0);
   
   if (g_atomic_int_dec_and_test (&queue->ref_count))
     {
@@ -246,7 +242,6 @@ void
 g_async_queue_lock (GAsyncQueue *queue)
 {
   g_return_if_fail (queue);
-  g_return_if_fail (g_atomic_int_get (&queue->ref_count) > 0);
 
   g_mutex_lock (queue->mutex);
 }
@@ -261,7 +256,6 @@ void
 g_async_queue_unlock (GAsyncQueue *queue)
 {
   g_return_if_fail (queue);
-  g_return_if_fail (g_atomic_int_get (&queue->ref_count) > 0);
 
   g_mutex_unlock (queue->mutex);
 }
@@ -277,7 +271,6 @@ void
 g_async_queue_push (GAsyncQueue* queue, gpointer data)
 {
   g_return_if_fail (queue);
-  g_return_if_fail (g_atomic_int_get (&queue->ref_count) > 0);
   g_return_if_fail (data);
 
   g_mutex_lock (queue->mutex);
@@ -297,7 +290,6 @@ void
 g_async_queue_push_unlocked (GAsyncQueue* queue, gpointer data)
 {
   g_return_if_fail (queue);
-  g_return_if_fail (g_atomic_int_get (&queue->ref_count) > 0);
   g_return_if_fail (data);
 
   g_queue_push_head (&queue->queue, data);
@@ -450,7 +442,6 @@ g_async_queue_pop (GAsyncQueue* queue)
   gpointer retval;
 
   g_return_val_if_fail (queue, NULL);
-  g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
 
   g_mutex_lock (queue->mutex);
   retval = g_async_queue_pop_intern_unlocked (queue, FALSE, NULL);
@@ -473,7 +464,6 @@ gpointer
 g_async_queue_pop_unlocked (GAsyncQueue* queue)
 {
   g_return_val_if_fail (queue, NULL);
-  g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
 
   return g_async_queue_pop_intern_unlocked (queue, FALSE, NULL);
 }
@@ -494,7 +484,6 @@ g_async_queue_try_pop (GAsyncQueue* queue)
   gpointer retval;
 
   g_return_val_if_fail (queue, NULL);
-  g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
 
   g_mutex_lock (queue->mutex);
   retval = g_async_queue_pop_intern_unlocked (queue, TRUE, NULL);
@@ -518,7 +507,6 @@ gpointer
 g_async_queue_try_pop_unlocked (GAsyncQueue* queue)
 {
   g_return_val_if_fail (queue, NULL);
-  g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
 
   return g_async_queue_pop_intern_unlocked (queue, TRUE, NULL);
 }
@@ -543,7 +531,6 @@ g_async_queue_timed_pop (GAsyncQueue* queue, GTimeVal *end_time)
   gpointer retval;
 
   g_return_val_if_fail (queue, NULL);
-  g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
 
   g_mutex_lock (queue->mutex);
   retval = g_async_queue_pop_intern_unlocked (queue, FALSE, end_time);
@@ -571,7 +558,6 @@ gpointer
 g_async_queue_timed_pop_unlocked (GAsyncQueue* queue, GTimeVal *end_time)
 {
   g_return_val_if_fail (queue, NULL);
-  g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
 
   return g_async_queue_pop_intern_unlocked (queue, FALSE, end_time);
 }
@@ -596,7 +582,6 @@ g_async_queue_length (GAsyncQueue* queue)
   gint retval;
 
   g_return_val_if_fail (queue, 0);
-  g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, 0);
 
   g_mutex_lock (queue->mutex);
   retval = queue->queue.length - queue->waiting_threads;
@@ -624,7 +609,6 @@ gint
 g_async_queue_length_unlocked (GAsyncQueue* queue)
 {
   g_return_val_if_fail (queue, 0);
-  g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, 0);
 
   return queue->queue.length - queue->waiting_threads;
 }
@@ -715,7 +699,6 @@ GMutex*
 _g_async_queue_get_mutex (GAsyncQueue* queue)
 {
   g_return_val_if_fail (queue, NULL);
-  g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
 
   return queue->mutex;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]