-/* $Id$ */
-
/* 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. */
#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;
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);
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);
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);
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));
*
* @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;
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));
* @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;