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;
*/
void SIMIX_cond_signal(smx_cond_t cond)
{
+ DEBUG1("Signal condition %p",cond);
xbt_assert0((cond != NULL), "Invalid parameters");
smx_process_t proc = NULL;
smx_action_t act_sleep;
xbt_assert0((mutex != NULL), "Invalid parameters");
+ DEBUG1("Wait condition %p",cond);
cond->mutex = mutex;
SIMIX_mutex_unlock(mutex);
/**
* \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
xbt_assert0((mutex != NULL), "Invalid parameters");
smx_action_t act_sleep;
+ DEBUG1("Timed wait condition %p",cond);
cond->mutex = mutex;
SIMIX_mutex_unlock(mutex);
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);
smx_process_t proc = NULL;
smx_process_t proc_next = NULL;
+ DEBUG1("Broadcast condition %p",cond);
xbt_swag_foreach_safe(proc,proc_next,cond->sleeping) {
xbt_swag_remove(proc,cond->sleeping);
xbt_swag_insert(proc, simix_global->process_to_run);
*/
void SIMIX_cond_destroy(smx_cond_t cond)
{
+ DEBUG1("Destroy condition %p",cond);
+ xbt_backtrace_display_current();
if ( cond == NULL )
return ;
else {
- xbt_assert0( xbt_swag_size(cond->sleeping) == 0 , "Cannot destroy conditional");
+ xbt_assert0( xbt_swag_size(cond->sleeping) == 0 , "Cannot destroy conditional since someone is still using it");
xbt_swag_free(cond->sleeping);
xbt_fifo_free(cond->actions);
xbt_free(cond);
{
xbt_assert0( (action != NULL) && (cond != NULL), "Invalid parameters");
+ DEBUG2("Register condition %p to action %p",cond,action);
xbt_fifo_push(action->cond_list,cond);
}