-- assert fixes for thrift concurrency lib
Summary:
- cannot assume that assert.h is defined
Reviewed By: marc k
Test Plan: everything compiles
Notes:
- need to reflect these changes in libfacebook/fbthread
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665073 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/Monitor.cpp b/lib/cpp/src/concurrency/Monitor.cpp
index ecd82ad..955fe9a 100644
--- a/lib/cpp/src/concurrency/Monitor.cpp
+++ b/lib/cpp/src/concurrency/Monitor.cpp
@@ -32,9 +32,11 @@
condInitialized_(false) {
try {
- assert(pthread_mutex_init(&pthread_mutex_, NULL) == 0);
+ int ret = pthread_mutex_init(&pthread_mutex_, NULL);
+ assert(ret);
mutexInitialized_ = true;
- assert(pthread_cond_init(&pthread_cond_, NULL) == 0);
+ ret = pthread_cond_init(&pthread_cond_, NULL);
+ assert(ret);
condInitialized_ = true;
} catch(...) {
cleanup();
@@ -50,9 +52,11 @@
void wait(long long timeout) const {
// XXX Need to assert that caller owns mutex
- assert(timeout >= 0LL);
+ bool bret = (timeout >= 0LL);
+ assert(bret);
if (timeout == 0LL) {
- assert(pthread_cond_wait(&pthread_cond_, &pthread_mutex_) == 0);
+ int iret = pthread_cond_wait(&pthread_cond_, &pthread_mutex_);
+ assert(iret);
} else {
struct timespec abstime;
long long now = Util::currentTime();
@@ -61,19 +65,22 @@
&pthread_mutex_,
&abstime);
if (result == ETIMEDOUT) {
- assert(Util::currentTime() >= (now + timeout));
+ bret = (Util::currentTime() >= (now + timeout));
+ assert(bret);
}
}
}
void notify() {
// XXX Need to assert that caller owns mutex
- assert(pthread_cond_signal(&pthread_cond_) == 0);
+ int iret = pthread_cond_signal(&pthread_cond_);
+ assert(iret);
}
void notifyAll() {
// XXX Need to assert that caller owns mutex
- assert(pthread_cond_broadcast(&pthread_cond_) == 0);
+ int iret = pthread_cond_broadcast(&pthread_cond_);
+ assert(iret);
}
private:
@@ -81,12 +88,14 @@
void cleanup() {
if (mutexInitialized_) {
mutexInitialized_ = false;
- assert(pthread_mutex_destroy(&pthread_mutex_) == 0);
+ int iret = pthread_mutex_destroy(&pthread_mutex_);
+ assert(iret);
}
if (condInitialized_) {
condInitialized_ = false;
- assert(pthread_cond_destroy(&pthread_cond_) == 0);
+ int iret = pthread_cond_destroy(&pthread_cond_);
+ assert(iret);
}
}
diff --git a/lib/cpp/src/concurrency/Mutex.cpp b/lib/cpp/src/concurrency/Mutex.cpp
index 3d74d75..0f650a1 100644
--- a/lib/cpp/src/concurrency/Mutex.cpp
+++ b/lib/cpp/src/concurrency/Mutex.cpp
@@ -20,14 +20,16 @@
class Mutex::impl {
public:
impl() : initialized_(false) {
- assert(pthread_mutex_init(&pthread_mutex_, NULL) == 0);
+ int ret = pthread_mutex_init(&pthread_mutex_, NULL);
+ assert(ret);
initialized_ = true;
}
~impl() {
if (initialized_) {
initialized_ = false;
- assert(pthread_mutex_destroy(&pthread_mutex_) == 0);
+ int ret = pthread_mutex_destroy(&pthread_mutex_);
+ assert(ret);
}
}
diff --git a/lib/cpp/src/concurrency/PosixThreadFactory.cpp b/lib/cpp/src/concurrency/PosixThreadFactory.cpp
index d5d0d06..a043418 100644
--- a/lib/cpp/src/concurrency/PosixThreadFactory.cpp
+++ b/lib/cpp/src/concurrency/PosixThreadFactory.cpp
@@ -68,25 +68,32 @@
state_ = starting;
pthread_attr_t thread_attr;
- assert(pthread_attr_init(&thread_attr) == 0);
- assert(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE) == 0);
+ int ret = pthread_attr_init(&thread_attr);
+ assert(ret);
+
+ ret = pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);
+ assert(ret);
// Set thread stack size
- assert(pthread_attr_setstacksize(&thread_attr, MB * stackSize_) == 0);
+ ret = pthread_attr_setstacksize(&thread_attr, MB * stackSize_);
+ assert(ret);
// Set thread policy
- assert(pthread_attr_setschedpolicy(&thread_attr, policy_) == 0);
+ ret = pthread_attr_setschedpolicy(&thread_attr, policy_);
+ assert(ret);
struct sched_param sched_param;
sched_param.sched_priority = priority_;
// Set thread priority
- assert(pthread_attr_setschedparam(&thread_attr, &sched_param) == 0);
+ ret = pthread_attr_setschedparam(&thread_attr, &sched_param);
+ assert(ret);
// Create reference
shared_ptr<PthreadThread>* selfRef = new shared_ptr<PthreadThread>();
*selfRef = self_.lock();
- assert(pthread_create(&pthread_, &thread_attr, threadMain, (void*)selfRef) == 0);
+ ret = pthread_create(&pthread_, &thread_attr, threadMain, (void*)selfRef);
+ assert(ret);
}
void join() {
@@ -101,7 +108,8 @@
void runnable(shared_ptr<Runnable> value) { Thread::runnable(value); }
void weakRef(shared_ptr<PthreadThread> self) {
- assert(self.get() == this);
+ bool ret = (self.get() == this);
+ assert(ret);
self_ = weak_ptr<PthreadThread>(self);
}
};
diff --git a/lib/cpp/src/concurrency/TimerManager.cpp b/lib/cpp/src/concurrency/TimerManager.cpp
index 050885d..6ab0e76 100644
--- a/lib/cpp/src/concurrency/TimerManager.cpp
+++ b/lib/cpp/src/concurrency/TimerManager.cpp
@@ -96,7 +96,8 @@
if (!manager_->taskMap_.empty()) {
timeout = manager_->taskMap_.begin()->first - now;
}
- assert((timeout != 0 && manager_->taskCount_ > 0) || (timeout == 0 && manager_->taskCount_ == 0));
+ bool ret = (timeout != 0 && manager_->taskCount_ > 0) || (timeout == 0 && manager_->taskCount_ == 0);
+ assert(ret);
manager_->monitor_.wait(timeout);
now = Util::currentTime();
}
@@ -182,7 +183,8 @@
while (state_ == TimerManager::STARTING) {
monitor_.wait();
}
- assert(state_ != TimerManager::STARTING);
+ bool ret = (state_ != TimerManager::STARTING);
+ assert(ret);
}
}
diff --git a/lib/cpp/src/concurrency/Util.h b/lib/cpp/src/concurrency/Util.h
index 06b4d18..de4d578 100644
--- a/lib/cpp/src/concurrency/Util.h
+++ b/lib/cpp/src/concurrency/Util.h
@@ -67,14 +67,16 @@
static const long long currentTime() {
#if defined(HAVE_CLOCK_GETTIME)
struct timespec now;
- assert(clock_gettime(CLOCK_REALTIME, &now) == 0);
+ int ret = clock_gettime(CLOCK_REALTIME, &now);
+ assert(ret);
return
(now.tv_sec * MS_PER_S) +
(now.tv_nsec / NS_PER_MS) +
(now.tv_nsec % NS_PER_MS >= 500000 ? 1 : 0) ;
#elif defined(HAVE_GETTIMEOFDAY)
struct timeval now;
- assert(gettimeofday(&now, NULL) == 0);
+ int ret = gettimeofday(&now, NULL);
+ assert(ret);
return
(((long long)now.tv_sec) * MS_PER_S) +
(now.tv_usec / MS_PER_S) +