Esempio n. 1
0
rust_kernel::rust_kernel(rust_env *env) :
    _log(NULL),
    max_task_id(INIT_TASK_ID-1), // sync_add_and_fetch increments first
    rval(0),
    max_sched_id(1),
    killed(false),
    already_exiting(false),
    sched_reaper(this),
    osmain_driver(NULL),
    non_weak_tasks(0),
    at_exit_runner(NULL),
    at_exit_started(false),
    env(env),
    global_data(0)
{
    // Create the single threaded scheduler that will run on the platform's
    // main thread
    rust_manual_sched_launcher_factory *osmain_launchfac =
        new rust_manual_sched_launcher_factory();
    osmain_scheduler = create_scheduler(osmain_launchfac, 1, false);
    osmain_driver = osmain_launchfac->get_driver();

    // Create the primary scheduler
    rust_thread_sched_launcher_factory *main_launchfac =
        new rust_thread_sched_launcher_factory();
    main_scheduler = create_scheduler(main_launchfac,
                                      env->num_sched_threads,
                                      false);

    sched_reaper.start();
}
Esempio n. 2
0
int main(int argc, char* argv[])
{
	schd = create_scheduler();
	initialize_scheduler(schd, NULL);

	session_1 = create_session();
	initialize_session(session_1, "222.214.218.237", 6601, "1299880", 0);
	set_session_index(session_1, 0);
	add_session(schd, session_1);

	session_2 = create_session();
	initialize_session(session_2, "222.214.218.237", 6601, "1299880", 1);
	set_session_index(session_2, 1);
	add_session(schd, session_2);

	set_surface_mode(schd->surface, mode_2);

	scheduler_start(schd);
	session_start(session_1);
	session_start(session_2);

	scheduler_wait(schd);

	session_stop(session_1);
	session_stop(session_2);
	destroy_session(session_1);
	destroy_session(session_2);

	return 0;
}
Esempio n. 3
0
File: flim.c Progetto: mrdg/flim
struct flim * flm_new()
{
    flim = malloc(sizeof(struct flim));
    initialize_js(flim);
    flim->scheduler = create_scheduler(flim->js_context);
    start_scheduler(flim->scheduler);
    flim->output = create_midi_out();
    return flim;
}
Esempio n. 4
0
struct schedule_helper *create_scheduler(double dt_min, double dt_max,
                                         int maxlen, double start_iterations) {
  double n_slots = dt_max / dt_min;
  int len;

  if (n_slots < (double)(maxlen - 1))
    len = (int)n_slots + 1;
  else
    len = maxlen;

  if (len < 2)
    len = 2;

  struct schedule_helper *sh = NULL;
  sh = (struct schedule_helper *)malloc(sizeof(struct schedule_helper));
  if (sh == NULL)
    return NULL;
  memset(sh, 0, sizeof(struct schedule_helper));

  sh->dt = dt_min;
  sh->dt_1 = 1 / dt_min;

  sh->now = start_iterations;
  sh->buf_len = len;

  sh->circ_buf_count = (int *)calloc(len, sizeof(int));
  if (sh->circ_buf_count == NULL)
    goto failure;

  sh->circ_buf_head = (struct abstract_element **)calloc(
      len * 2, sizeof(struct abstract_element*));
  if (sh->circ_buf_head == NULL)
    goto failure;
  sh->circ_buf_tail = sh->circ_buf_head + len;

  if (sh->dt * sh->buf_len < dt_max) {
    sh->next_scale =
        create_scheduler(dt_min * len, dt_max, maxlen, sh->now + dt_min * len);
    if (sh->next_scale == NULL)
      goto failure;
    sh->next_scale->depth = sh->depth + 1;
  }

  return sh;

failure:
  if (sh != NULL)
    delete_scheduler(sh);
  return NULL;
}
Esempio n. 5
0
int main() {
    struct rlimit rl;
    rl.rlim_max = rl.rlim_cur = 1024*64;
    if (setrlimit(RLIMIT_NOFILE, &rl) < -1) {
        return -1;
    }

    fiber_mutex_init(&mtx);
    memset((char*)sharedArr, 0, 64);

    const char *server_ip = "127.0.0.1";

    struct Scheduler *sch = create_scheduler(8);
    if (sch == NULL) return 0;
    struct TcpServer *server = create_tcp_server(server_ip, 12400, data_processor);
    if (server == NULL) return 0;

    start_scheduler(sch);
    run_tcp_server(sch, server);

    return 0;
}
Esempio n. 6
0
rust_sched_id
rust_kernel::create_scheduler(size_t num_threads) {
    rust_thread_sched_launcher_factory *launchfac =
        new rust_thread_sched_launcher_factory();
    return create_scheduler(launchfac, num_threads, true);
}
Esempio n. 7
0
int schedule_insert(struct schedule_helper *sh, void *data,
                    int put_neg_in_current) {
  struct abstract_element *ae = (struct abstract_element *)data;

  if (put_neg_in_current && ae->t < sh->now) {
    /* insert item into current list */

    sh->current_count++;
    if (sh->current_tail == NULL) {
      sh->current = sh->current_tail = ae;
      ae->next = NULL;
    } else {
      sh->current_tail->next = ae;
      sh->current_tail = ae;
      ae->next = NULL;
    }
    return 0;
  }

  /* insert item into future lists */
  sh->count++;
  double nsteps = (ae->t - sh->now) * sh->dt_1;

  if (nsteps < ((double)sh->buf_len)) {
    /* item fits in array for this scale */

    int i;
    if (nsteps < 0.0)
      i = sh->index;
    else
      i = (int)nsteps + sh->index;
    if (i >= sh->buf_len)
      i -= sh->buf_len;

    if (sh->circ_buf_tail[i] == NULL) {
      sh->circ_buf_count[i] = 1;
      sh->circ_buf_head[i] = sh->circ_buf_tail[i] = ae;
      ae->next = NULL;
    } else {
      sh->circ_buf_count[i]++;

      /* For schedulers other than the first tier, maintain a LIFO ordering */
      if (sh->depth) {
        ae->next = sh->circ_buf_head[i];
        sh->circ_buf_head[i] = ae;
      }

      /* For first-tier scheduler, maintain FIFO ordering */
      else {
        sh->circ_buf_tail[i]->next = ae;
        ae->next = NULL;
        sh->circ_buf_tail[i] = ae;
      }
    }
  } else {
    /* item fits in array for coarser scale */

    if (sh->next_scale == NULL) {
      sh->next_scale = create_scheduler(
          sh->dt * sh->buf_len, sh->dt * sh->buf_len * sh->buf_len, sh->buf_len,
          sh->now + sh->dt * (sh->buf_len - sh->index));
      if (sh->next_scale == NULL)
        return 1;
      sh->next_scale->depth = sh->depth + 1;
    }

    /* insert item at coarser scale and insist that item is not placed in
     * "current" list */
    return schedule_insert(sh->next_scale, data, 0);
  }

  return 0;
}