summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2011-07-03 15:30:31 +0200
committerMartin Sustrik <sustrik@250bpm.com>2011-07-03 15:30:31 +0200
commit6ae1be1a121b9367ea11ce1789d99ec56fb39682 (patch)
treea9214a1d95e3a041ba37c6a2cbccf784028a7caa /src
parent9a9a0cf41066d32f0d16492e212712b42df36950 (diff)
Race condition in eventfd signaler fixed
recv function on eventfd signaler could accidentally grab two signals instead of one. Fixed. Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src')
-rw-r--r--src/signaler.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/signaler.cpp b/src/signaler.cpp
index 3045467..fb72a07 100644
--- a/src/signaler.cpp
+++ b/src/signaler.cpp
@@ -206,8 +206,16 @@ void zmq::signaler_t::recv ()
uint64_t dummy;
ssize_t sz = read (r, &dummy, sizeof (dummy));
errno_assert (sz == sizeof (dummy));
-if (dummy != 1)
-printf ("dummy:%d\n", (int) dummy);
+
+ // If we accidentally grabbed the next signal along with the current
+ // one, return it back to the eventfd object.
+ if (unlikely (dummy == 2)) {
+ const uint64_t inc = 1;
+ ssize_t sz = write (w, &inc, sizeof (inc));
+ errno_assert (sz == sizeof (inc));
+ return;
+ }
+
zmq_assert (dummy == 1);
#else
unsigned char dummy;