From f2ff2c6e5c4e244dea28e1ac6ec3f886b7ebc356 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Wed, 30 Sep 2009 10:08:35 +0200 Subject: checking for available messages added to ypipe/pipe --- src/ypipe.hpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/ypipe.hpp') diff --git a/src/ypipe.hpp b/src/ypipe.hpp index 6c51b63..0a9b5d5 100644 --- a/src/ypipe.hpp +++ b/src/ypipe.hpp @@ -106,16 +106,12 @@ namespace zmq return true; } - // Reads an item from the pipe. Returns false if there is no value. - // available. - inline bool read (T *value_) + // Check whether item is available for reading. + inline bool check_read () { - // Was the value prefetched already? If so, return it. - if (&queue.front () != r) { - *value_ = queue.front (); - queue.pop (); + // Was the value prefetched already? If so, return. + if (&queue.front () != r) return true; - } // There's no prefetched value, so let us prefetch more values. // (Note that D is a template parameter. Becaue of that one of @@ -165,6 +161,18 @@ namespace zmq return false; } + // There was at least one value prefetched. + return true; + } + + // Reads an item from the pipe. Returns false if there is no value. + // available. + inline bool read (T *value_) + { + // Try to prefetch a value. + if (!check_read ()) + return false; + // There was at least one value prefetched. // Return it to the caller. *value_ = queue.front (); -- cgit v1.2.3