Example #1
0
/** @brief Destroy a message exchange queue.
 *
 * Any remaining content is leaked.
 */
void xbt_queue_free(xbt_queue_t * queue)
{

  xbt_dynar_free(&((*queue)->data));
  xbt_mutex_destroy((*queue)->mutex);
  xbt_cond_destroy((*queue)->not_full);
  xbt_cond_destroy((*queue)->not_empty);
  free(*queue);
  *queue = NULL;
}
Example #2
0
/** Main function */
int main(int argc, char *argv[])
{
    msg_error_t res = MSG_OK;

    /* Argument checking */
    MSG_init(&argc, argv);
    if (argc < 3) {
        XBT_CRITICAL("Usage: %s platform_file deployment_file\n", argv[0]);
        XBT_CRITICAL("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
                     argv[0]);
        exit(1);
    }

    /* Simulation setting */
    MSG_create_environment(argv[1]);

    /* Application deployment */
    MSG_function_register("emigrant", emigrant);
    MSG_function_register("policeman", policeman);
    MSG_launch_application(argv[2]);

    /* Run the simulation */
    mutex = xbt_mutex_init();
    cond = xbt_cond_init();
    res = MSG_main();
    XBT_INFO("Simulation time %g", MSG_get_clock());
    xbt_cond_destroy(cond);
    xbt_mutex_destroy(mutex);

    if (res == MSG_OK)
        return 0;
    else
        return 1;
}                               /* end_of_main */
Example #3
0
void xbt_thread_join(xbt_thread_t thread)
{
  xbt_mutex_acquire(thread->mutex);
  xbt_assert(thread->joinable,
              "Cannot join on %p: wasn't created joinable", thread);
  if (!thread->done) {
    xbt_cond_wait(thread->cond, thread->mutex);
    xbt_mutex_release(thread->mutex);
  }

  xbt_mutex_destroy(thread->mutex);
  xbt_cond_destroy(thread->cond);
  free(thread->name);
  free(thread);

}
Example #4
0
static int xbt_thread_create_wrapper(int argc, char *argv[])
{
  smx_process_t self = SIMIX_process_self();
  xbt_thread_t t =
      (xbt_thread_t) SIMIX_process_self_get_data(self);
  simcall_process_set_data(self, t->father_data);
  t->code(t->userparam);
  if (t->joinable) {
    t->done = 1;
    xbt_mutex_acquire(t->mutex);
    xbt_cond_broadcast(t->cond);
    xbt_mutex_release(t->mutex);
  } else {
    xbt_mutex_destroy(t->mutex);
    xbt_cond_destroy(t->cond);
    free(t->name);
    free(t);
  }
  return 0;
}