Commit 8cb71cbd authored by ahoms's avatar ahoms

* added mutex lock/unlock to Frelon::SerialLine write/readLine (respectively)


git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@156 45c4679d-1946-429d-baad-37912b19538b
parent 4a0c4166
......@@ -2,6 +2,7 @@
#define FRELONSERIALLINE_H
#include "Frelon.h"
#include "ThreadUtils.h"
namespace lima
{
......@@ -67,6 +68,7 @@ class SerialLine : public HwSerialLine
private:
Espia::SerialLine& m_espia_ser_line;
Mutex m_mutex;
bool m_multi_line_cmd;
bool m_reset_cmd;
int m_last_warn;
......
......@@ -37,6 +37,8 @@ void SerialLine::write(const string& buffer, bool no_wait)
splitMsg(buffer, msg_parts);
const string& cmd = msg_parts[MsgCmd];
m_mutex.lock();
m_multi_line_cmd = false;
m_reset_cmd = (cmd == CmdStrMap[Reset]);
if (!m_reset_cmd) {
......@@ -70,6 +72,14 @@ void SerialLine::readStr(string& buffer, int max_len,
void SerialLine::readLine(string& buffer, int max_len, double timeout)
{
class AutoUnlock
{
Mutex& m;
public:
AutoUnlock(Mutex& mutex) : m(mutex) {}
~AutoUnlock() { m.unlock(); }
} ul(m_mutex);
if ((timeout == TimeoutDefault) && (m_multi_line_cmd))
readMultiLine(buffer, max_len);
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment