Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Corrected bug.
authordonassbr <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 16 Jul 2007 10:07:21 +0000 (10:07 +0000)
committerdonassbr <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 16 Jul 2007 10:07:21 +0000 (10:07 +0000)
Bug: xbt_queues strangely handled

simix_cond_wait_timeout now raise an exception if the timeout happens.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3798 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/simix/smx_synchro.c
src/xbt/xbt_queue.c

index 9451f5a..730e2cd 100644 (file)
@@ -226,7 +226,7 @@ void __SIMIX_cond_wait(smx_cond_t cond)
 /**
  * \brief Waits on a condition with timeout.
  *
- * Same behavior of #SIMIX_cond_wait, but waits a maximum time.
+ * Same behavior of #SIMIX_cond_wait, but waits a maximum time and throws an timeout_error if it happens.
  * \param cond A condition
  * \param mutex A mutex
  * \param max_duration Timeout time
@@ -245,7 +245,14 @@ void SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_durat
                SIMIX_register_condition_to_action(act_sleep,cond);
                __SIMIX_cond_wait(cond);
                xbt_fifo_remove(act_sleep->cond_list,cond);
-               SIMIX_action_destroy(act_sleep);
+               if ( SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) {
+                       SIMIX_action_destroy(act_sleep);
+                       THROW0(timeout_error,0,"Condition timeout"); 
+               }
+               else {
+                       SIMIX_action_destroy(act_sleep);
+               }
+
        }
        else
                __SIMIX_cond_wait(cond);
index 3bb1fd3..a31ac73 100644 (file)
@@ -145,16 +145,11 @@ void xbt_queue_shift(xbt_queue_t queue, void* const dst) {
  * @see #xbt_queue_push
  */
 void xbt_queue_push_timed(xbt_queue_t queue, const void *src,double delay) {
-        double timeout = xbt_os_time() + delay;
+        double timeout = xbt_time() + delay;
    xbt_mutex_lock(queue->mutex);
-   if (queue->capacity != 0 && queue->capacity == xbt_dynar_length(queue->data)) {
-      DEBUG2("Capacity of %p exceded (=%d). Waiting",queue,queue->capacity);
-      xbt_cond_timedwait(queue->not_full,queue->mutex, delay);
-                       /* check if a timeout occurs */
-                       if (xbt_os_time() >= timeout) {
-                               xbt_mutex_unlock(queue->mutex);
-                               THROW1(timeout_error,0,"Timeout (delay was %f)",delay);
-                       }
+   while ( (queue->capacity != 0) && (queue->capacity == xbt_dynar_length(queue->data)) && (xbt_time() < timeout) ) {
+                DEBUG2("Capacity of %p exceded (=%d). Waiting",queue,queue->capacity);
+                xbt_cond_timedwait(queue->not_full,queue->mutex, timeout - xbt_time());
         }
         xbt_dynar_push(queue->data,src);
         xbt_cond_signal(queue->not_empty);
@@ -168,16 +163,11 @@ void xbt_queue_push_timed(xbt_queue_t queue, const void *src,double delay) {
  * 
  */
 void xbt_queue_pop_timed(xbt_queue_t queue, void* const dst,double delay) {
-        double timeout = xbt_os_time() + delay;
+        double timeout = xbt_time() + delay;
    xbt_mutex_lock(queue->mutex);
-   if (xbt_dynar_length(queue->data) == 0) {
+   while ( (xbt_dynar_length(queue->data) == 0) && (xbt_time() < timeout) ) {
       DEBUG1("Queue %p empty. Waiting",queue);
-      xbt_cond_timedwait(queue->not_empty,queue->mutex,delay);
-                       /* check if a timeout occurs */
-                       if (xbt_os_time() >= timeout) {
-                               xbt_mutex_unlock(queue->mutex);
-                               THROW1(timeout_error,0,"Timeout (delay was %f)",delay);
-                       }
+      xbt_cond_timedwait(queue->not_empty,queue->mutex, timeout - xbt_time());
    }
         xbt_dynar_pop(queue->data,dst);
         xbt_cond_signal(queue->not_full);
@@ -189,16 +179,11 @@ 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) {
-        double timeout = xbt_os_time() + delay;
+        double timeout = xbt_time() + delay;
    xbt_mutex_lock(queue->mutex);
-   if (queue->capacity != 0 && queue->capacity == xbt_dynar_length(queue->data)) {
+   while ( (queue->capacity != 0) && (queue->capacity == xbt_dynar_length(queue->data)) && (xbt_time() < timeout) ) {
       DEBUG2("Capacity of %p exceded (=%d). Waiting",queue,queue->capacity);
-      xbt_cond_timedwait(queue->not_full,queue->mutex,delay);
-                       /* check if a timeout occurs */
-                       if (xbt_os_time() >= timeout) {
-                               xbt_mutex_unlock(queue->mutex);
-                               THROW1(timeout_error,0,"Timeout (delay was %f)",delay);
-                       }
+      xbt_cond_timedwait(queue->not_full,queue->mutex, timeout - xbt_time());
    }
         xbt_dynar_unshift(queue->data,src);
         xbt_cond_signal(queue->not_empty);
@@ -212,16 +197,11 @@ void xbt_queue_unshift_timed(xbt_queue_t queue, const void *src,double delay) {
  * 
  */
 void xbt_queue_shift_timed(xbt_queue_t queue, void* const dst,double delay) {
-        double timeout = xbt_os_time() + delay;
+        double timeout = xbt_time() + delay;
    xbt_mutex_lock(queue->mutex);
-   while (xbt_dynar_length(queue->data) == 0) {
+   while ( (xbt_dynar_length(queue->data) == 0) && (xbt_time() < timeout) ) {
       DEBUG1("Queue %p empty. Waiting",queue);
-      xbt_cond_timedwait(queue->not_empty,queue->mutex,delay);
-                       /* check if a timeout occurs */
-                       if (xbt_os_time() >= timeout) {
-                               xbt_mutex_unlock(queue->mutex);
-                               THROW1(timeout_error,0,"Timeout (delay was %f)",delay);
-                       }
+      xbt_cond_timedwait(queue->not_empty,queue->mutex, timeout - xbt_time());
    }
         xbt_dynar_shift(queue->data,dst);
         xbt_cond_signal(queue->not_full);