コード例 #1
0
ファイル: smx_synchro.c プロジェクト: Shurakai/SimGrid
static void _SIMIX_sem_wait(smx_sem_t sem, double timeout, smx_process_t issuer,
                            smx_simcall_t simcall)
{
  XBT_IN("(%p, %f, %p, %p)",sem,timeout,issuer,simcall);
  smx_action_t sync_act = NULL;

  XBT_DEBUG("Wait semaphore %p (timeout:%f)", sem, timeout);
  if (sem->value <= 0) {
    sync_act = SIMIX_synchro_wait(issuer->smx_host, timeout);
    xbt_fifo_unshift(sync_act->simcalls, simcall);
    issuer->waiting_action = sync_act;
    xbt_swag_insert(issuer, sem->sleeping);
  } else {
    sem->value--;
    SIMIX_simcall_answer(simcall);
  }
  XBT_OUT();
}
コード例 #2
0
static void _SIMIX_sem_wait(smx_sem_t sem, double timeout, smx_actor_t issuer,
                            smx_simcall_t simcall)
{
  XBT_IN("(%p, %f, %p, %p)",sem,timeout,issuer,simcall);
  smx_activity_t synchro = nullptr;

  XBT_DEBUG("Wait semaphore %p (timeout:%f)", sem, timeout);
  if (sem->value <= 0) {
    synchro = SIMIX_synchro_wait(issuer->host, timeout);
    synchro->simcalls.push_front(simcall);
    issuer->waiting_synchro = synchro;
    xbt_swag_insert(issuer, sem->sleeping);
  } else {
    sem->value--;
    SIMIX_simcall_answer(simcall);
  }
  XBT_OUT();
}
コード例 #3
0
ファイル: smx_synchro.c プロジェクト: Shurakai/SimGrid
static void _SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex, double timeout,
                             smx_process_t issuer, smx_simcall_t simcall)
{
  XBT_IN("(%p, %p, %f, %p,%p)",cond,mutex,timeout,issuer,simcall);
  smx_action_t sync_act = NULL;

  XBT_DEBUG("Wait condition %p", cond);

  /* If there is a mutex unlock it */
  /* FIXME: what happens if the issuer is not the owner of the mutex? */
  if (mutex != NULL) {
    cond->mutex = mutex;
    SIMIX_mutex_unlock(mutex, issuer);
  }

  sync_act = SIMIX_synchro_wait(issuer->smx_host, timeout);
  xbt_fifo_unshift(sync_act->simcalls, simcall);
  issuer->waiting_action = sync_act;
  xbt_swag_insert(simcall->issuer, cond->sleeping);   
  XBT_OUT();
}
コード例 #4
0
static void _SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex, double timeout,
                             smx_actor_t issuer, smx_simcall_t simcall)
{
  XBT_IN("(%p, %p, %f, %p,%p)",cond,mutex,timeout,issuer,simcall);
  smx_activity_t synchro = nullptr;

  XBT_DEBUG("Wait condition %p", cond);

  /* If there is a mutex unlock it */
  /* FIXME: what happens if the issuer is not the owner of the mutex? */
  if (mutex != nullptr) {
    cond->mutex = mutex;
    mutex->unlock(issuer);
  }

  synchro = SIMIX_synchro_wait(issuer->host, timeout);
  synchro->simcalls.push_front(simcall);
  issuer->waiting_synchro = synchro;
  xbt_swag_insert(simcall->issuer, cond->sleeping);   
  XBT_OUT();
}
コード例 #5
0
void Mutex::lock(smx_actor_t issuer)
{
  XBT_IN("(%p; %p)", this, issuer);
  /* FIXME: check where to validate the arguments */
  smx_activity_t synchro = nullptr;

  if (this->locked) {
    /* FIXME: check if the host is active ? */
    /* Somebody using the mutex, use a synchronization to get host failures */
    synchro = SIMIX_synchro_wait(issuer->host, -1);
    synchro->simcalls.push_back(&issuer->simcall);
    issuer->waiting_synchro = synchro;
    xbt_swag_insert(issuer, this->sleeping);
  } else {
    /* mutex free */
    this->locked = true;
    this->owner = issuer;
    SIMIX_simcall_answer(&issuer->simcall);
  }
  XBT_OUT();
}
コード例 #6
0
ファイル: smx_synchro.c プロジェクト: Shurakai/SimGrid
/**
 * \brief Handles a mutex lock simcall.
 * \param simcall the simcall
 */
void SIMIX_pre_mutex_lock(smx_simcall_t simcall, smx_mutex_t mutex)
{
  XBT_IN("(%p)",simcall);
  /* FIXME: check where to validate the arguments */
  smx_action_t sync_act = NULL;
  smx_process_t process = simcall->issuer;

  if (mutex->locked) {
    /* FIXME: check if the host is active ? */
    /* Somebody using the mutex, use a synchro action to get host failures */
    sync_act = SIMIX_synchro_wait(process->smx_host, -1);
    xbt_fifo_push(sync_act->simcalls, simcall);
    simcall->issuer->waiting_action = sync_act;
    xbt_swag_insert(simcall->issuer, mutex->sleeping);   
  } else {
    /* mutex free */
    mutex->locked = 1;
    mutex->owner = simcall->issuer;
    SIMIX_simcall_answer(simcall);
  }
  XBT_OUT();
}