Ejemplo n.º 1
0
void init_descriptors()
{
	gdt_install();
	idt_install();
	init_handlers();
	irq_install();
}
Ejemplo n.º 2
0
static ErlDrvData
tcbdb_start    (ErlDrvPort     port,
                char*          buf)
{
  ErlDrvSysInfo info;
  TcDriverData* d = (TcDriverData*) driver_alloc (sizeof (TcDriverData));
  (void) buf;

  memset (d, 0, sizeof (TcDriverData));

  d->ref_count = 1;
  d->port = port;
  d->bdb = tcbdbnew ();
  driver_system_info (&info, sizeof (info));
  if (info.thread_support && info.async_threads > 0)
    {
      d->async_threads = 1;
    }
  d->cur = tcbdbcurnew (d->bdb);
  init_handlers (d->handlers);

  d->magic = ((intptr_t) d) >> 8;

  return (ErlDrvData) d;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[]) {
	if(access("config.json", F_OK)) {
		// no config file.
		printf("[core\tfail] no config file (config.json) found, exiting..\n");
		exit(-1);
	}

	b.admin = "svkampen";

	load_config(&b);
	load_protocol(&b);

	init_handlers();
	b.proto->init(&b);

	b.proto->connect();
	b.proto->tick();
	b.proto->destroy();
	destroy();

	dlclose(b.proto->protolib);

	printf("[core\tinfo] bye!\n");
	return 0;
}
Ejemplo n.º 4
0
int load_handlers( char *base_dir, struct _handler ***list, int count ) {
	int new_count = 0;

	new_count = load_handlers_from_dir( base_dir, list, count );
	init_handlers( (*list), new_count );

	return new_count;
}
int main(int argc, char *argv[])
{
    int res = 0;

    /* Parse command line parameters */
    if (0 != (res = parse_peer_params(argc, argv, &proc_id, &fname))) {
        dbg_err("parse_args() returned nonzero status:%d", res);
        goto end;
    }

    /*
     * Parse the DME simulation config file.
     */
    if (0 != (res = parse_file(fname, proc_id, &nodes, &nodes_count))) {
        dbg_err("parse_file() returned nonzero status:%d", res);
        goto end;
    }

    /* Initialize and allocate any structures/vars used by the generic algorithm */

    /* struct genericstruct = calloc(...) */

    /*
     * Init connections (open listening socket)
     */
    if (0 != (res = open_listen_socket(proc_id, nodes, nodes_count))) {
        dbg_err("open_listen_socket() returned nonzero status:%d", res);
        goto end;
    }

    /*
     * Register signals (for I/O, alarms, etc.)
     */
    if (0 != (res = init_handlers(nodes[proc_id].sock_fd))) {
        dbg_err("init_handlers() returned nonzero status");
        goto end;
    }

    /* Register event handlers that will be called automatically on event occurrence */
    register_event_handler(DME_EV_SUP_MSG_IN, handle_supervisor_msg);
    register_event_handler(DME_EV_PEER_MSG_IN, handle_peer_msg);
    register_event_handler(DME_EV_WANT_CRITICAL_REG, process_ev_want_cr);
    register_event_handler(DME_EV_ENTERED_CRITICAL_REG, process_ev_entered_cr);
    register_event_handler(DME_EV_EXITED_CRITICAL_REG, process_ev_exited_cr);

    /*
     * Main loop: just sit here and wait for events (triggered by the supervisor).
     * All work is done in interrupt handlers mapped to registered functions.
     */
    wait_events();

end:
    /*
     * Do cleanup (deallocating dynamic structures)
     */
    deinit_handlers();

    /* Close our listening socket */
    if (nodes && nodes[proc_id].sock_fd > 0) {
        close(nodes[proc_id].sock_fd);
    }

    /* Free allocated structures */
    safe_free(nodes);

    return res;
}
int main(int argc, char *argv[])
{
    int res = 0;
    
    if (0 != (res = parse_sup_params(argc, argv, &fname, &logfname,
                                     &concurency_ratio, &max_concurrent_proc,
                                     &election_interval, &number_of_runs))) {
        dbg_err("parse_args() returned nonzero status:%d", res);
        goto end;
    }

    /*
     * Parse the file fname
     */
    if (0 != (res = parse_file(fname, proc_id, &nodes, &nodes_count))) {
        dbg_err("parse_file() returned nonzero status:%d", res);
        goto end;
    }
    dbg_msg("nodes has %d elements", nodes_count);

    /* compute the number of maximum concurrent processes (nearest integer) */
    if (max_concurrent_proc != 0) {
        /* The '-c' option was specified on the command line */
        fixed_concurent_num = TRUE;
    } else {
        /* Compute based on concurrency ratio */
        max_concurrent_proc = (nodes_count * concurency_ratio + 50) / 100;
        fixed_concurent_num = FALSE;
    }

    if (max_concurrent_proc < 2) {
        dbg_err("concurrency ratio or number set too low. At least 2 processes must be concurrent.");
        goto end;
    } else if (max_concurrent_proc > nodes_count) {
        dbg_err("concurrency number is greater than total number of processes. Setting it to maximum.");
        max_concurrent_proc = nodes_count;
    }

    dbg_msg("max_concurrent_proc=%d", max_concurrent_proc);

    randomizer_init();
    
    /* Allocate the statistics collection storage and open the log file */
    synchro_delays = calloc(nodes_count, sizeof(timespec_t));
    response_times = calloc(nodes_count, sizeof(timespec_t));

    if (NULL == (log_fh = fopen(logfname, "w"))) {
        dbg_err("Could not open log file %s for writing", logfname);
        res = ERR_BADFILE;
        goto end;
    }


    /*
     * Init connections (open listening socket)
     */
    if (0 != (res = open_listen_socket(proc_id, nodes, nodes_count))) {
        dbg_err("open_listen_socket() returned nonzero status:%d", res);
        goto end;
    }

    /*
     * Register signals (for I/O, alarms, etc.)
     */
    if (0 != (res = init_handlers(nodes[proc_id].sock_fd))) {
        dbg_err("init_handlers() returned nonzero status");
        goto end;
    }
    
    register_event_handler(DME_SEV_PERIODIC_WORK, do_work);
    register_event_handler(DME_SEV_SYNCRO, syncro);
    register_event_handler(DME_SEV_ENDSIMULATION, end_simulation);
    register_event_handler(DME_SEV_MSG_IN, process_messages);

    /* wait for peers processes to init, then kick start the supervisor */
    sleep(1);
    
    /* Start working; mark time */
    clock_gettime(CLOCK_REALTIME, &tstamp_supervisor_start);

    handle_event(DME_SEV_SYNCRO, &tstamp_supervisor_start);
    sleep(1);

    handle_event(DME_SEV_PERIODIC_WORK, NULL);

    /*
     * Main loop: just sit here and wait for interrupts.
     * All work is done in interrupt handlers mapped to registered functions.
     */
    wait_events();
    
end:
    /*
     * Do cleanup (deallocating dynamic structures)
     */
    deinit_handlers();

    /* Close our listening socket */
    if (nodes && nodes[proc_id].sock_fd > 0) {
        close(nodes[proc_id].sock_fd);
    }

    if (log_fh) {
        fclose(log_fh);
    }

    safe_free(nodes);
    safe_free(synchro_delays);
    safe_free(response_times);
    
    return res;
}