void advanced_quit (void) { if (!USE_PRIMENET) { outputLongLine (MANUAL_QUIT); if (askYesNo ('N')) { writeResults ("Quitting GIMPS.\n"); //bug - either delete file, or delete all work_units and write the file. //bug IniDeleteAllLines (WORKTODO_FILE); stop_workers_for_escape (); } } else { int res; outputLongLine (PRIMENET_QUIT); res = askYesNoCancel ('C'); if (res == 0) { OutputBoth (MAIN_THREAD_NUM, "Quitting GIMPS after current work completes.\n"); IniWriteInt (INI_FILE, "NoMoreWork", 1); askOK (); } if (res == 1) { OutputBoth (MAIN_THREAD_NUM, "Quitting GIMPS immediately.\n"); spoolMessage (MSG_QUIT_GIMPS, NULL); askOK (); } } }
void test_stop (void) { unsigned long worker; worker = 0; askNum ("Worker to stop, 0=all", &worker, 0, NUM_WORKER_THREADS); if (worker == 0) stop_workers_for_escape (); else stop_one_worker (worker - 1); }
void sigterm_handler(int signo) { stop_workers_for_escape (); if (signo != SIGINT) THREAD_KILL = TRUE; (void)signal(signo, sigterm_handler); }
void main_menu (void) { unsigned long choice; mloop: if (THREAD_KILL) return; printf ("\t Main Menu\n"); loop: printf ("\n"); printf ("\t 1. Test/Primenet\n"); printf ("\t 2. Test/Worker threads\n"); printf ("\t 3. Test/Status\n"); if (WORKER_THREADS_ACTIVE && active_workers_count () < WORKER_THREADS_ACTIVE) printf ("\t 4. Test/Continue or Stop\n"); else if (!WORKER_THREADS_ACTIVE || WORKER_THREADS_STOPPING) printf ("\t 4. Test/Continue\n"); else printf ("\t 4. Test/Stop\n"); printf ("\t 5. Test/Exit\n"); printf ("\t 6. Advanced/Test\n"); printf ("\t 7. Advanced/Time\n"); printf ("\t 8. Advanced/P-1\n"); printf ("\t 9. Advanced/ECM\n"); printf ("\t10. Advanced/Manual Communication\n"); printf ("\t11. Advanced/Unreserve Exponent\n"); printf ("\t12. Advanced/Quit Gimps\n"); printf ("\t13. Options/CPU\n"); printf ("\t14. Options/Preferences\n"); printf ("\t15. Options/Torture Test\n"); printf ("\t16. Options/Benchmark\n"); printf ("\t17. Help/About\n"); printf ("\t18. Help/About PrimeNet Server\n"); printf ("Your choice: "); choice = get_number (0); if (choice <= 0 || choice >= 19) { printf ("\t Invalid choice\n"); goto loop; } /* Display the main menu and switch off the users choice */ printf ("\n"); switch (choice) { /* Test/Primenet dialog */ case 1: test_primenet (); break; /* Test/User Information dialog */ case 2: test_worker_threads (); break; /* Test/Status message */ case 3: test_status (); askOK (); break; /* Test/Continue or Stop or Test/Continue or Test/Stop */ case 4: if (WORKER_THREADS_ACTIVE && active_workers_count () < WORKER_THREADS_ACTIVE) test_continue_or_stop (); else if (NUM_WORKER_THREADS > 1 && active_workers_count () < WORKER_THREADS_ACTIVE - 1) test_continue (); else if (!WORKER_THREADS_ACTIVE || WORKER_THREADS_STOPPING) { while (WORKER_THREADS_STOPPING) Sleep (50); linuxContinue ("Another mprime is running.\n", ALL_WORKERS, FALSE); } else if (active_workers_count () > 1) test_stop (); else stop_workers_for_escape (); break; /* Test/Exit */ case 5: { int counter = 0; if (WORKER_THREADS_ACTIVE && !WORKER_THREADS_STOPPING) stop_workers_for_escape (); while (WORKER_THREADS_STOPPING) { if (counter++ % 100 == 0) printf ("Waiting for worker threads to stop.\n"); Sleep (50); } } return; /* Advanced/Test dialog */ case 6: advanced_test (); break; /* Advanced/Time dialog */ case 7: advanced_time (); break; /* Advanced/P-1 dialog */ case 8: advanced_pminus1 (); break; /* Advanced/ECM dialog */ case 9: advanced_ecm (); break; /* Advanced/Manual Communication dialog */ case 10: advanced_manualcomm (); break; /* Advanced/Unreserve exponent dialog */ case 11: advanced_unreserve (); break; /* Advanced/Quit Gimps dialog */ case 12: advanced_quit (); break; /* Options/CPU dialog */ case 13: options_cpu (); break; /* Options/Preferences dialog */ case 14: options_preferences (); break; /* Options/Torture Test */ case 15: torture (); askOK (); break; /* Options/Benchmark Test */ case 16: LaunchBench (); askOK (); break; /* Help/About */ case 17: help_about (); break; /* Help/About PrimeNet Server */ case 18: help_about_server (); break; } goto mloop; }