summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys/posix/PollableCondition.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/qpid/sys/posix/PollableCondition.cpp')
-rw-r--r--cpp/src/qpid/sys/posix/PollableCondition.cpp113
1 files changed, 25 insertions, 88 deletions
diff --git a/cpp/src/qpid/sys/posix/PollableCondition.cpp b/cpp/src/qpid/sys/posix/PollableCondition.cpp
index 0991e5fd76..b22a615a54 100644
--- a/cpp/src/qpid/sys/posix/PollableCondition.cpp
+++ b/cpp/src/qpid/sys/posix/PollableCondition.cpp
@@ -46,8 +46,8 @@ private:
~PollableConditionPrivate();
void dispatch(sys::DispatchHandle& h);
- void rewatch();
- void unwatch();
+ void set();
+ void clear();
private:
PollableCondition::Callback cb;
@@ -57,10 +57,11 @@ private:
std::auto_ptr<DispatchHandleRef> handle;
};
-PollableConditionPrivate::PollableConditionPrivate(const sys::PollableCondition::Callback& cb,
- sys::PollableCondition& parent,
- const boost::shared_ptr<sys::Poller>& poller)
- : IOHandle(new sys::IOHandlePrivate), cb(cb), parent(parent)
+PollableConditionPrivate::PollableConditionPrivate(
+ const sys::PollableCondition::Callback& cb,
+ sys::PollableCondition& parent,
+ const boost::shared_ptr<sys::Poller>& poller
+) : IOHandle(new sys::IOHandlePrivate), cb(cb), parent(parent)
{
int fds[2];
if (::pipe(fds) == -1)
@@ -71,39 +72,41 @@ PollableConditionPrivate::PollableConditionPrivate(const sys::PollableCondition:
throw ErrnoException(QPID_MSG("Can't create PollableCondition"));
if (::fcntl(writeFd, F_SETFL, O_NONBLOCK) == -1)
throw ErrnoException(QPID_MSG("Can't create PollableCondition"));
- handle.reset (new DispatchHandleRef(*this,
- boost::bind(&sys::PollableConditionPrivate::dispatch, this, _1),
- 0, 0));
+ handle.reset (new DispatchHandleRef(
+ *this,
+ boost::bind(&sys::PollableConditionPrivate::dispatch, this, _1),
+ 0, 0));
handle->startWatch(poller);
handle->unwatch();
+
+ // Make the read FD readable
+ static const char dummy=0;
+ ssize_t n = ::write(writeFd, &dummy, 1);
+ if (n == -1 && errno != EAGAIN)
+ throw ErrnoException("Error setting PollableCondition");
}
-PollableConditionPrivate::~PollableConditionPrivate()
-{
+PollableConditionPrivate::~PollableConditionPrivate() {
handle->stopWatch();
close(writeFd);
}
-void PollableConditionPrivate::dispatch(sys::DispatchHandle& /*h*/)
-{
+void PollableConditionPrivate::dispatch(sys::DispatchHandle&) {
cb(parent);
}
-void PollableConditionPrivate::rewatch()
-{
+void PollableConditionPrivate::set() {
handle->rewatch();
}
-void PollableConditionPrivate::unwatch()
-{
+void PollableConditionPrivate::clear() {
handle->unwatch();
}
- /* PollableCondition */
PollableCondition::PollableCondition(const Callback& cb,
- const boost::shared_ptr<sys::Poller>& poller)
- : impl(new PollableConditionPrivate(cb, *this, poller))
+ const boost::shared_ptr<sys::Poller>& poller
+) : impl(new PollableConditionPrivate(cb, *this, poller))
{
}
@@ -112,75 +115,9 @@ PollableCondition::~PollableCondition()
delete impl;
}
-void PollableCondition::set() {
- static const char dummy=0;
- ssize_t n = ::write(impl->writeFd, &dummy, 1);
- if (n == -1 && errno != EAGAIN)
- throw ErrnoException("Error setting PollableCondition");
-}
-
-bool PollableCondition::clear() {
- char buf[256];
- ssize_t n;
- bool wasSet = false;
- while ((n = ::read(impl->impl->fd, buf, sizeof(buf))) > 0)
- wasSet = true;
- if (n == -1 && errno != EAGAIN)
- throw ErrnoException(QPID_MSG("Error clearing PollableCondition"));
- return wasSet;
-}
-
-void PollableCondition::disarm() {
- impl->unwatch();
-}
-
-void PollableCondition::rearm() {
- impl->rewatch();
-}
-
-
-#if 0
-// FIXME aconway 2008-08-12: More efficient Linux implementation using
-// eventfd system call. Move to separate file & do configure.ac test
-// to enable this when ::eventfd() is available.
-
-#include <sys/eventfd.h>
+void PollableCondition::set() { impl->set(); }
-namespace qpid {
-namespace sys {
-
-PollableConditionPrivate::PollableConditionPrivate(const PollableCondition::Callback& cb,
- sys::PollableCondition& parent,
- const boost::shared_ptr<sys::Poller>& poller)
- : cb(cb), parent(parent), poller(poller),
- IOHandle(new sys::IOHandlePrivate) {
- impl->fd = ::eventfd(0, 0);
- if (impl->fd < 0) throw ErrnoException("conditionfd() failed");
-}
-
-void PollableCondition::set() {
- static const uint64_t value=1;
- ssize_t n = ::write(impl->impl->fd,
- reinterpret_cast<const void*>(&value), 8);
- if (n != 8) throw ErrnoException("write failed on conditionfd");
-}
-
-bool PollableCondition::clear() {
- char buf[8];
- ssize_t n = ::read(impl->impl->fd, buf, 8);
- if (n != 8) throw ErrnoException("read failed on conditionfd");
- return *reinterpret_cast<uint64_t*>(buf);
-}
-
-void PollableCondition::disarm() {
- // ????
-}
-
-void PollableCondition::rearm() {
- // ????
-}
-
-#endif
+void PollableCondition::clear() { impl->clear(); }
}} // namespace qpid::sys