diff options
author | dwight <dwight@10gen.com> | 2010-09-13 08:31:57 -0400 |
---|---|---|
committer | dwight <dwight@10gen.com> | 2010-09-13 08:31:57 -0400 |
commit | 7709c273590194d14bdeb5f903537224b3f0d81e (patch) | |
tree | c9542c7c8b75fa79eeb581a872aec6df1f3d5d23 /util | |
parent | d48a16161eac5f462e4e0b453dc9bdd9c5683070 (diff) | |
parent | 03a596e18b839a452b935141c329e4a1a6fa9b9f (diff) | |
download | mongo-7709c273590194d14bdeb5f903537224b3f0d81e.tar.gz |
Merge branch 'master' of github.com:mongodb/mongo
Diffstat (limited to 'util')
-rw-r--r-- | util/queue.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/util/queue.h b/util/queue.h index 35e02a87330..304c1d168d8 100644 --- a/util/queue.h +++ b/util/queue.h @@ -63,6 +63,33 @@ namespace mongo { _queue.pop(); return t; } + + + /** + * blocks waiting for an object until maxSecondsToWait passes + * if maxSecondsToWait passes, an Timeout exception is thrown + */ + T blockingPop( int maxSecondsToWait ){ + + Timer timer; + + boost::xtime xt; + boost::xtime_get(&xt, boost::TIME_UTC); + xt.sec += maxSecondsToWait; + + scoped_lock l( _lock ); + while( _queue.empty() ){ + _condition.timed_wait( l.boost() , xt ); + if ( timer.seconds() >= maxSecondsToWait ) + throw Timeout(); + } + + T t = _queue.front(); + _queue.pop(); + return t; + } + + class Timeout {}; private: std::queue<T> _queue; |