提交 4e37b226 编写于 作者: L liaogang

Revise member variable in private barrier class

上级 75beeaf7
...@@ -17,6 +17,7 @@ limitations under the License. */ ...@@ -17,6 +17,7 @@ limitations under the License. */
#include <dispatch/dispatch.h> #include <dispatch/dispatch.h>
#include <libkern/OSAtomic.h> #include <libkern/OSAtomic.h>
namespace paddle { namespace paddle {
class SemaphorePrivate { class SemaphorePrivate {
public: public:
~SemaphorePrivate() { ~SemaphorePrivate() {
...@@ -69,20 +70,20 @@ void SpinLock::unlock() { ...@@ -69,20 +70,20 @@ void SpinLock::unlock() {
class ThreadBarrierPrivate { class ThreadBarrierPrivate {
public: public:
pthread_mutex_t mutex; pthread_mutex_t mutex_;
pthread_cond_t cond; pthread_cond_t cond_;
int count; int count_;
int tripCount; int tripCount_;
inline explicit ThreadBarrierPrivate(int cnt):count(0), tripCount(cnt) { inline explicit ThreadBarrierPrivate(int cnt):count_(0), tripCount_(cnt) {
CHECK_NE(cnt, 0); CHECK_NE(cnt, 0);
CHECK_GE(pthread_mutex_init(&mutex, 0), 0); CHECK_GE(pthread_mutex_init(&mutex_, 0), 0);
CHECK_GE(pthread_cond_init(&cond, 0), 0); CHECK_GE(pthread_cond_init(&cond_, 0), 0);
} }
inline ~ThreadBarrierPrivate() { inline ~ThreadBarrierPrivate() {
pthread_cond_destroy(&cond); pthread_cond_destroy(&cond_);
pthread_mutex_destroy(&mutex); pthread_mutex_destroy(&mutex_);
} }
/** /**
...@@ -90,16 +91,16 @@ public: ...@@ -90,16 +91,16 @@ public:
* @return true if the last wait * @return true if the last wait
*/ */
inline bool wait() { inline bool wait() {
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex_);
++count; ++count_;
if (count >= tripCount) { if (count_ >= tripCount_) {
count = 0; count_ = 0;
pthread_cond_broadcast(&cond); pthread_cond_broadcast(&cond_);
pthread_mutex_unlock(&mutex); pthread_mutex_unlock(&mutex_);
return true; return true;
} else { } else {
pthread_cond_wait(&cond, &mutex); pthread_cond_wait(&cond_, &mutex_);
pthread_mutex_unlock(&mutex); pthread_mutex_unlock(&mutex_);
return false; return false;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册