Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New thread to receive messages. Not working yet.
[simgrid.git] / src / simix / smx_synchro.c
index f2feb6b..730e2cd 100644 (file)
@@ -96,9 +96,9 @@ int SIMIX_mutex_trylock(smx_mutex_t mutex)
 void SIMIX_mutex_unlock(smx_mutex_t mutex)
 {
        smx_process_t p;        /*process to wake up */
-       
+
        xbt_assert0((mutex != NULL), "Invalid parameters");
-       
+
        if (xbt_swag_size(mutex->sleeping) > 0) {
                p = xbt_swag_extract(mutex->sleeping);
                mutex->using = 0;
@@ -199,6 +199,11 @@ void SIMIX_cond_wait(smx_cond_t cond,smx_mutex_t mutex)
        return;
 }
 
+xbt_fifo_t SIMIX_cond_get_actions(smx_cond_t cond)
+{
+       xbt_assert0((cond != NULL), "Invalid parameters");
+       return cond->actions;
+}
 
 void __SIMIX_cond_wait(smx_cond_t cond)
 {
@@ -221,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
@@ -238,8 +243,19 @@ void SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_durat
                act_sleep = SIMIX_action_sleep(SIMIX_host_self(), max_duration);
                SIMIX_register_action_to_condition(act_sleep,cond);
                SIMIX_register_condition_to_action(act_sleep,cond);
+               __SIMIX_cond_wait(cond);
+               xbt_fifo_remove(act_sleep->cond_list,cond);
+               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);
+               }
+
        }
-       __SIMIX_cond_wait(cond);
+       else
+               __SIMIX_cond_wait(cond);
 
        /* get the mutex again */
        SIMIX_mutex_lock(cond->mutex);