C++ Thrift coding style changes
Summary: Make underscore for class members consistent
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664818 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/ThreadManager.cc b/lib/cpp/src/concurrency/ThreadManager.cc
index 7d6fef7..895d1cd 100644
--- a/lib/cpp/src/concurrency/ThreadManager.cc
+++ b/lib/cpp/src/concurrency/ThreadManager.cc
@@ -32,10 +32,10 @@
public:
Impl() :
- _workerCount(0),
- _workerMaxCount(0),
- _idleCount(0),
- _state(ThreadManager::UNINITIALIZED) {}
+ workerCount_(0),
+ workerMaxCount_(0),
+ idleCount_(0),
+ state_(ThreadManager::UNINITIALIZED) {}
~Impl() { stop(); }
@@ -43,37 +43,41 @@
void stop();
- const ThreadManager::STATE state() const { return _state; }
+ const ThreadManager::STATE state() const {
+ return state_;
+ }
shared_ptr<ThreadFactory> threadFactory() const {
- Synchronized s(_monitor);
- return _threadFactory;
+ Synchronized s(monitor_);
+ return threadFactory_;
}
void threadFactory(shared_ptr<ThreadFactory> value) {
- Synchronized s(_monitor);
- _threadFactory = value;
+ Synchronized s(monitor_);
+ threadFactory_ = value;
}
void addWorker(size_t value);
void removeWorker(size_t value);
- size_t idleWorkerCount() const { return _idleCount; }
+ size_t idleWorkerCount() const {
+ return idleCount_;
+ }
size_t workerCount() const {
- Synchronized s(_monitor);
- return _workerCount;
+ Synchronized s(monitor_);
+ return workerCount_;
}
size_t pendingTaskCount() const {
- Synchronized s(_monitor);
- return _tasks.size();
+ Synchronized s(monitor_);
+ return tasks_.size();
}
size_t totalTaskCount() const {
- Synchronized s(_monitor);
- return _tasks.size() + _workerCount - _idleCount;
+ Synchronized s(monitor_);
+ return tasks_.size() + workerCount_ - idleCount_;
}
void add(shared_ptr<Runnable> value);
@@ -81,21 +85,21 @@
void remove(shared_ptr<Runnable> task);
private:
- size_t _workerCount;
- size_t _workerMaxCount;
- size_t _idleCount;
- ThreadManager::STATE _state;
- shared_ptr<ThreadFactory> _threadFactory;
+ size_t workerCount_;
+ size_t workerMaxCount_;
+ size_t idleCount_;
+ ThreadManager::STATE state_;
+ shared_ptr<ThreadFactory> threadFactory_;
friend class ThreadManager::Task;
- std::queue<shared_ptr<Task> > _tasks;
- Monitor _monitor;
- Monitor _workerMonitor;
+ std::queue<shared_ptr<Task> > tasks_;
+ Monitor monitor_;
+ Monitor workerMonitor_;
friend class ThreadManager::Worker;
- std::set<shared_ptr<Thread> > _workers;
- std::set<shared_ptr<Thread> > _deadWorkers;
+ std::set<shared_ptr<Thread> > workers_;
+ std::set<shared_ptr<Thread> > deadWorkers_;
};
class ThreadManager::Task : public Runnable {
@@ -109,22 +113,22 @@
};
Task(shared_ptr<Runnable> runnable) :
- _runnable(runnable),
- _state(WAITING) {}
+ runnable_(runnable),
+ state_(WAITING) {}
~Task() {}
void run() {
- if (_state == EXECUTING) {
- _runnable->run();
- _state = COMPLETE;
+ if (state_ == EXECUTING) {
+ runnable_->run();
+ state_ = COMPLETE;
}
}
private:
- shared_ptr<Runnable> _runnable;
+ shared_ptr<Runnable> runnable_;
friend class ThreadManager::Worker;
- STATE _state;
+ STATE state_;
};
class ThreadManager::Worker: public Runnable {
@@ -138,13 +142,15 @@
public:
Worker(ThreadManager::Impl* manager) :
- _manager(manager),
- _state(UNINITIALIZED),
- _idle(false) {}
+ manager_(manager),
+ state_(UNINITIALIZED),
+ idle_(false) {}
~Worker() {}
- bool isActive() const { return _manager->_workerCount <= _manager->_workerMaxCount; }
+ bool isActive() const {
+ return manager_->workerCount_ <= manager_->workerMaxCount_;
+ }
/**
* Worker entry point
@@ -164,17 +170,17 @@
* since that is what the manager blocks on for worker add/remove
*/
{
- Synchronized s(_manager->_monitor);
- active = _manager->_workerCount < _manager->_workerMaxCount;
+ Synchronized s(manager_->monitor_);
+ active = manager_->workerCount_ < manager_->workerMaxCount_;
if (active) {
- _manager->_workerCount++;
- notifyManager = _manager->_workerCount == _manager->_workerMaxCount;
+ manager_->workerCount_++;
+ notifyManager = manager_->workerCount_ == manager_->workerMaxCount_;
}
}
if (notifyManager) {
- Synchronized s(_manager->_workerMonitor);
- _manager->_workerMonitor.notify();
+ Synchronized s(manager_->workerMonitor_);
+ manager_->workerMonitor_.notify();
notifyManager = false;
}
@@ -191,34 +197,34 @@
* the manager will see it.
*/
{
- Synchronized s(_manager->_monitor);
+ Synchronized s(manager_->monitor_);
active = isActive();
- while (active && _manager->_tasks.empty()) {
- _manager->_idleCount++;
- _idle = true;
- _manager->_monitor.wait();
+ while (active && manager_->tasks_.empty()) {
+ manager_->idleCount_++;
+ idle_ = true;
+ manager_->monitor_.wait();
active = isActive();
- _idle = false;
- _manager->_idleCount--;
+ idle_ = false;
+ manager_->idleCount_--;
}
if (active) {
- if (!_manager->_tasks.empty()) {
- task = _manager->_tasks.front();
- _manager->_tasks.pop();
- if (task->_state == ThreadManager::Task::WAITING) {
- task->_state = ThreadManager::Task::EXECUTING;
+ if (!manager_->tasks_.empty()) {
+ task = manager_->tasks_.front();
+ manager_->tasks_.pop();
+ if (task->state_ == ThreadManager::Task::WAITING) {
+ task->state_ = ThreadManager::Task::EXECUTING;
}
}
} else {
- _idle = true;
- _manager->_workerCount--;
- notifyManager = _manager->_workerCount == _manager->_workerMaxCount;
+ idle_ = true;
+ manager_->workerCount_--;
+ notifyManager = manager_->workerCount_ == manager_->workerMaxCount_;
}
}
if (task != NULL) {
- if (task->_state == ThreadManager::Task::EXECUTING) {
+ if (task->state_ == ThreadManager::Task::EXECUTING) {
try {
task->run();
} catch(...) {
@@ -229,10 +235,10 @@
}
{
- Synchronized s(_manager->_workerMonitor);
- _manager->_deadWorkers.insert(this->thread());
+ Synchronized s(manager_->workerMonitor_);
+ manager_->deadWorkers_.insert(this->thread());
if (notifyManager) {
- _manager->_workerMonitor.notify();
+ manager_->workerMonitor_.notify();
}
}
@@ -240,10 +246,10 @@
}
private:
- ThreadManager::Impl* _manager;
+ ThreadManager::Impl* manager_;
friend class ThreadManager::Impl;
- STATE _state;
- bool _idle;
+ STATE state_;
+ bool idle_;
};
@@ -252,68 +258,68 @@
for (size_t ix = 0; ix < value; ix++) {
class ThreadManager::Worker;
shared_ptr<ThreadManager::Worker> worker = shared_ptr<ThreadManager::Worker>(new ThreadManager::Worker(this));
- newThreads.insert(_threadFactory->newThread(worker));
+ newThreads.insert(threadFactory_->newThread(worker));
}
{
- Synchronized s(_monitor);
- _workerMaxCount+= value;
- _workers.insert(newThreads.begin(), newThreads.end());
+ Synchronized s(monitor_);
+ workerMaxCount_ += value;
+ workers_.insert(newThreads.begin(), newThreads.end());
}
for (std::set<shared_ptr<Thread> >::iterator ix = newThreads.begin(); ix != newThreads.end(); ix++) {
shared_ptr<ThreadManager::Worker> worker = dynamic_pointer_cast<ThreadManager::Worker, Runnable>((*ix)->runnable());
- worker->_state = ThreadManager::Worker::STARTING;
+ worker->state_ = ThreadManager::Worker::STARTING;
(*ix)->start();
}
{
- Synchronized s(_workerMonitor);
- while (_workerCount != _workerMaxCount) {
- _workerMonitor.wait();
+ Synchronized s(workerMonitor_);
+ while (workerCount_ != workerMaxCount_) {
+ workerMonitor_.wait();
}
}
}
void ThreadManager::Impl::start() {
- if (_state == ThreadManager::STOPPED) {
+ if (state_ == ThreadManager::STOPPED) {
return;
}
{
- Synchronized s(_monitor);
- if (_state == ThreadManager::UNINITIALIZED) {
- if (_threadFactory == NULL) {
+ Synchronized s(monitor_);
+ if (state_ == ThreadManager::UNINITIALIZED) {
+ if (threadFactory_ == NULL) {
throw InvalidArgumentException();
}
- _state = ThreadManager::STARTED;
- _monitor.notifyAll();
+ state_ = ThreadManager::STARTED;
+ monitor_.notifyAll();
}
- while (_state == STARTING) {
- _monitor.wait();
+ while (state_ == STARTING) {
+ monitor_.wait();
}
}
}
void ThreadManager::Impl::stop() {
bool doStop = false;
- if (_state == ThreadManager::STOPPED) {
+ if (state_ == ThreadManager::STOPPED) {
return;
}
{
- Synchronized s(_monitor);
- if (!_state != ThreadManager::STOPPING && _state != ThreadManager::STOPPED) {
+ Synchronized s(monitor_);
+ if (!state_ != ThreadManager::STOPPING && state_ != ThreadManager::STOPPED) {
doStop = true;
- _state = ThreadManager::STOPPING;
+ state_ = ThreadManager::STOPPING;
}
}
if (doStop) {
- removeWorker(_workerCount);
- _state = ThreadManager::STOPPING;
+ removeWorker(workerCount_);
+ state_ = ThreadManager::STOPPING;
}
// XXX
@@ -324,56 +330,56 @@
void ThreadManager::Impl::removeWorker(size_t value) {
std::set<shared_ptr<Thread> > removedThreads;
{
- Synchronized s(_monitor);
- if (value > _workerMaxCount) {
+ Synchronized s(monitor_);
+ if (value > workerMaxCount_) {
throw InvalidArgumentException();
}
- _workerMaxCount-= value;
+ workerMaxCount_ -= value;
- if (_idleCount < value) {
- for (size_t ix = 0; ix < _idleCount; ix++) {
- _monitor.notify();
+ if (idleCount_ < value) {
+ for (size_t ix = 0; ix < idleCount_; ix++) {
+ monitor_.notify();
}
} else {
- _monitor.notifyAll();
+ monitor_.notifyAll();
}
}
{
- Synchronized s(_workerMonitor);
+ Synchronized s(workerMonitor_);
- while (_workerCount != _workerMaxCount) {
- _workerMonitor.wait();
+ while (workerCount_ != workerMaxCount_) {
+ workerMonitor_.wait();
}
- for (std::set<shared_ptr<Thread> >::iterator ix = _deadWorkers.begin(); ix != _deadWorkers.end(); ix++) {
- _workers.erase(*ix);
+ for (std::set<shared_ptr<Thread> >::iterator ix = deadWorkers_.begin(); ix != deadWorkers_.end(); ix++) {
+ workers_.erase(*ix);
}
- _deadWorkers.clear();
+ deadWorkers_.clear();
}
}
void ThreadManager::Impl::add(shared_ptr<Runnable> value) {
- Synchronized s(_monitor);
+ Synchronized s(monitor_);
- if (_state != ThreadManager::STARTED) {
+ if (state_ != ThreadManager::STARTED) {
throw IllegalStateException();
}
- _tasks.push(shared_ptr<ThreadManager::Task>(new ThreadManager::Task(value)));
+ tasks_.push(shared_ptr<ThreadManager::Task>(new ThreadManager::Task(value)));
// If idle thread is available notify it, otherwise all worker threads are
// running and will get around to this task in time.
- if (_idleCount > 0) {
- _monitor.notify();
+ if (idleCount_ > 0) {
+ monitor_.notify();
}
}
void ThreadManager::Impl::remove(shared_ptr<Runnable> task) {
- Synchronized s(_monitor);
- if (_state != ThreadManager::STARTED) {
+ Synchronized s(monitor_);
+ if (state_ != ThreadManager::STARTED) {
throw IllegalStateException();
}
}
@@ -382,19 +388,19 @@
public:
SimpleThreadManager(size_t workerCount=4) :
- _workerCount(workerCount),
- _firstTime(true) {
+ workerCount_(workerCount),
+ firstTime_(true) {
}
void start() {
ThreadManager::Impl::start();
- addWorker(_workerCount);
+ addWorker(workerCount_);
}
private:
- const size_t _workerCount;
- bool _firstTime;
- Monitor _monitor;
+ const size_t workerCount_;
+ bool firstTime_;
+ Monitor monitor_;
};