Esempio n. 1
0
static PLI_INT32 from_myhdl_calltf(PLI_BYTE8 *user_data)
{
  vpiHandle reg_iter, reg_handle;
  s_vpi_time verilog_time_s;
  char buf[MAXLINE];
  char s[MAXWIDTH];
  int n;

  static int from_myhdl_flag = 0;

  if (from_myhdl_flag) {
    vpi_printf("ERROR: $from_myhdl called more than once\n");
    vpi_control(vpiFinish, 1);  /* abort simulation */
    return(0);
  }
  from_myhdl_flag = 1;

  init_pipes();

  verilog_time_s.type = vpiSimTime;
  vpi_get_time(NULL, &verilog_time_s);
  verilog_time = timestruct_to_time(&verilog_time_s);
  if (verilog_time != 0) {
    vpi_printf("ERROR: $from_myhdl should be called at time 0\n");
    vpi_control(vpiFinish, 1);  /* abort simulation */
    return(0);
  }
  sprintf(buf, "FROM 0 ");
  pli_time = 0;
  delta = 0;

  from_myhdl_systf_handle = vpi_handle(vpiSysTfCall, NULL);
  reg_iter = vpi_iterate(vpiArgument, from_myhdl_systf_handle);
  while ((reg_handle = vpi_scan(reg_iter)) != NULL) {
    if (vpi_get(vpiType, reg_handle) != vpiReg) {
      vpi_printf("ERROR: $from_myhdl argument %s should be a reg\n",
		 vpi_get_str(vpiName, reg_handle));
      vpi_control(vpiFinish, 1);  /* abort simulation */
      return(0);
    }
    strcat(buf, vpi_get_str(vpiName, reg_handle));
    strcat(buf, " ");
    sprintf(s, "%d ", vpi_get(vpiSize, reg_handle));
    strcat(buf, s);
    vpi_free_object(reg_handle);
  }
  //vpi_free_object(reg_iter);

  n = write(wpipe, buf, strlen(buf));  

  if ((n = read(rpipe, buf, MAXLINE)) == 0) {
    vpi_printf("Info: MyHDL simulator down\n");
    vpi_control(vpiFinish, 1);  /* abort simulation */
    return(0);
  }
  assert(n > 0);
  buf[n] = '\0';

  return(0);
}
Esempio n. 2
0
void Model::init_items(){
    QJsonObject json_obj= read_json_file(":/map/items_1.json");
    QJsonArray blocks_array = json_obj.value(QString("items")).toObject()["block"].toArray();
    init_blocks(blocks_array);
    QJsonArray coins_array = json_obj.value(QString("items")).toObject()["coins"].toArray();
    init_coins(coins_array);
    QJsonArray pipes_array = json_obj.value(QString("items")).toObject()["pipes"].toArray();
    init_pipes(pipes_array);
    QJsonArray decor_array = json_obj.value(QString("items")).toObject()["decor"].toArray();
    init_decor(decor_array);
}
Esempio n. 3
0
File: sh.c Progetto: amazonsx/nos
int main(int argc, char *argv[])
{
	char buf[MAX] = {0};
	int count = 0;
	while ((count = get_cmds(buf, MAX)) > 0) {
#if DEBUG == 1
		print_cmds(count);
#endif
		run_cmds(buf);
		init_pipes();
	}
}
Esempio n. 4
0
/* Initialize all kernel subsystems and run system */
int main(void) {
	printa("In main %x\n", (unsigned)main);
	init_int();
	init_page_alloc();
	init_pipes();
	init_scheduler();

	add_task(&init_systems);

	while (1) {
		schedule();
	}

	return 0;
}
Esempio n. 5
0
//-----------------------------------------------------------------------------
void init( int argc, char* argv[] ) {
  // * set variables from constants *
  cpu = DEFAULT_CPU;

  // * open error logs *
  std::string log_name = "info.log";

  info = log_c( log_name );
  log_c::error_e log_err;
  log_err = info.allocate( LOG_CAPACITY );
  if( log_err != log_c::ERROR_NONE ) {
    sprintf( errstr, "(coordinator.cpp) init() failed calling log_c::allocate(...).\nExiting\n" ); 
    printf( "%s", errstr );
    exit( 1 );
  }

  // * get the process identifier *
  coordinator_pid = getpid( );
  printf( "coordinator pid: %d\n", coordinator_pid );

  // * bind the process to a single cpu *
  if( cpu_c::bind( coordinator_pid, cpu ) != cpu_c::ERROR_NONE ) {
    sprintf( errstr, "(coordinator.cpp) init() failed calling cpu_c::bind(coordinator_pid,DEFAULT_CPU).\nExiting\n" );
    //error_log.write( errstr );
    printf( "%s", errstr );

    //error_log.close( );
    exit( 1 );
  }

  // * set the process to be scheduled with realtime policy and max priority *
  if( scheduler_c::set_realtime_policy( coordinator_pid, coordinator_priority ) != scheduler_c::ERROR_NONE ) {
    sprintf( errstr, "(coordinator.cpp) init() failed calling schedule_set_realtime_max(coordinator_pid,coordinator_priority).\nExiting\n" );
    //error_log.write( errstr );
    printf( "%s", errstr );

    //error_log.close( );
    exit( 1 );
  }
  printf( "coordinator process priority: %d\n", coordinator_priority );

  // * determine if the OS supports high resolution timers *
  struct timespec res;
  clock_getres( CLOCK_MONOTONIC, &res );
  double clock_res = timespec_to_real( res );
  printf( "Clock resolution (secs): %10.9f\n", clock_res );

  if( res.tv_sec != 0 && res.tv_nsec != 1 ) {
    sprintf( errstr, "(coordinator.cpp) init() failed.  The host operating system does not support high resolution timers.  Consult your system documentation on enabling this feature.\nExiting\n" );
    //error_log.write( errstr );
    printf( "%s", errstr );

    //error_log.close( );
    exit( 1 );
  }

  // * get the cpu speed *
  if( cpu_c::get_speed( cpu_speed, cpu ) != cpu_c::ERROR_NONE ) {
    sprintf( errstr, "(coordinator.cpp) init() failed calling cpu_c::get_frequency(cpu_speed,cpu)\nExiting\n" );
    //error_log.write( errstr );
    printf( "%s", errstr );

    //error_log.close( );
    exit( 1 );
  }

  // * initialize pipes *
  if( !init_pipes() ) {
    sprintf( errstr, "(coordinator.cpp) init() failed calling init_pipes()\nExiting\n" );
    //error_log.write( errstr );
    printf( "%s", errstr );

    //error_log.close( );
    exit( 1 );
  }

  // * initialize shared memory *
  msgbuffer = client_message_buffer_c( CLIENT_MESSAGE_BUFFER_NAME, CLIENT_MESSAGE_BUFFER_MUTEX_NAME, true );
  if( msgbuffer.open( ) != client_message_buffer_c::ERROR_NONE ) {
    sprintf( errstr, "(coordinator.cpp) init() failed calling actuator_msg_buffer_c.open(...,true)\n" );
    //error_log.write( errstr );
    printf( "%s", errstr );

    close_pipes( );
    //error_log.close( );
    exit( 1 );
  }

  // * initialize clients *
/*
  CLIENT_MAX_PRIORITY = coordinator_priority - 1;
  CLIENT_MIN_PRIORITY = coordinator_priority - 3;
  int client_priority_step = CLIENT_MAX_PRIORITY - CLIENT_MIN_PRIORITY;

  processor = boost::shared_ptr<processor_c>( new processor_c() );
  processor->name = "processor";

  dynamics = boost::shared_ptr<dynamics_c>( new dynamics_c() );
  dynamics->name = "dynamics";

  prey = boost::shared_ptr<timesink_c>( new timesink_c( scheduler_c::PROGRESS) );
  prey->name = "prey_timesink";
  prey_controller = boost::shared_ptr<osthread_c>( new osthread_c(&select, &read_notifications) );
  prey_controller->name = "prey_controller";
  prey_controller->_max_priority = CLIENT_MAX_PRIORITY;
  prey_controller->_min_priority = CLIENT_MIN_PRIORITY;
  prey_controller->_priority_step = client_priority_step;

  pred = boost::shared_ptr<timesink_c>( new timesink_c(scheduler_c::PRIORITY) );
  pred->name = "pred_timesink";
  pred_controller = boost::shared_ptr<osthread_c>( new osthread_c(&select, &read_notifications) );
  pred_controller->name = "pred_controller";
  pred_controller->_max_priority = CLIENT_MAX_PRIORITY;
  pred_controller->_min_priority = CLIENT_MIN_PRIORITY;
  pred_controller->_priority_step = client_priority_step;
  pred_planner = boost::shared_ptr<osthread_c>( new osthread_c(&select, &read_notifications) );
  pred_planner->name = "pred_planner";
  pred_planner->_max_priority = CLIENT_MAX_PRIORITY;
  pred_planner->_min_priority = CLIENT_MIN_PRIORITY;
  pred_planner->_priority_step = client_priority_step;

  processor->run_queue.push_back( dynamics );
  processor->run_queue.push_back( prey );
  processor->run_queue.push_back( pred );
  std::make_heap(processor->run_queue.begin(),processor->run_queue.end(),compare_thread_p_t());

  prey->run_queue.push_back( prey_controller );
  std::make_heap(prey->run_queue.begin(),prey->run_queue.end(),compare_thread_p_t());

  pred->run_queue.push_back( pred_planner );
  pred->run_queue.push_back( pred_controller );
  std::make_heap(pred->run_queue.begin(),pred->run_queue.end(),compare_thread_p_t());
*/
  // * initialize block detection, i.e. wakeup * 
  wakeup_priority = coordinator_priority - 2;

  if( scheduler_c::create( wakeup_thread, wakeup_priority, wakeup ) != scheduler_c::ERROR_NONE ) {
     msgbuffer.close( );
     close_pipes( );
     //error_log.close( );
     printf( "(coordinator.cpp) init() failed calling wakeup_thread.create(...,wakeup)\nExiting\n" );
     exit( 1 );
  }

  // * initialize timer *
  if( timer.create( timer_sighandler, RTTIMER_SIGNAL ) != timer_c::ERROR_NONE ) {
    sprintf( errstr, "(coordinator.cpp) init() failed calling timer.create(timer_sighandler,RTTIMER_SIGNAL)\nExiting\n" );
    //error_log.write( errstr );
    printf( "%s", errstr );

    msgbuffer.close( );
    close_pipes( );
    //error_log.close( );
    exit( 1 );
  }


  // * initialize other resources *

  // lock into memory to prevent pagefaults.  do last before main loop
  mlockall( MCL_CURRENT );
} 
Esempio n. 6
0
/* Note: adjust rlimit if needed for more allowed open fd */
int main(int argc, char **argv)
{
	int i;
	int rc;
	void *thread_retval;
	int retry;

	if (argc > 1) {
		target_addr = strtoul(argv[1], NULL, 0);
	}
	fprintf(stderr, "target_addr = %p\n", (void *)target_addr);

	setfdlimit();
	init_sock();
	init_mmap();

redo:
	retry = 0;
	init_pipes();

	for (i = 0; i < NR_SOCKS; i++) {
		rc = pthread_create(&sendmmsg_threads[i], NULL,
			sendmmsg_thread_func, NULL);

		if (rc) {
			perror("sendmmsg_threads failed");

			exit(2);
		}
	}

	sleep(3);
	kill_switch = 1;
	for (i = 0; i < NR_SOCKS; i++) {
		pthread_join(sendmmsg_threads[i], &thread_retval);
	}
	kill_switch = 0;
	sleep(1);

	rc = pthread_create(&mmap_thread, NULL, mmap_thread_func, NULL);
	if (rc) {
		perror("mmap_thread failed");
	}

	for (i = 0; i < NR_PIPES; i++) {
		rc = pthread_create(&pipe_write_threads[i], NULL,
		                    pipe_write_func, (void *)pipes[i].fd[1]);
		if (rc) {
			perror("pipe_write_thread failed");
			exit(2);
		}

		rc = pthread_create(&pipe_read_threads[i], NULL,
		                    pipe_read_func, (void *)pipes[i].fd[0]);
		if (rc) {
			perror("pipe_read_thread failed");
			exit(2);
		}
	}

	for (i = 0; i < NR_PIPES; i++) {
		fprintf(stderr, "join read thread %d...\n", i);
		pthread_join(pipe_read_threads[i], &thread_retval);
		if (thread_retval == (void *)-1) {
			retry = 1;
		}
		fprintf(stderr, "done\n");
	}

	kill_switch = 1;
	fprintf(stderr, "kill others\n");
	fprintf(stderr, "join mmap thread...\n");
	pthread_join(mmap_thread, &thread_retval);
	fprintf(stderr, "done\n");

	for (i = 0; i < NR_PIPES; i++) {
		for(;;) {
			if (close(pipes[i].fd[0])) {
				perror("close write pipe failed");
				continue;
			}

			if (close(pipes[i].fd[1])) {
				perror("close read pipe failed");
				continue;
			}
			break;
		}
	}
	fprintf(stderr, "pipe closed\n");

	if (retry) {
		goto redo;
	}

	exit(0);

	return 0;
}
Esempio n. 7
0
int main( int argc, char *argv[] )
{
	GtkWidget *mainbox, *hbox, *hbox2, *label,*pixmap_w;
/*	GdkPixmap *pixmap;
	GdkBitmap *mask;
	GtkStyle *style;*/

	init_pipes(); /* set all pipe data to 0 */

	command_line_options(argc, argv);

	/* g_thread_init(NULL); no ide why I had to remove it */
	gtk_init(&argc, &argv);
	gdk_rgb_init ();

/*	capturing_init = FALSE;
	playing = FALSE;*/

	signal(SIGSEGV, signal_handler);
	signal(SIGTERM, signal_handler);
	signal(SIGINT, signal_handler);
	signal(SIGPIPE, signal_handler);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

	gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (delete_event), NULL);
	gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (destroy), NULL);

	gtk_window_set_title (GTK_WINDOW (window), "Linux Video Studio");
	gtk_container_set_border_width (GTK_CONTAINER (window), 0);

	mainbox = gtk_vbox_new(FALSE,0);
	gtk_container_add (GTK_CONTAINER (window), mainbox);
	gtk_widget_show (mainbox);

	make_menus(mainbox);

	notebook = gtk_notebook_new ();

/*	style = gtk_widget_get_style(window);*/
	gtk_widget_realize(window);
	hbox = create_lavrec_layout(window);
	if (hbox != NULL)
	{
		hbox2 = gtk_hbox_new(FALSE, 10);
/*		pixmap = gdk_pixmap_create_from_xpm_d(window->window, &mask,
			&style->bg[GTK_STATE_NORMAL], cam_xpm);
		pixmap_w = gtk_pixmap_new(pixmap, mask);*/
		pixmap_w = gtk_widget_from_xpm_data(cam_xpm);
		gtk_widget_show(pixmap_w);
		gtk_box_pack_start(GTK_BOX(hbox2), pixmap_w, FALSE, FALSE, 0);
		label = gtk_label_new("Capture Video");
		gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
		gtk_widget_show(label);
		gtk_notebook_append_page (GTK_NOTEBOOK (notebook), hbox, hbox2);
		gtk_widget_show(hbox);
		gtk_widget_show(hbox2);
	}

	hbox = create_lavedit_layout(window);
	hbox2 = gtk_hbox_new(FALSE, 10);
/*	pixmap = gdk_pixmap_create_from_xpm_d(window->window, &mask, &style->bg[GTK_STATE_NORMAL], editing_xpm);
	pixmap_w = gtk_pixmap_new(pixmap, mask);*/
	pixmap_w = gtk_widget_from_xpm_data(editing_xpm);
	gtk_widget_show(pixmap_w);
	gtk_box_pack_start(GTK_BOX(hbox2), pixmap_w, FALSE, FALSE, 0);
	label = gtk_label_new("Edit Video");
	gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
	gtk_widget_show(label);
	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), hbox, hbox2);
	gtk_widget_show(hbox);
	gtk_widget_show(hbox2);

	hbox = create_lavplay_layout();
	if (hbox != NULL)
	{
		hbox2 = gtk_hbox_new(FALSE, 10);
/*		pixmap = gdk_pixmap_create_from_xpm_d(window->window, &mask,
			&style->bg[GTK_STATE_NORMAL], tv_xpm);
		pixmap_w = gtk_pixmap_new(pixmap, mask);*/
		pixmap_w = gtk_widget_from_xpm_data(tv_xpm);
		gtk_widget_show(pixmap_w);
		gtk_box_pack_start(GTK_BOX(hbox2), pixmap_w, FALSE, FALSE, 0);
		label = gtk_label_new("Playback Video");
		gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
		gtk_widget_show(label);
		gtk_notebook_append_page (GTK_NOTEBOOK (notebook), hbox, hbox2);
		gtk_widget_show(hbox);
		gtk_widget_show(hbox2);
	}

        /* New notebook entry for encoding */
	hbox = create_lavencode_layout(); 
	hbox2 = gtk_hbox_new(FALSE, 10);
/*	pixmap = gdk_pixmap_create_from_xpm_d(window->window, &mask,
		&style->bg[GTK_STATE_NORMAL], arrows_xpm);
	pixmap_w = gtk_pixmap_new(pixmap, mask);*/
	pixmap_w = gtk_widget_from_xpm_data(arrows_xpm);
	gtk_widget_show(pixmap_w);
	gtk_box_pack_start(GTK_BOX(hbox2), pixmap_w, FALSE, FALSE, 0);
	label = gtk_label_new("Encode Video");
	gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
	gtk_widget_show(label);
	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), hbox, hbox2);
	gtk_widget_show(hbox);
	gtk_widget_show(hbox2);

	hbox = gtk_hbox_new(FALSE,5);
	gtk_box_pack_start(GTK_BOX(hbox), notebook, FALSE, FALSE, 5);
	gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
	gtk_widget_show(notebook);
	gtk_box_pack_start(GTK_BOX(mainbox), hbox, FALSE, FALSE, 5);
	gtk_widget_show(hbox);

	gtk_signal_connect(GTK_OBJECT(notebook), "switch_page", GTK_SIGNAL_FUNC(notebook_page_switched),NULL);

	gtk_widget_show(window);
	if (verbose) g_print("Linux Video Studio initialized correctly\n");

	gdk_threads_enter();
	gtk_main();
	gdk_threads_leave();
	
	return 0;
}
Esempio n. 8
0
//-----------------------------------------------------------------------------
void init( int argc, char* argv[] ) {
  //quit = false;
  quit = 0;
  //quit.store( 0, std::memory_order_seq_cst  );
  //quit.store( 0, std::memory_order_relaxed  );

  actual_timer_events = 0;
  caught_timer_events = 0;

  // * set variables from constants *
  cpu = DEFAULT_CPU;

  // * install SIGTERM signal handler *
  struct sigaction action;
  memset( &action, 0, sizeof(struct sigaction) );
  action.sa_handler = term_sighandler;
  sigaction( SIGTERM, &action, NULL );

  // * open log *
#ifdef DO_LOGGING
  info = log_p( new log_c( "info.log", true ) );
  log_c::error_e log_err = info->allocate( LOG_CAPACITY );
  if( log_err != log_c::ERROR_NONE ) {
    sprintf( spstr, "(coordinator.cpp) init() failed calling log_c::allocate(...).\nExiting\n" ); 
    printf( spstr );
    exit( 1 );
  }
#endif

  // * get the process identifier *
  coordinator_pid = getpid( );

  sprintf( spstr, "coordinator pid: %d\n", coordinator_pid );
  if( info ) info->write( spstr );
  printf( "%s", spstr );

  // * bind the process to a single cpu *
  if( cpu_c::bind( coordinator_pid, cpu ) != cpu_c::ERROR_NONE ) {
    sprintf( spstr, "(coordinator.cpp) init() failed calling cpu_c::_bind(coordinator_pid,DEFAULT_CPU).\nExiting\n" );
    if( info ) info->write( spstr );
    printf( "%s", spstr );
    exit( 1 );
  }

  // * set the process to be scheduled with realtime policy and max priority *
  if( scheduler_c::set_realtime_policy( coordinator_pid, coordinator_os_priority ) != scheduler_c::ERROR_NONE ) {
    sprintf( spstr, "(coordinator.cpp) init() failed calling schedule_set_realtime_max(coordinator_pid,coordinator_priority).\nExiting\n" );
    if( info ) info->write( spstr );
    printf( "%s", spstr );
    exit( 1 );
  }
  sprintf( spstr, "coordinator os priority: %d\n", coordinator_os_priority );
  if( info ) info->write( spstr );
  printf( "%s", spstr );

  // * determine if the OS supports high resolution timers *
  struct timespec res;
  clock_getres( CLOCK_MONOTONIC, &res );
  double clock_res = timespec_to_real( res );

  sprintf( spstr, "clock resolution (secs): %10.9f\n", clock_res );
  if( info ) info->write( spstr );
  printf( "%s", spstr );
 
  if( res.tv_sec != 0 && res.tv_nsec != 1 ) {
    sprintf( spstr, "(coordinator.cpp) init() failed.  The host operating system does not support high resolution timers.  Consult your system documentation on enabling this feature.\nExiting\n" );
    if( info ) info->write( spstr );
    printf( "%s", spstr );
    exit( 1 );
  }

  // * get the cpu speed *
  if( cpu_c::get_speed( cpu_speed, cpu ) != cpu_c::ERROR_NONE ) {
    sprintf( spstr, "(coordinator.cpp) init() failed calling cpu_c::get_frequency(cpu_speed,cpu)\nExiting\n" );
    if( info ) info->write( spstr );
    printf( "%s", spstr );
    exit( 1 );
  }
  sprintf( spstr, "cpu speed(hz): %llu\n", cpu_speed );
  if( info ) info->write( spstr );
  printf( "%s", spstr );

  // * initialize pipes *
  if( !init_pipes() ) {
    sprintf( spstr, "(coordinator.cpp) init() failed calling init_pipes()\nExiting\n" );
    if( info ) info->write( spstr );
    printf( "%s", spstr );
    exit( 1 );
  }

  // * initialize shared memory *
  msgbuffer = client_message_buffer_c( CLIENT_MESSAGE_BUFFER_NAME, CLIENT_MESSAGE_BUFFER_MUTEX_NAME, true );
  if( msgbuffer.open( ) != client_message_buffer_c::ERROR_NONE ) {
    sprintf( spstr, "(coordinator.cpp) init() failed calling actuator_msg_buffer_c.open(...,true)\nExiting\n" );
    if( info ) info->write( spstr );
    printf( "%s", spstr );
    close_pipes( );
    exit( 1 );
  }

  // * initialize block detection, i.e. wakeup * 
  wakeup_os_priority = coordinator_os_priority - 2;
  wakeup_enabled.store( 1 );
  // set up the wakeup overhead to minimize what changes inside
  wakeup_note.source = notification_t::WAKEUP;
  wakeup_write_fd = FD_WAKEUP_TO_COORDINATOR_WRITE_CHANNEL;

  if( info ) info->flush();

  // lock into memory to prevent pagefaults.  do last before main loop
  mlockall( MCL_CURRENT );

/*
  if( scheduler_c::create( wakeup_thread, wakeup_os_priority, wakeup ) != scheduler_c::ERROR_NONE ) {
    sprintf( spstr, "(coordinator.cpp) init() failed calling wakeup_thread.create(...,wakeup)\nExiting\n" );
    if( info ) info->write( spstr );
    printf( "%s", spstr );
    msgbuffer.close( );
    close_pipes( );
    exit( 1 );
  }
*/
/*
  if( scheduler_c::get_priority( wakeup_thread, wakeup_os_priority ) != scheduler_c::ERROR_NONE ) {
    sprintf( spstr, "(coordinator.cpp) init() failed calling get_priority(wakeup_thread,...)\nExiting\n" );
    info.write( spstr );
    msgbuffer.close( );
    close_pipes( );
    // kill the wakeup thread?
    exit(1);
  }
*/
  sprintf( spstr, "wakeup thread created... priority:%d\n", wakeup_os_priority );
  if( info ) info->write( spstr );
  printf( "%s", spstr );

  // * initialize clients *
  sprintf( spstr, "initializing clients\n" );
  if( info ) info->write( spstr );
  printf( "%s", spstr );

  scheduler_c::error_e schedulererr;

  double controller_floor_seconds = 0.001;
  double controller_ceiling_seconds = 0.01;
  double planner_floor_seconds = 0.01;
  double planner_ceiling_seconds = 0.5;
  std::string controller_seed = "1";

  char numbuf[16];

  sprintf(numbuf,"%llu",seconds_to_cycles(controller_floor_seconds, cpu_speed));
  std::string controller_floor = numbuf;
  sprintf(numbuf,"%llu",seconds_to_cycles(controller_ceiling_seconds, cpu_speed));
  std::string controller_ceiling = numbuf;
  sprintf(numbuf,"%llu",seconds_to_cycles(planner_floor_seconds, cpu_speed));
  std::string planner_floor = numbuf;
  sprintf(numbuf,"%llu",seconds_to_cycles(planner_ceiling_seconds, cpu_speed));
  std::string planner_ceiling = numbuf;

  CLIENT_OS_MAX_PRIORITY = coordinator_os_priority - 1;
  CLIENT_OS_MIN_PRIORITY = coordinator_os_priority - 3;
  int client_os_priority_step = CLIENT_OS_MAX_PRIORITY - CLIENT_OS_MIN_PRIORITY;

  log_c* pinfo = NULL;
  if( info ) pinfo = info.get();
/*
  // - create a processor -
  processor = boost::shared_ptr<processor_c>( new processor_c( "processor_0" ) );
  timesink_p processor_timesink = boost::dynamic_pointer_cast<timesink_c>( processor );
  processor_thread = boost::dynamic_pointer_cast<thread_c>( processor );
  processor->info = pinfo;

  // - create dynamics process -
  dynamics = boost::shared_ptr<dynamics_c>( new dynamics_c( "dynamics", processor_timesink, cpu_speed ) );
  dynamics->info = pinfo;
  processor->run_queue.push( dynamics );

  // - create prey processes -
  prey = boost::shared_ptr<timesink_c>( new timesink_c( "prey", processor_timesink, scheduler_c::PROGRESS) );
  prey->info = pinfo;
  //prey->priority = 0;
  processor->run_queue.push( prey );
  prey_thread = boost::dynamic_pointer_cast<thread_c>(prey);
*/
  prey_controller = boost::shared_ptr<osthread_c>( new osthread_c( "prey_controller", prey, &select, &read_notifications, &process_notifications, pinfo ) );
  prey_controller->_max_os_priority = CLIENT_OS_MAX_PRIORITY;
  prey_controller->_min_os_priority = CLIENT_OS_MIN_PRIORITY;
  prey_controller->_os_priority_step = client_os_priority_step;
  prey_controller->_cpu_speed = cpu_speed;
  prey_controller->priority = 0;
  prey_controller->desired_period = seconds_to_cycles( controller_ceiling_seconds, cpu_speed );
  //prey->run_queue.push( prey_controller );

  schedulererr = scheduler_c::create( prey_controller, 3, DEFAULT_CPU, "client-process", "prey-controller", controller_seed.c_str(), controller_floor.c_str(), controller_ceiling.c_str() );
  //prey_controller->block();

  sprintf( spstr, "created prey-controller: pid[%d], _os_priority[%d], _os_priority_step[%d], _max_os_priority[%d], _min_os_priority[%d]\n", prey_controller->pid, prey_controller->_os_priority, prey_controller->_os_priority_step, prey_controller->_max_os_priority, prey_controller->_min_os_priority );
  if( info ) info->write( spstr );
/*
  // - create predator processes -
  pred = boost::shared_ptr<timesink_c>( new timesink_c( "pred", processor_timesink, scheduler_c::PROGRESS) );
  pred->info = pinfo;
  //prey->priority = 0;
  processor->run_queue.push( pred );
  pred_thread = boost::dynamic_pointer_cast<thread_c>(pred);

  pred_controller = boost::shared_ptr<osthread_c>( new osthread_c( "pred_controller", pred, &select, &read_notifications, &process_notifications, pinfo ) );
  pred_controller->_max_os_priority = CLIENT_OS_MAX_PRIORITY;
  pred_controller->_min_os_priority = CLIENT_OS_MIN_PRIORITY;
  pred_controller->_os_priority_step = client_os_priority_step;
  pred_controller->_cpu_speed = cpu_speed;
  pred_controller->priority = 0;
  pred_controller->desired_period = seconds_to_cycles( controller_ceiling_seconds, cpu_speed );
  pred->run_queue.push( pred_controller );

  schedulererr = scheduler_c::create( pred_controller, 3, DEFAULT_CPU, "client-process", "pred-controller", controller_seed.c_str(), controller_floor.c_str(), controller_ceiling.c_str() );
  //prey_controller->block();

  sprintf( spstr, "created pred-controller: pid[%d], _os_priority[%d], _os_priority_step[%d], _max_os_priority[%d], _min_os_priority[%d]\n", pred_controller->pid, pred_controller->_os_priority, pred_controller->_os_priority_step, pred_controller->_max_os_priority, pred_controller->_min_os_priority );
  if( info ) info->write( spstr );
*/
  // * initialize timer *
  // set up the timer handler overhead to minimize what changes inside
  timer_note.source = notification_t::TIMER;
  timer_write_fd = FD_TIMER_TO_COORDINATOR_WRITE_CHANNEL;

  // create the timer
  if( timer.create( timer_sighandler, RTTIMER_SIGNAL ) != timer_c::ERROR_NONE ) {
    sprintf( spstr, "(coordinator.cpp) init() failed calling timer.create(timer_sighandler,RTTIMER_SIGNAL)\nExiting\n" );
    pthread_cancel( wakeup_thread );
    int status;
    if( pred_controller ) {
      kill( pred_controller->pid, SIGTERM );
      waitpid( pred_controller->pid, &status, 0 );
    }

    if( prey_controller ) {
      kill( prey_controller->pid, SIGTERM );
      waitpid( prey_controller->pid, &status, 0 );
    }

    if( info ) info->write( spstr );
    printf( "%s", spstr );
    msgbuffer.close( );
    close_pipes( );
    exit( 1 );
  }

  // * initialize other resources *

  //clients.push_back( prey_controller );
  //clients.push_back( pred_controller );
  //clients.push_back( pred_planner );
} 
Esempio n. 9
0
void cmus_track_request_init(void)
{
	init_pipes(&cmus_next_track_request_fd, &cmus_next_track_request_fd_priv);
}
Esempio n. 10
0
bool wine_start(char *wine_app, char *avsloader, AVS_PIPES *avs_pipes, int pipe_timeout)
{
  char sname[MAX_PATH];
  struct stat st;
  sprintf(sname, "%s %s %d", wine_app, avsloader, pipe_timeout);

  FILE *pfile = popen(sname, "r");
  if (!pfile)
  {
   DEBUG_PRINTF_RED("avsfilter : popen failed, errno %d, failed start app is : [%s]\n", errno, sname);
   return false;
  }

  if (fscanf(pfile, "%s\n", sname) != 1 ||
      stat(sname, &st) ||
      !S_ISDIR(st.st_mode))
  {
    DEBUG_PRINTF_RED("avsfilter : tmpdirname [%s] failed, errno %d[stat %d isdir %d]\n", sname, errno, stat(sname, &st), S_ISDIR(st.st_mode));
    pclose(pfile);
    return false;
  }

  DEBUG_PRINTF("avsfilter : good tmpdirname %s\n", sname);

  if (!init_pipes(avs_pipes, CMD_PIPE_NUM, pfile))
  {
    DEBUG_PRINTF_RED("init_pipes failed\n");
    pclose(pfile);
    return false;
  }

  time_t t = time(NULL);
  DEBUG_PRINTF("avsfilter : precreate thread time %s\n",
         ctime(&t));
  pthread_t thread;
  TPARSER tp = { avs_pipes, pfile };

  open_pipes_ok = false;

  if (pthread_create(&thread, NULL, parse_wine_stdout, &tp))
  {
    DEBUG_PRINTF_RED("Cannot pthread started...Errno %d\n",errno);
    deinit_pipes(avs_pipes, CMD_PIPE_NUM);
    return false;
  }

  t = time(NULL);
  DEBUG_PRINTF("avsfilter : preopen time %s\n",
         ctime(&t));

  if (!open_pipes(avs_pipes, CMD_PIPE_NUM) || wine_loader_down)
  {
    open_pipes_ok = true;
    DEBUG_PRINTF_RED("open_pipes failed\n");
    deinit_pipes(avs_pipes, CMD_PIPE_NUM);
    return false;
  }

  open_pipes_ok = true;

  if (pipe_test_filter (avs_pipes[PIPE_LOADER_READ].hpipe,
                        avs_pipes[PIPE_FILTER_WRITE].hpipe))
  {
    DEBUG_PRINTF("avsfilter : test pipe to filter ok\n");

    if (pipe_test_filter (avs_pipes[PIPE_LOADER_READ].hpipe,
                          avs_pipes[PIPE_LOADER_WRITE].hpipe))
    {
      DEBUG_PRINTF("avsfilter : test pipe to loader ok\n");
    }
    else
      goto error_pipe_test;
  }
  else
  {
    error_pipe_test:
    DEBUG_PRINTF_RED("Error test read/write pipes\n");
    deinit_pipes(avs_pipes, CMD_PIPE_NUM);
    return false;
  }

  DEBUG_PRINTF("wine start is ok\n");
  return true;
}
Esempio n. 11
0
static PLI_INT32 to_myhdl_calltf(PLI_BYTE8 *user_data)
{
  vpiHandle net_iter, net_handle, cb_h;
  char buf[MAXLINE];
  char s[MAXWIDTH];
  int n;
  int i;
  int *id;
  s_cb_data cb_data_s;
  s_vpi_time verilog_time_s;
  s_vpi_time time_s;
  s_vpi_value value_s;
  static int to_myhdl_flag = 0;

  if (to_myhdl_flag) {
    vpi_printf("ERROR: $to_myhdl called more than once\n");
    vpi_control(vpiFinish, 1);  /* abort simulation */
    return(0);
  }
  to_myhdl_flag = 1;

  init_pipes();

  verilog_time_s.type = vpiSimTime;
  vpi_get_time(NULL, &verilog_time_s);
  verilog_time = timestruct_to_time(&verilog_time_s);
  if (verilog_time != 0) {
    vpi_printf("ERROR: $to_myhdl should be called at time 0\n");
    vpi_control(vpiFinish, 1);  /* abort simulation */
    return(0);
  }
  sprintf(buf, "TO 0 ");
  pli_time = 0;
  delta = 0;

  time_s.type = vpiSuppressTime;
  value_s.format = vpiSuppressVal;
  cb_data_s.reason = cbValueChange;
  cb_data_s.cb_rtn = change_callback;
  cb_data_s.time = &time_s;
  cb_data_s.value = &value_s;
  // value_s.format = vpiHexStrVal;
  i = 0;
  to_myhdl_systf_handle = vpi_handle(vpiSysTfCall, NULL);
  net_iter = vpi_iterate(vpiArgument, to_myhdl_systf_handle);
  while ((net_handle = vpi_scan(net_iter)) != NULL) {
    if (i == MAXARGS) {
      vpi_printf("ERROR: $to_myhdl max #args (%d) exceeded\n", MAXARGS);
      vpi_control(vpiFinish, 1);  /* abort simulation */
    }
    strcat(buf, vpi_get_str(vpiName, net_handle));
    strcat(buf, " ");
    sprintf(s, "%d ", vpi_get(vpiSize, net_handle));
    strcat(buf, s);
    changeFlag[i] = 0;
    id = malloc(sizeof(int));
    *id = i;
    cb_data_s.user_data = (PLI_BYTE8 *)id;
    cb_data_s.obj = net_handle;
    cb_h = vpi_register_cb(&cb_data_s);
    vpi_free_object(cb_h);
    i++;
    vpi_free_object(net_handle);
  }
  //vpi_free_object(net_iter);

  n = write(wpipe, buf, strlen(buf));

  if ((n = read(rpipe, buf, MAXLINE)) == 0) {
    vpi_printf("ABORT from $to_myhdl\n");
    vpi_control(vpiFinish, 1);  /* abort simulation */
    return(0);
  }
  buf[n] = '\0';
  assert(n > 0);

  // register read-only callback //
  time_s.type = vpiSimTime;
  time_s.high = 0;
  time_s.low = 0;
  cb_data_s.reason = cbReadOnlySynch;
  cb_data_s.user_data = NULL;
  cb_data_s.cb_rtn = readonly_callback;
  cb_data_s.obj = NULL;
  cb_data_s.time = &time_s;
  cb_data_s.value = NULL;
  cb_h = vpi_register_cb(&cb_data_s);
  vpi_free_object(cb_h);

  // pre-register delta cycle callback //
  delta = 0;
  time_s.type = vpiSimTime;
  time_s.high = 0;
  time_s.low = 1;
  cb_data_s.reason = cbAfterDelay;
  cb_data_s.user_data = NULL;
  cb_data_s.cb_rtn = delta_callback;
  cb_data_s.obj = NULL;
  cb_data_s.time = &time_s;
  cb_data_s.value = NULL;
  cb_h = vpi_register_cb(&cb_data_s);
  vpi_free_object(cb_h);

  return(0);
}