Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do not request status if not requested by caller.
[simgrid.git] / src / xbt / xbt_queue.c
index b609da3..679160c 100644 (file)
@@ -1,7 +1,8 @@
 /* A (synchronized) message queue.                                          */
 /* Popping an empty queue is blocking, as well as pushing a full one        */
 
-/* Copyright (c) 2007 Martin Quinson. All rights reserved.                  */
+/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -14,7 +15,8 @@
 #include "xbt/synchro.h"
 #include "xbt/queue.h"          /* this module */
 #include "gras/virtu.h"
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_queue, xbt, "Message exchanging queue");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_queue, xbt,
+                                "Message exchanging queue");
 
 typedef struct s_xbt_queue_ {
   int capacity;
@@ -31,7 +33,8 @@ typedef struct s_xbt_queue_ {
 xbt_queue_t xbt_queue_new(int capacity, unsigned long elm_size)
 {
   xbt_queue_t res = xbt_new0(s_xbt_queue_t, 1);
-  xbt_assert0(capacity >= 0, "Capacity cannot be negative");
+  if (capacity<0)
+    capacity=0;
 
   res->capacity = capacity;
   res->data = xbt_dynar_new(elm_size, NULL);
@@ -77,7 +80,8 @@ void xbt_queue_push(xbt_queue_t queue, const void *src)
   xbt_mutex_acquire(queue->mutex);
   while (queue->capacity != 0
          && queue->capacity == xbt_dynar_length(queue->data)) {
-    DEBUG2("Capacity of %p exceded (=%d). Waiting", queue, queue->capacity);
+    DEBUG2("Capacity of %p exceded (=%d). Waiting", queue,
+           queue->capacity);
     xbt_cond_wait(queue->not_full, queue->mutex);
   }
   xbt_dynar_push(queue->data, src);
@@ -116,7 +120,8 @@ void xbt_queue_unshift(xbt_queue_t queue, const void *src)
   xbt_mutex_acquire(queue->mutex);
   while (queue->capacity != 0
          && queue->capacity == xbt_dynar_length(queue->data)) {
-    DEBUG2("Capacity of %p exceded (=%d). Waiting", queue, queue->capacity);
+    DEBUG2("Capacity of %p exceded (=%d). Waiting", queue,
+           queue->capacity);
     xbt_cond_wait(queue->not_full, queue->mutex);
   }
   xbt_dynar_unshift(queue->data, src);
@@ -163,15 +168,17 @@ void xbt_queue_push_timed(xbt_queue_t queue, const void *src, double delay)
         queue->capacity == xbt_dynar_length(queue->data)) {
 
       xbt_mutex_release(queue->mutex);
-      THROW2(timeout_error, 0, "Capacity of %p exceded (=%d), and delay = 0",
-             queue, queue->capacity);
+      THROW2(timeout_error, 0,
+             "Capacity of %p exceded (=%d), and delay = 0", queue,
+             queue->capacity);
     }
   } else {
     while (queue->capacity != 0 &&
            queue->capacity == xbt_dynar_length(queue->data) &&
            (delay < 0 || (xbt_time() - begin) <= delay)) {
 
-      DEBUG2("Capacity of %p exceded (=%d). Waiting", queue, queue->capacity);
+      DEBUG2("Capacity of %p exceded (=%d). Waiting", queue,
+             queue->capacity);
       TRY {
         xbt_cond_timedwait(queue->not_full, queue->mutex,
                            delay < 0 ? -1 : delay - (xbt_time() - begin));
@@ -230,7 +237,8 @@ void xbt_queue_pop_timed(xbt_queue_t queue, void *const dst, double delay)
  *
  * @see #xbt_queue_unshift
  */
-void xbt_queue_unshift_timed(xbt_queue_t queue, const void *src, double delay)
+void xbt_queue_unshift_timed(xbt_queue_t queue, const void *src,
+                             double delay)
 {
   double begin = xbt_time();
   xbt_ex_t e;
@@ -242,15 +250,17 @@ void xbt_queue_unshift_timed(xbt_queue_t queue, const void *src, double delay)
         queue->capacity == xbt_dynar_length(queue->data)) {
 
       xbt_mutex_release(queue->mutex);
-      THROW2(timeout_error, 0, "Capacity of %p exceded (=%d), and delay = 0",
-             queue, queue->capacity);
+      THROW2(timeout_error, 0,
+             "Capacity of %p exceded (=%d), and delay = 0", queue,
+             queue->capacity);
     }
   } else {
     while (queue->capacity != 0 &&
            queue->capacity == xbt_dynar_length(queue->data) &&
            (delay < 0 || (xbt_time() - begin) <= delay)) {
 
-      DEBUG2("Capacity of %p exceded (=%d). Waiting", queue, queue->capacity);
+      DEBUG2("Capacity of %p exceded (=%d). Waiting", queue,
+             queue->capacity);
       TRY {
         xbt_cond_timedwait(queue->not_full, queue->mutex,
                            delay < 0 ? -1 : delay - (xbt_time() - begin));
@@ -273,7 +283,8 @@ void xbt_queue_unshift_timed(xbt_queue_t queue, const void *src, double delay)
  * @see #xbt_queue_shift
  *
  */
-void xbt_queue_shift_timed(xbt_queue_t queue, void *const dst, double delay)
+void xbt_queue_shift_timed(xbt_queue_t queue, void *const dst,
+                           double delay)
 {
   double begin = xbt_time();
   xbt_ex_t e;