Exemple #1
0
/** @brief Pop something from the message exchange queue, with a timeout.
 *
 * @see #xbt_queue_pop
 *
 */
void xbt_queue_pop_timed(xbt_queue_t queue, void *const dst, double delay)
{
  double begin = xbt_time();

  xbt_mutex_acquire(queue->mutex);

  if (delay == 0) {
    if (xbt_dynar_is_empty(queue->data)) {
      xbt_mutex_release(queue->mutex);
      THROWF(timeout_error, 0, "Delay = 0, and queue is empty");
    }
  } else {
    while ((xbt_dynar_is_empty(queue->data)) &&
           (delay < 0 || (xbt_time() - begin) <= delay)) {
      XBT_DEBUG("Queue %p empty. Waiting", queue);
      TRY {
        xbt_cond_timedwait(queue->not_empty, queue->mutex,
                           delay < 0 ? -1 : delay - (xbt_time() - begin));
      }
      CATCH_ANONYMOUS {
        xbt_mutex_release(queue->mutex);
        RETHROW;
      }
    }
  }

  xbt_dynar_pop(queue->data, dst);
  xbt_cond_signal(queue->not_full);
  xbt_mutex_release(queue->mutex);
}
Exemple #2
0
void surfxml_bufferstack_pop(int new_one)
{
  if (!new_one)
    surfxml_bufferstack = old_buff;
  else {
    free(surfxml_bufferstack);
    xbt_dynar_pop(surfxml_bufferstack_stack, &surfxml_bufferstack);
  }
}
Exemple #3
0
/** @brief Pop something from the message exchange queue.
 *
 * This is blocking if the queue is empty.
 *
 * @see #xbt_dynar_pop
 *
 */
void xbt_queue_pop(xbt_queue_t queue, void *const dst)
{
  xbt_mutex_acquire(queue->mutex);
  while (xbt_dynar_is_empty(queue->data)) {
    XBT_DEBUG("Queue %p empty. Waiting", queue);
    xbt_cond_wait(queue->not_empty, queue->mutex);
  }
  xbt_dynar_pop(queue->data, dst);
  xbt_cond_signal(queue->not_full);
  xbt_mutex_release(queue->mutex);
}
/** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
 *
 * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
 * error message in that case.
 *
 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
 * on a line. One day maybe, if the maya allow it.
 */
int ETag_surfxml_include_state(void)
{
  fflush(nullptr);
  XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);

  if(xbt_dynar_is_empty(surf_input_buffer_stack)) // nope, that's a true premature EOF. Let the parser die verbosely.
    return 0;

  // Yeah, we were in an <include> Restore state and proceed.
  fclose(surf_file_to_parse);
  xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
  surf_parse_pop_buffer_state();
  xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);

  // Restore the filename for error messages
  free(surf_parsed_filename);
  xbt_dynar_pop(surf_parsed_filename_stack,&surf_parsed_filename);

  return 1;
}
Exemple #5
0
void rctx_wait_bg(void)
{
  /* Do not use xbt_dynar_free or it will lock the dynar, preventing armageddon
   * from working */
  while (!xbt_dynar_is_empty(bg_jobs)) {
    rctx_t rctx = xbt_dynar_getlast_as(bg_jobs, rctx_t);
    wait_it(rctx);
    xbt_dynar_pop(bg_jobs, &rctx);
    rctx_free(rctx);
  }
  xbt_dynar_reset(bg_jobs);
}
Exemple #6
0
int coordinator(int argc, char *argv[])
{
  xbt_dynar_t requests = xbt_dynar_new(sizeof(char *), NULL);   // dynamic vector storing requests (which are char*)
  int CS_used = 0;              // initially the CS is idle
  int todo = AMOUNT_OF_CLIENTS * CS_PER_PROCESS;        // amount of releases we are expecting
  while (todo > 0) {
    msg_task_t task = NULL;
    MSG_task_receive(&task, "coordinator");
    const char *kind = MSG_task_get_name(task); //is it a request or a release?
    if (!strcmp(kind, "request")) {     // that's a request
      char *req = MSG_task_get_data(task);
      if (CS_used) {            // need to push the request in the vector
        XBT_INFO("CS already used. Queue the request");
        xbt_dynar_push(requests, &req);
      } else {                  // can serve it immediatly
        XBT_INFO("CS idle. Grant immediatly");
        msg_task_t answer = MSG_task_create("grant", 0, 1000, NULL);
        MSG_task_send(answer, req);
        CS_used = 1;
      }
    } else {                    // that's a release. Check if someone was waiting for the lock
      if (!xbt_dynar_is_empty(requests)) {
        XBT_INFO("CS release. Grant to queued requests (queue size: %lu)",
              xbt_dynar_length(requests));
        char *req;
        xbt_dynar_pop(requests, &req);
        MSG_task_send(MSG_task_create("grant", 0, 1000, NULL), req);
        todo--;
      } else {                  // nobody wants it
        XBT_INFO("CS release. resource now idle");
        CS_used = 0;
        todo--;
      }
    }
    MSG_task_destroy(task);
  }
  XBT_INFO("Received all releases, quit now");
  return 0;
}