summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-08-12 19:36:45 +0000
committerAlan Conway <aconway@apache.org>2008-08-12 19:36:45 +0000
commitef43b64040956f3714e98f101718b4f5f48f598c (patch)
treea868605c93271ed15a0b42d56a61e186375ad49f
parenta1f525cb64b851a5177b7564d36c08f4d5c8898d (diff)
downloadqpid-python-ef43b64040956f3714e98f101718b4f5f48f598c.tar.gz
Replace eventfd with more portable pipe implementation in PollableCondition.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@685278 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/src/qpid/cluster/PollableCondition.cpp45
-rw-r--r--qpid/cpp/src/qpid/cluster/PollableCondition.h3
2 files changed, 46 insertions, 2 deletions
diff --git a/qpid/cpp/src/qpid/cluster/PollableCondition.cpp b/qpid/cpp/src/qpid/cluster/PollableCondition.cpp
index 1970420297..eecf95ff8d 100644
--- a/qpid/cpp/src/qpid/cluster/PollableCondition.cpp
+++ b/qpid/cpp/src/qpid/cluster/PollableCondition.cpp
@@ -22,8 +22,6 @@
*
*/
-// Linux implementation of PollableCondition using the conditionfd(2) system call.
-
// FIXME aconway 2008-08-11: this could be of more general interest,
// move to common lib.
//
@@ -31,6 +29,47 @@
#include "qpid/sys/posix/PrivatePosix.h"
#include "qpid/cluster/PollableCondition.h"
#include "qpid/Exception.h"
+
+#include <unistd.h>
+#include <fcntl.h>
+
+namespace qpid {
+namespace cluster {
+
+PollableCondition::PollableCondition() : IOHandle(new sys::IOHandlePrivate) {
+ int fds[2];
+ if (::pipe(fds) == -1)
+ throw ErrnoException(QPID_MSG("Can't create PollableCondition"));
+ impl->fd = fds[0];
+ writeFd = fds[1];
+ if (::fcntl(impl->fd, F_SETFL, O_NONBLOCK) == -1)
+ throw ErrnoException(QPID_MSG("Can't create PollableCondition"));
+ if (::fcntl(writeFd, F_SETFL, O_NONBLOCK) == -1)
+ throw ErrnoException(QPID_MSG("Can't create PollableCondition"));
+}
+
+bool PollableCondition::clear() {
+ char buf[256];
+ ssize_t n;
+ bool wasSet = false;
+ while ((n = ::read(impl->fd, buf, sizeof(buf))) > 0)
+ wasSet = true;
+ if (n == -1 && errno != EAGAIN) throw ErrnoException(QPID_MSG("Error clearing PollableCondition"));
+ return wasSet;
+}
+
+void PollableCondition::set() {
+ static const char dummy=0;
+ ssize_t n = ::write(writeFd, &dummy, 1);
+ if (n == -1 && errno != EAGAIN) throw ErrnoException("Error setting PollableCondition");
+}
+
+
+#if 0
+// FIXME aconway 2008-08-12: More efficient Linux implementation using
+// eventfd system call. Do a configure.ac test to enable this when
+// eventfd is available.
+
#include <sys/eventfd.h>
namespace qpid {
@@ -54,6 +93,8 @@ void PollableCondition::set() {
if (n != 8) throw ErrnoException("write failed on conditionfd");
}
+#endif
+
}} // namespace qpid::cluster
#endif /*!QPID_SYS_LINUX_POLLABLECONDITION_CPP*/
diff --git a/qpid/cpp/src/qpid/cluster/PollableCondition.h b/qpid/cpp/src/qpid/cluster/PollableCondition.h
index affcae580a..6bfca6cabe 100644
--- a/qpid/cpp/src/qpid/cluster/PollableCondition.h
+++ b/qpid/cpp/src/qpid/cluster/PollableCondition.h
@@ -51,6 +51,9 @@ class PollableCondition : public sys::IOHandle {
*@return The state of the condition before it was cleared.
*/
bool clear();
+
+ private:
+ int writeFd;
};
}} // namespace qpid::cluster