enb: fix stopping of input thread

since we've used a blocking read of stdin (with std::getline())
we had a race when the eNB was stopped and the user was still making
keyboard inputs. this is because the we didn't wait until the input
thread was terminated until we stopped the eNB.

we know use poll to query stdin (getline has no timeout mechanism).
master
Andre Puschmann 4 years ago
parent db03275337
commit 1d1d52f3e6

@ -19,6 +19,7 @@
*
*/
#include <poll.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
@ -401,8 +402,12 @@ static bool do_metrics = false;
static void* input_loop(metrics_stdout* metrics, srsenb::enb_command_interface* control)
{
struct pollfd pfd = {STDIN_FILENO, POLLIN, 0};
string input_line;
while (running) {
int ret = poll(&pfd, 1, 1000); // query stdin with a timeout of 1000ms
if (ret == 1) {
// there is user input to read
getline(cin, input_line);
if (cin.eof() || cin.bad()) {
cout << "Closing stdin thread." << endl;
@ -441,6 +446,7 @@ static void* input_loop(metrics_stdout* metrics, srsenb::enb_command_interface*
}
}
}
}
return nullptr;
}
@ -504,9 +510,8 @@ int main(int argc, char* argv[])
}
// create input thread
thread input(&input_loop, &metrics_screen, (enb_command_interface*)enb.get());
std::thread input(&input_loop, &metrics_screen, (enb_command_interface*)enb.get());
bool signals_pregenerated = false;
if (running) {
if (args.gui.enable) {
enb->start_plot();
@ -521,8 +526,9 @@ int main(int argc, char* argv[])
enb->print_pool();
}
}
usleep(10000);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
input.join();
metricshub.stop();
enb->stop();
cout << "--- exiting ---" << endl;

Loading…
Cancel
Save