diff options
author | malosek <malosek@fastmq.com> | 2009-10-05 10:22:31 +0200 |
---|---|---|
committer | malosek <malosek@fastmq.com> | 2009-10-05 10:22:31 +0200 |
commit | d57ee0984ac3f8712063a7f83d7200be25ca5513 (patch) | |
tree | a956443e70c48ebd21242c11cc015db61c53c682 /src/ypipe.hpp | |
parent | ff65e26ce7567ea6a907e566f8530f4988231d68 (diff) | |
parent | 4efe2366d7394e8969fc9aa64c50be6842d8455f (diff) |
Merge branch 'master' of git@github.com:sustrik/zeromq2
Diffstat (limited to 'src/ypipe.hpp')
-rw-r--r-- | src/ypipe.hpp | 24 |
1 files changed, 16 insertions, 8 deletions
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 @@ -166,6 +162,18 @@ namespace zmq } // 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 (); queue.pop (); |