monero-wallet-cli: hang on exit in readline code (#2117)

readline_buffer: fix start/stop threads being starved by process

process could run for quite some time re-acquiring the process
lock, leaving start/stop starving. Yielding after unlock in
process is much better but doesn't seem to be enough to reliably
yield, so we sleep for a millisecond, which should be transparent
for user input anyway.

Signed-off-by: Jethro Grassie <jtg@xtrabass.com>
This commit is contained in:
moneromooo-monero 2017-06-27 08:10:26 -07:00 committed by Jethro Grassie
parent be9d4f0411
commit a73a42a6b0
No known key found for this signature in database
GPG Key ID: DE8ED755616565BB
1 changed files with 10 additions and 2 deletions

View File

@ -5,6 +5,7 @@
#include <unistd.h> #include <unistd.h>
#include <mutex> #include <mutex>
#include <condition_variable> #include <condition_variable>
#include <boost/thread.hpp>
static int process_input(); static int process_input();
static void install_line_handler(); static void install_line_handler();
@ -83,10 +84,17 @@ void rdln::readline_buffer::set_prompt(const std::string& prompt)
int rdln::readline_buffer::process() int rdln::readline_buffer::process()
{ {
std::unique_lock<std::mutex> lock(process_mutex); process_mutex.lock();
if(m_cout_buf == NULL) if(m_cout_buf == NULL)
{
process_mutex.unlock();
boost::this_thread::sleep_for(boost::chrono::milliseconds( 1 ));
return 0; return 0;
return process_input(); }
int count = process_input();
process_mutex.unlock();
boost::this_thread::sleep_for(boost::chrono::milliseconds( 1 ));
return count;
} }
int rdln::readline_buffer::sync() int rdln::readline_buffer::sync()