From 3f234dad0ed5e5eb629e5eaf451672366ce1f89e Mon Sep 17 00:00:00 2001 From: Aditya Agarwal Date: Sun, 1 Apr 2007 01:19:57 +0000 Subject: [PATCH] -- more assert fixes for thrift concurrency Reviewed By: mcslee git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665074 13f79535-47bb-0310-9956-ffa450edef68 --- lib/cpp/src/concurrency/Monitor.cpp | 20 +++++++++---------- lib/cpp/src/concurrency/Mutex.cpp | 4 ++-- .../src/concurrency/PosixThreadFactory.cpp | 15 +++++++------- lib/cpp/src/concurrency/TimerManager.cpp | 6 ++---- lib/cpp/src/concurrency/Util.h | 4 ++-- 5 files changed, 22 insertions(+), 27 deletions(-) diff --git a/lib/cpp/src/concurrency/Monitor.cpp b/lib/cpp/src/concurrency/Monitor.cpp index 955fe9a3..2443a6eb 100644 --- a/lib/cpp/src/concurrency/Monitor.cpp +++ b/lib/cpp/src/concurrency/Monitor.cpp @@ -33,10 +33,10 @@ class Monitor::Impl { try { int ret = pthread_mutex_init(&pthread_mutex_, NULL); - assert(ret); + assert(ret == 0); mutexInitialized_ = true; ret = pthread_cond_init(&pthread_cond_, NULL); - assert(ret); + assert(ret == 0); condInitialized_ = true; } catch(...) { cleanup(); @@ -52,11 +52,10 @@ class Monitor::Impl { void wait(long long timeout) const { // XXX Need to assert that caller owns mutex - bool bret = (timeout >= 0LL); - assert(bret); + assert(timeout >= 0LL); if (timeout == 0LL) { int iret = pthread_cond_wait(&pthread_cond_, &pthread_mutex_); - assert(iret); + assert(iret == 0); } else { struct timespec abstime; long long now = Util::currentTime(); @@ -65,8 +64,7 @@ class Monitor::Impl { &pthread_mutex_, &abstime); if (result == ETIMEDOUT) { - bret = (Util::currentTime() >= (now + timeout)); - assert(bret); + assert(Util::currentTime() >= (now + timeout)); } } } @@ -74,13 +72,13 @@ class Monitor::Impl { void notify() { // XXX Need to assert that caller owns mutex int iret = pthread_cond_signal(&pthread_cond_); - assert(iret); + assert(iret == 0); } void notifyAll() { // XXX Need to assert that caller owns mutex int iret = pthread_cond_broadcast(&pthread_cond_); - assert(iret); + assert(iret == 0); } private: @@ -89,13 +87,13 @@ class Monitor::Impl { if (mutexInitialized_) { mutexInitialized_ = false; int iret = pthread_mutex_destroy(&pthread_mutex_); - assert(iret); + assert(iret == 0); } if (condInitialized_) { condInitialized_ = false; int iret = pthread_cond_destroy(&pthread_cond_); - assert(iret); + assert(iret == 0); } } diff --git a/lib/cpp/src/concurrency/Mutex.cpp b/lib/cpp/src/concurrency/Mutex.cpp index 0f650a19..5993ea19 100644 --- a/lib/cpp/src/concurrency/Mutex.cpp +++ b/lib/cpp/src/concurrency/Mutex.cpp @@ -21,7 +21,7 @@ class Mutex::impl { public: impl() : initialized_(false) { int ret = pthread_mutex_init(&pthread_mutex_, NULL); - assert(ret); + assert(ret == 0); initialized_ = true; } @@ -29,7 +29,7 @@ class Mutex::impl { if (initialized_) { initialized_ = false; int ret = pthread_mutex_destroy(&pthread_mutex_); - assert(ret); + assert(ret == 0); } } diff --git a/lib/cpp/src/concurrency/PosixThreadFactory.cpp b/lib/cpp/src/concurrency/PosixThreadFactory.cpp index a043418d..972c1c1d 100644 --- a/lib/cpp/src/concurrency/PosixThreadFactory.cpp +++ b/lib/cpp/src/concurrency/PosixThreadFactory.cpp @@ -69,31 +69,31 @@ class PthreadThread: public Thread { pthread_attr_t thread_attr; int ret = pthread_attr_init(&thread_attr); - assert(ret); + assert(ret == 0); ret = pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE); - assert(ret); + assert(ret == 0); // Set thread stack size ret = pthread_attr_setstacksize(&thread_attr, MB * stackSize_); - assert(ret); + assert(ret == 0); // Set thread policy ret = pthread_attr_setschedpolicy(&thread_attr, policy_); - assert(ret); + assert(ret == 0); struct sched_param sched_param; sched_param.sched_priority = priority_; // Set thread priority ret = pthread_attr_setschedparam(&thread_attr, &sched_param); - assert(ret); + assert(ret == 0); // Create reference shared_ptr* selfRef = new shared_ptr(); *selfRef = self_.lock(); ret = pthread_create(&pthread_, &thread_attr, threadMain, (void*)selfRef); - assert(ret); + assert(ret == 0); } void join() { @@ -108,8 +108,7 @@ class PthreadThread: public Thread { void runnable(shared_ptr value) { Thread::runnable(value); } void weakRef(shared_ptr self) { - bool ret = (self.get() == this); - assert(ret); + assert(self.get() == this); self_ = weak_ptr(self); } }; diff --git a/lib/cpp/src/concurrency/TimerManager.cpp b/lib/cpp/src/concurrency/TimerManager.cpp index 6ab0e766..050885d4 100644 --- a/lib/cpp/src/concurrency/TimerManager.cpp +++ b/lib/cpp/src/concurrency/TimerManager.cpp @@ -96,8 +96,7 @@ class TimerManager::Dispatcher: public Runnable { if (!manager_->taskMap_.empty()) { timeout = manager_->taskMap_.begin()->first - now; } - bool ret = (timeout != 0 && manager_->taskCount_ > 0) || (timeout == 0 && manager_->taskCount_ == 0); - assert(ret); + assert((timeout != 0 && manager_->taskCount_ > 0) || (timeout == 0 && manager_->taskCount_ == 0)); manager_->monitor_.wait(timeout); now = Util::currentTime(); } @@ -183,8 +182,7 @@ void TimerManager::start() { while (state_ == TimerManager::STARTING) { monitor_.wait(); } - bool ret = (state_ != TimerManager::STARTING); - assert(ret); + assert(state_ != TimerManager::STARTING); } } diff --git a/lib/cpp/src/concurrency/Util.h b/lib/cpp/src/concurrency/Util.h index de4d5789..fe12b497 100644 --- a/lib/cpp/src/concurrency/Util.h +++ b/lib/cpp/src/concurrency/Util.h @@ -68,7 +68,7 @@ class Util { #if defined(HAVE_CLOCK_GETTIME) struct timespec now; int ret = clock_gettime(CLOCK_REALTIME, &now); - assert(ret); + assert(ret == 0); return (now.tv_sec * MS_PER_S) + (now.tv_nsec / NS_PER_MS) + @@ -76,7 +76,7 @@ class Util { #elif defined(HAVE_GETTIMEOFDAY) struct timeval now; int ret = gettimeofday(&now, NULL); - assert(ret); + assert(ret == 0); return (((long long)now.tv_sec) * MS_PER_S) + (now.tv_usec / MS_PER_S) + -- 2.17.1