static void on_timeout() { #pragma omp critical (g_display_stats) { display_statistics(); exit(0); } }
unsigned read_smtlib_file(char const * benchmark_file) { g_start_time = clock(); register_on_timeout_proc(on_timeout); signal(SIGINT, on_ctrl_c); smtlib::solver solver; g_solver = &solver; bool ok = true; ok = solver.solve_smt(benchmark_file); if (!ok) { if (benchmark_file) { std::cerr << "ERROR: solving '" << benchmark_file << "'.\n"; } else { std::cerr << "ERROR: solving input stream.\n"; } } #pragma omp critical (g_display_stats) { display_statistics(); register_on_timeout_proc(0); g_solver = 0; } return solver.get_error_code(); }
/** * Main body of the program. * * @param argc Number of arguments from the command line. * @param argv Array of strings containing the command line arguments. * @return The exit status of the program (EXIT_SUCCESS or EXIT_FAILURE). */ int main(int argc, char **argv) { sim_setoptions(argc, argv); sim_init(); sim_readdata(); display_statistics(); sim_free(); return EXIT_SUCCESS; }
static void on_ctrl_c(int) { signal (SIGINT, SIG_DFL); #pragma omp critical (g_display_stats) { display_statistics(); } raise(SIGINT); }
static void STD_CALL on_ctrl_c(int) { if (g_opt && g_first_interrupt) { g_opt->get_manager().limit().cancel(); g_first_interrupt = false; } else { signal (SIGINT, SIG_DFL); #pragma omp critical (g_display_stats) { display_statistics(); } raise(SIGINT); } }
unsigned read_smtlib2_commands(char const * file_name) { g_start_time = clock(); register_on_timeout_proc(on_timeout); signal(SIGINT, on_ctrl_c); cmd_context ctx; ctx.set_solver_factory(mk_smt_strategic_solver_factory()); ctx.set_interpolating_solver_factory(mk_smt_solver_factory()); install_dl_cmds(ctx); install_dbg_cmds(ctx); install_polynomial_cmds(ctx); install_subpaving_cmds(ctx); install_opt_cmds(ctx); g_cmd_context = &ctx; signal(SIGINT, on_ctrl_c); bool result = true; if (file_name) { std::ifstream in(file_name); if (in.bad() || in.fail()) { std::cerr << "(error \"failed to open file '" << file_name << "'\")" << std::endl; exit(ERR_OPEN_FILE); } result = parse_smt2_commands(ctx, in); } else { result = parse_smt2_commands(ctx, std::cin, true); } #pragma omp critical (g_display_stats) { display_statistics(); g_cmd_context = 0; } return result ? 0 : 1; }
int main(void) { unsigned process_id=0; unsigned scheduler=0; unsigned total_time=0; unsigned time_quantum=0; unsigned fixed_response_time=0; char option; char *str=NULL; struct process_node *p=NULL,*q=NULL,*r=NULL,*start=NULL; system("clear"); printf("STARTING SIMULATION: "); do { q=create_process(process_id++); if(p!=NULL) add_process(p,q); else p=q; printf("\nOne more process: (y/n) "); fflush(stdin); scanf("%s",&option); }while(option!='n'); display_process(p); printf("\nPress y to continue\n"); fflush(stdin); scanf("%s",&option); do { scheduler=0; scheduler=display_options(); str=NULL; switch(scheduler) { case 1:/* if(total_time=fcfs_process_arrives_in_system(p)) { str="FCFS (Process Creation)"; }*/ break; case 2:/* if(total_time=fcfs_process_arrives_in_ready_queue(p)) { str="FCFS (Arrival in Ready Queue)"; }*/ break; case 3: if(total_time=priority_scheduler(p)) { str="Priority Scheduler"; } break; case 4:/* if(total_time=sjf_scheduler(p)) { str="Shortest Job First Scheduler"; }*/ break; case 5:/* if(total_time=srtf_scheduler(p)) { str="Shortest Remaining Time First Scheduler"; }*/ break; case 6:/* printf("\nEnter time quantum: "); fflush(stdin); scanf("%u",&time_quantum); if(total_time=round_robin_scheduler(p,time_quantum)) { str="Round Robin Scheduler"; }*/ break; case 7:/* printf("\nEnter fixed response duration: "); fflush(stdin); scanf("%u",&fixed_response_time); if(total_time=round_robin_scheduler_2(p,fixed_response_time)) { str="Round Robin Scheduler 2"; }*/ break; case 8://display process details display_process(p); break; case 9://add another process q=create_process(process_id++); if(!isEmpty(p)) add_process(p,q); else p=q; break; case 10: for(start=p;start!=NULL;) { r=start; start=start->next; free(r); r=NULL; } exit(0); break; default: printf("\nError: Pls try again\n"); } if(scheduler>=1 && scheduler<=7)//!=8 && scheduler!=0) { if(total_time) { display_statistics(p,str,total_time); clear_statistics(p); } else { printf("\nScheduler failed\n"); } } }while(1); return 0; }
static void STD_CALL on_ctrl_c(int) { signal (SIGINT, SIG_DFL); display_statistics(); raise(SIGINT); }
static void on_timeout() { display_statistics(); exit(0); }
void displayStatsTimerCallback(TimerHandle_t timer){ // Display statistics every 1 second display_statistics(); }
void play (char *source_string) { transport_t *transport; format_t *format; data_source_t *source; decoder_t *decoder; decoder_callbacks_t decoder_callbacks; void *decoder_callbacks_arg; /* Preserve between calls so we only open the audio device when we have to */ static audio_format_t old_audio_fmt = { 0, 0, 0, 0, 0 }; audio_format_t new_audio_fmt; audio_reopen_arg_t *reopen_arg; /* Flags and counters galore */ int eof = 0, eos = 0, ret; int nthc = 0, ntimesc = 0; int next_status = 0; static int status_interval = 0; /* Reset all of the signal flags */ sig_request.cancel = 0; sig_request.skipfile = 0; sig_request.exit = 0; sig_request.pause = 0; /* Set preferred audio format (used by decoder) */ new_audio_fmt.big_endian = ao_is_big_endian(); new_audio_fmt.signed_sample = 1; new_audio_fmt.word_size = 2; /* Select appropriate callbacks */ if (audio_buffer != NULL) { decoder_callbacks.printf_error = &decoder_buffered_error_callback; decoder_callbacks.printf_metadata = &decoder_buffered_metadata_callback; decoder_callbacks_arg = audio_buffer; } else { decoder_callbacks.printf_error = &decoder_error_callback; decoder_callbacks.printf_metadata = &decoder_metadata_callback; decoder_callbacks_arg = NULL; } /* Locate and use transport for this data source */ if ( (transport = select_transport(source_string)) == NULL ) { status_error(_("No module could be found to read from %s.\n"), source_string); return; } if ( (source = transport->open(source_string, &options)) == NULL ) { status_error(_("Cannot open %s.\n"), source_string); return; } /* Detect the file format and initialize a decoder */ if ( (format = select_format(source)) == NULL ) { status_error(_("The file format of %s is not supported.\n"), source_string); return; } if ( (decoder = format->init(source, &options, &new_audio_fmt, &decoder_callbacks, decoder_callbacks_arg)) == NULL ) { /* We may have failed because of user command */ if (!sig_request.cancel) status_error(_("Error opening %s using the %s module." " The file may be corrupted.\n"), source_string, format->name); return; } /* Decide which statistics are valid */ select_stats(stat_format, &options, source, decoder, audio_buffer); /* Start the audio playback thread before we begin sending data */ if (audio_buffer != NULL) { /* First reset mutexes and other synchronization variables */ buffer_reset (audio_buffer); buffer_thread_start (audio_buffer); } /* Show which file we are playing */ decoder_callbacks.printf_metadata(decoder_callbacks_arg, 1, _("Playing: %s"), source_string); /* Skip over audio */ if (options.seekpos > 0.0) { if (!format->seek(decoder, options.seekpos, DECODER_SEEK_START)) { status_error(_("Could not skip %f seconds of audio."), options.seekpos); if (audio_buffer != NULL) buffer_thread_kill(audio_buffer); return; } } /* Main loop: Iterates over all of the logical bitstreams in the file */ while (!eof && !sig_request.exit) { /* Loop through data within a logical bitstream */ eos = 0; while (!eos && !sig_request.exit) { /* Check signals */ if (sig_request.skipfile) { eof = eos = 1; break; } if (sig_request.pause) { if (audio_buffer) buffer_thread_pause (audio_buffer); kill (getpid(), SIGSTOP); /* We block here until we unpause */ /* Done pausing */ if (audio_buffer) buffer_thread_unpause (audio_buffer); sig_request.pause = 0; } /* Read another block of audio data */ ret = format->read(decoder, convbuffer, convsize, &eos, &new_audio_fmt); /* Bail if we need to */ if (ret == 0) { eof = eos = 1; break; } else if (ret < 0) { status_error(_("Error: Decoding failure.\n")); break; } /* Check to see if the audio format has changed */ if (!audio_format_equal(&new_audio_fmt, &old_audio_fmt)) { old_audio_fmt = new_audio_fmt; /* Update our status printing interval */ status_interval = new_audio_fmt.word_size * new_audio_fmt.channels * new_audio_fmt.rate / options.status_freq; next_status = 0; reopen_arg = new_audio_reopen_arg(options.devices, &new_audio_fmt); if (audio_buffer) buffer_insert_action_at_end(audio_buffer, &audio_reopen_action, reopen_arg); else audio_reopen_action(NULL, reopen_arg); } /* Update statistics display if needed */ if (next_status <= 0) { display_statistics(stat_format, audio_buffer, source, decoder); next_status = status_interval; } else next_status -= ret; if (options.endpos > 0.0 && options.endpos <= current_time(decoder)) { eof = eos = 1; break; } /* Write audio data block to output, skipping or repeating chunks as needed */ do { if (nthc-- == 0) { if (audio_buffer) buffer_submit_data(audio_buffer, convbuffer, ret); else audio_play_callback(convbuffer, ret, eos, &audio_play_arg); nthc = options.nth - 1; } } while (!sig_request.exit && !sig_request.skipfile && ++ntimesc < options.ntimes); ntimesc = 0; } /* End of data loop */ } /* End of logical bitstream loop */ /* Done playing this logical bitstream. Clean up house. */ if (audio_buffer) { if (!sig_request.exit && !sig_request.skipfile) { buffer_mark_eos(audio_buffer); buffer_wait_for_empty(audio_buffer); } buffer_thread_kill(audio_buffer); } /* Print final stats */ display_statistics_quick(stat_format, audio_buffer, source, decoder); format->cleanup(decoder); transport->close(source); status_reset_output_lock(); /* In case we were killed mid-output */ status_message(1, _("Done.")); if (sig_request.exit) exit (0); }
static void display_statistics() { if (g_ctx) { display_statistics(std::cout, *g_ctx, *g_orig_rules, *g_code, *g_ectx, true); } }