More bullet proofing of timer manager
facebook::thrift::concurrency::TimerManager::stop
Added proper cleanup of unprocessed tasks and shutdown of dispatcher thread to stop
facebook::thrift::concurrency::TimerManager::~TimerManager
Call stop if manager wasn't explicitly stopped
facebook::thrift::concurrency::test.TimerManagerTest
Calculate error margin for timeout expiration and verify it's within bounds
Verify manager stops properly when it goes out of scope
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664724 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/Monitor.cc b/lib/cpp/src/concurrency/Monitor.cc
index f6144ba..b1d7b72 100644
--- a/lib/cpp/src/concurrency/Monitor.cc
+++ b/lib/cpp/src/concurrency/Monitor.cc
@@ -59,6 +59,8 @@
// XXX Need to assert that caller owns mutex
+ assert(timeout >= 0LL);
+
if(timeout == 0LL) {
assert(pthread_cond_wait(&_pthread_cond, &_pthread_mutex) == 0);
@@ -67,13 +69,15 @@
struct timespec abstime;
+ long long now = Util::currentTime();
+
+ Util::toTimespec(abstime, now + timeout);
+
int result = pthread_cond_timedwait(&_pthread_cond, &_pthread_mutex, &abstime);
if(result == ETIMEDOUT) {
- // XXX Add assert once currentTime is fixed to have ms resolution or better
-
- // assert(Util::currentTime() >= (now + timeout));
+ assert(Util::currentTime() >= (now + timeout));
}
}
}