aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2020-11-29 01:55:15 -0600
committerluigi1111 <luigi1111w@gmail.com>2020-11-29 01:55:15 -0600
commita15d78170753132ee110e8286cc3f1be44a97533 (patch)
treed7a7630e6c482923b297026cfcab4a90f90857f9 /contrib
parentMerge pull request #6973 (diff)
parentepee: readline_buffer - fix thread safety, fix sync() after stop() (diff)
downloadmonero-a15d78170753132ee110e8286cc3f1be44a97533.tar.xz
Merge pull request #6995
60bc676 epee: readline_buffer - fix thread safety, fix sync() after stop() (xiphon)
Diffstat (limited to 'contrib')
-rw-r--r--contrib/epee/src/readline_buffer.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/contrib/epee/src/readline_buffer.cpp b/contrib/epee/src/readline_buffer.cpp
index 05322b693..bcf499963 100644
--- a/contrib/epee/src/readline_buffer.cpp
+++ b/contrib/epee/src/readline_buffer.cpp
@@ -51,6 +51,7 @@ rdln::readline_buffer::readline_buffer()
void rdln::readline_buffer::start()
{
+ boost::lock_guard<boost::mutex> lock(sync_mutex);
if(m_cout_buf != NULL)
return;
m_cout_buf = std::cout.rdbuf();
@@ -60,6 +61,7 @@ void rdln::readline_buffer::start()
void rdln::readline_buffer::stop()
{
+ boost::lock_guard<boost::mutex> lock(sync_mutex);
if(m_cout_buf == NULL)
return;
std::cout.rdbuf(m_cout_buf);
@@ -88,9 +90,9 @@ rdln::linestatus rdln::readline_buffer::get_line(std::string& line) const
void rdln::readline_buffer::set_prompt(const std::string& prompt)
{
+ boost::lock_guard<boost::mutex> lock(sync_mutex);
if(m_cout_buf == NULL)
return;
- boost::lock_guard<boost::mutex> lock(sync_mutex);
rl_set_prompt(std::string(m_prompt_length, ' ').c_str());
rl_redisplay();
rl_set_prompt(prompt.c_str());
@@ -113,6 +115,12 @@ const std::vector<std::string>& rdln::readline_buffer::get_completions()
int rdln::readline_buffer::sync()
{
boost::lock_guard<boost::mutex> lock(sync_mutex);
+
+ if (m_cout_buf == nullptr)
+ {
+ return -1;
+ }
+
#if RL_READLINE_VERSION < 0x0700
char lbuf[2] = {0,0};
char *line = NULL;