static void SIMIX_synchro_finish(smx_action_t action) { XBT_IN("(%p)",action); smx_simcall_t simcall = xbt_fifo_shift(action->simcalls); switch (action->state) { case SIMIX_SRC_TIMEOUT: SMX_EXCEPTION(simcall->issuer, timeout_error, 0, "Synchro's wait timeout"); break; case SIMIX_FAILED: simcall->issuer->context->iwannadie = 1; // SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed"); break; default: THROW_IMPOSSIBLE; break; } SIMIX_synchro_stop_waiting(simcall->issuer, simcall); simcall->issuer->waiting_action = NULL; SIMIX_synchro_destroy(action); SIMIX_simcall_answer(simcall); XBT_OUT(); }
/** * \brief Signalizes a condition. * * Signalizes a condition and wakes up a sleeping process. * If there are no process sleeping, no action is done. * \param cond A condition */ void SIMIX_cond_signal(smx_cond_t cond) { XBT_IN("(%p)",cond); smx_process_t proc = NULL; smx_mutex_t mutex = NULL; smx_simcall_t simcall = NULL; XBT_DEBUG("Signal condition %p", cond); /* If there are processes waiting for the condition choose one and try to make it acquire the mutex */ if ((proc = xbt_swag_extract(cond->sleeping))) { /* Destroy waiter's synchro action */ SIMIX_synchro_destroy(proc->waiting_action); proc->waiting_action = NULL; /* Now transform the cond wait simcall into a mutex lock one */ simcall = &proc->simcall; if(simcall->call == SIMCALL_COND_WAIT) mutex = simcall_cond_wait__get__mutex(simcall); else mutex = simcall_cond_wait_timeout__get__mutex(simcall); simcall->call = SIMCALL_MUTEX_LOCK; SIMIX_pre_mutex_lock(simcall, mutex); } XBT_OUT(); }
/** @brief release the semaphore * * Unlock a process waiting on the semaphore. * If no one was blocked, the semaphore capacity is increased by 1. */ void SIMIX_sem_release(smx_sem_t sem) { XBT_IN("(%p)",sem); smx_process_t proc; XBT_DEBUG("Sem release semaphore %p", sem); if ((proc = xbt_swag_extract(sem->sleeping))) { SIMIX_synchro_destroy(proc->waiting_action); proc->waiting_action = NULL; SIMIX_simcall_answer(&proc->simcall); } else if (sem->value < SMX_SEM_NOLIMIT) { sem->value++; } XBT_OUT(); }
/** * \brief Unlocks a mutex. * * Unlocks the mutex and gives it to a process waiting for it. * If the unlocker is not the owner of the mutex nothing happens. * If there are no process waiting, it sets the mutex as free. * \param mutex The mutex * \param issuer The process trying to unlock the mutex */ void SIMIX_mutex_unlock(smx_mutex_t mutex, smx_process_t issuer) { XBT_IN("(%p, %p)",mutex,issuer); smx_process_t p; /*process to wake up */ /* If the mutex is not owned by the issuer do nothing */ if (issuer != mutex->owner){ XBT_OUT(); return; } if (xbt_swag_size(mutex->sleeping) > 0) { p = xbt_swag_extract(mutex->sleeping); SIMIX_synchro_destroy(p->waiting_action); p->waiting_action = NULL; mutex->owner = p; SIMIX_simcall_answer(&p->simcall); } else { /* nobody to wake up */ mutex->locked = 0; mutex->owner = NULL; } XBT_OUT(); }