Rearrange main loop so that --net-only isn't quite such a special case.

This commit is contained in:
Oliver Jowett 2015-02-17 21:44:30 +00:00
parent 0a055c34d0
commit 38845c2447

View file

@ -1003,24 +1003,20 @@ int main(int argc, char **argv) {
// If the user specifies --net-only, just run in order to serve network
// clients without reading data from the RTL device
while (Modes.net_only) {
if (Modes.net_only) {
while (!Modes.exit) {
struct timespec start_time;
if (Modes.exit) {
display_total_stats();
exit(0); // If we exit net_only nothing further in main()
}
start_cpu_timing(&start_time);
backgroundTasks();
end_cpu_timing(&start_time, &Modes.stats_current.background_cpu);
usleep(100000);
}
} else {
// Create the thread that will read the data from the device.
pthread_create(&Modes.reader_thread, NULL, readerThreadEntryPoint, NULL);
pthread_mutex_lock(&Modes.data_mutex);
pthread_create(&Modes.reader_thread, NULL, readerThreadEntryPoint, NULL);
while (Modes.exit == 0) {
struct timespec start_time;
@ -1103,14 +1099,16 @@ int main(int argc, char **argv) {
pthread_mutex_unlock(&Modes.data_mutex);
pthread_join(Modes.reader_thread,NULL); // Wait on reader thread exit
pthread_cond_destroy(&Modes.data_cond); // Thread cleanup - only after the reader thread is dead!
pthread_mutex_destroy(&Modes.data_mutex);
}
// If --stats were given, print statistics
if (Modes.stats) {
display_total_stats();
}
pthread_join(Modes.reader_thread,NULL); // Wait on reader thread exit
pthread_cond_destroy(&Modes.data_cond); // Thread cleanup - only after the reader thread is dead!
pthread_mutex_destroy(&Modes.data_mutex);
log_with_timestamp("Normal exit.");
#ifndef _WIN32