/* This function is called (via check_events()) from the top level sieve loops (prime_sieve() etc.). It can assume that it is safe to tighten any sieving parameters other than p_min and p_max. */ void process_events(uint64_t current_prime) { /* event_happened was set last in notify_event(), so clear it first which ensures that if some signal arrives while we are in process_events() it might have to wait until the next sieve iteration to get processed, but it won't be lost. */ event_happened = 0; if (clear_event(initialise_events)) { init_signals(); init_progress_report(current_prime); } if (clear_event(subsequence_eliminated)) remove_eliminated_subsequences(current_prime); if (clear_event(sieve_parameters_changed)) init_progress_report(current_prime); if (clear_event(received_sigterm)) { finish_srsieve("SIGTERM was received",current_prime); signal(SIGTERM,SIG_DFL); raise(SIGTERM); } if (clear_event(received_sigint)) { finish_srsieve("SIGINT was received",current_prime); signal(SIGINT,SIG_DFL); raise(SIGINT); } if (clear_event(report_due)) progress_report(current_prime); if (clear_event(save_due)) write_save_file(current_prime); }
static void progress_report(uint64_t p) { uint32_t current_time = millisec_clock(); uint32_t ms_per_factor; if (current_time == last_report_time) return; if (factor_times[oldest_rec] == 0) /* first cycle of factor_times */ { if (oldest_rec == 0) /* No factors reported since sieve started */ ms_per_factor = 0; else ms_per_factor = current_time / oldest_rec; } else ms_per_factor = (current_time-factor_times[oldest_rec]) / FACTOR_TIMES; print_status(p, (p - prev_prime) * 1000 / (current_time - last_report_time), ms_per_factor); if (factor_stop_rate && factor_count >= FACTORS_FOUND_BEFORE_STOPPING) { if (ms_per_factor > factor_stop_rate) { if (++stop_rate_exceeded >= TIMES_STOP_RATE_EXCEEDED_BEFORE_STOPPING) { finish_srsieve("--stop-rate was exceeded", p); exit(0); } } else stop_rate_exceeded = 0; } prev_prime = p; last_report_time = current_time; }
/* This function is called (via check_events()) from the top level sieve loops (prime_sieve() etc.). It can assume that it is safe to tighten any sieving parameters other than p_min and p_max. */ void process_events(uint64_t current_prime) { /* event_happened was set last in notify_event(), so clear it first which ensures that if some signal arrives while we are in process_events() it might have to wait until the next sieve iteration to get processed, but it won't be lost. */ event_happened = 0; if (clear_event(initialise_events)) { init_signals(); init_progress_report(current_prime); } if (clear_event(sieve_parameters_changed)) init_progress_report(current_prime); if (clear_event(received_sigterm)) { finish_srsieve("SIGTERM was received",current_prime); signal(SIGTERM,SIG_DFL); raise(SIGTERM); } if (clear_event(received_sigint)) { finish_srsieve("SIGINT was received",current_prime); signal(SIGINT,SIG_DFL); raise(SIGINT); } #ifdef SIGHUP if (clear_event(received_sighup)) { finish_srsieve("SIGHUP was received",current_prime); signal(SIGHUP,SIG_DFL); raise(SIGHUP); } #endif #if HAVE_FORK if (clear_event(received_sigpipe)) { finish_srsieve("SIGPIPE was received",current_prime); signal(SIGPIPE,SIG_DFL); raise(SIGPIPE); } if (clear_event(received_sigchld)) { finish_srsieve("SIGCHLD was received",current_prime); signal(SIGCHLD,SIG_DFL); raise(SIGCHLD); exit(EXIT_FAILURE); } #endif if (clear_event(factor_found)) next_report_due = time(NULL); if (clear_event(report_due)) progress_report(current_prime); if (clear_event(save_due)) { #if SOBISTRATOR_OPT if (sobistrator_opt) sob_write_checkpoint(current_prime); #endif write_checkpoint(current_prime); } }