summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRALOVICH, Kristof <tade60@freemail.hu>2014-01-19 14:20:11 +0100
committerRALOVICH, Kristof <tade60@freemail.hu>2014-01-19 14:20:11 +0100
commit870f9e47d59eeee738c4aa029da4c72e957d1950 (patch)
treedccfa50e89f997cbbb432482f214f9a2b15049f0 /src
parent36ded0ebf0dd7e527d3e02db10b90f33ba51505b (diff)
infrastructure to interrupt waiting message listeners
basically we intentionally generate a "spurious wakeup" of the condition variable
Diffstat (limited to 'src')
-rw-r--r--src/AntChannel.cpp18
-rw-r--r--src/AntChannel.hpp2
-rw-r--r--src/AntMessenger.cpp10
-rw-r--r--src/AntMessenger.hpp1
4 files changed, 31 insertions, 0 deletions
diff --git a/src/AntChannel.cpp b/src/AntChannel.cpp
index f4639ac..2594501 100644
--- a/src/AntChannel.cpp
+++ b/src/AntChannel.cpp
@@ -48,6 +48,16 @@ AntChannel::onMsg(AntMessage &m)
}
}
+void
+AntChannel::interruptWait()
+{
+ boost::unique_lock<boost::mutex> lock(m_mtxListeners);
+ for(std::list<AntListenerBase*>::iterator i = listeners.begin(); i != listeners.end(); i++)
+ {
+ (*i)->interruptWait();
+ }
+}
+
@@ -78,6 +88,14 @@ AntListenerBase::onMsg(AntMessage& m)
}
}
+void
+AntListenerBase::interruptWait()
+{
+ boost::unique_lock<boost::mutex> lock(m_mtxResp);
+ m_msgResp.reset();
+ m_cndResp.notify_all(); // intentionally generate a "spurious" wakeup
+}
+
bool
AntListenerBase::waitForMsg(AntMessage* m, const size_t timeout_ms)
{
diff --git a/src/AntChannel.hpp b/src/AntChannel.hpp
index 0549267..3165793 100644
--- a/src/AntChannel.hpp
+++ b/src/AntChannel.hpp
@@ -38,6 +38,7 @@ public:
AntListenerBase(AntChannel& o);
virtual ~AntListenerBase();
virtual void onMsg(AntMessage& m);
+ virtual void interruptWait();
protected:
virtual bool match(AntMessage& other) const = 0;
public:
@@ -55,6 +56,7 @@ public:
void addMsgListener2(AntListenerBase* lb);
void rmMsgListener2(AntListenerBase* lb);
void onMsg(AntMessage &m);
+ void interruptWait();
};
diff --git a/src/AntMessenger.cpp b/src/AntMessenger.cpp
index a9bfa29..daf9b69 100644
--- a/src/AntMessenger.cpp
+++ b/src/AntMessenger.cpp
@@ -1138,6 +1138,16 @@ AntMessenger::waitForBroadcast(const uchar chan, AntMessage* reply, const size_t
}
+void
+AntMessenger::interruptWait()
+{
+ for(size_t i = 0; i < ANTPM_MAX_CHANNELS; i++)
+ {
+ chs[i].interruptWait();
+ }
+}
+
+
// receive bytes from the serial interface
void*
AntMessenger::th_messageHandler()
diff --git a/src/AntMessenger.hpp b/src/AntMessenger.hpp
index 52a4c10..d315e39 100644
--- a/src/AntMessenger.hpp
+++ b/src/AntMessenger.hpp
@@ -162,6 +162,7 @@ private:
public:
bool waitForBurst(const uchar chan, std::vector<uchar>& burstData, const size_t timeout_ms = 30000);
bool waitForBroadcast(const uchar chan, AntMessage* reply = NULL, const size_t timeout_ms = 2000);
+ void interruptWait();
//public:
private:
Serial* m_io;