From 96d2388ade7af4f23d2c95b92496b79ec0321133 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Thu, 26 Jul 2007 21:10:32 +0000 Subject: [PATCH] Thrift: Cleaned up whitespace. Summary: Replaced a lot of tabs with spaces in the thrift codebase. Removed a lot of trailing whitespace from thrift-generated c++. Added a few things to cleanup.sh. Trac Bug: # Blame Rev: Reviewed By: mcslee Test Plan: Recompiled thrift. Re-thrifted some test .thrifts. Compiled the genrated c++. Ran cleanup.sh. Revert Plan: ok Notes: EImportant: git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665176 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/cpp/src/generate/t_cpp_generator.cc | 30 +++++++------- lib/cpp/cleanup.sh | 4 +- lib/cpp/src/concurrency/Mutex.h | 4 +- lib/cpp/src/concurrency/ThreadManager.cpp | 34 ++++++++-------- lib/cpp/src/concurrency/TimerManager.cpp | 40 +++++++++---------- lib/cpp/src/concurrency/test/Tests.cpp | 8 ++-- .../src/concurrency/test/ThreadFactoryTests.h | 24 +++++------ .../src/concurrency/test/ThreadManagerTests.h | 24 +++++------ .../src/concurrency/test/TimerManagerTests.h | 10 ++--- lib/cpp/src/protocol/TBinaryProtocol.cpp | 4 +- lib/cpp/src/protocol/TBinaryProtocol.h | 14 +++---- lib/cpp/src/protocol/TOneWayProtocol.h | 14 +++---- lib/cpp/src/protocol/TProtocol.h | 28 ++++++------- 13 files changed, 121 insertions(+), 117 deletions(-) diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc index d3d4ccbe..354926d8 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -424,8 +424,7 @@ void t_cpp_generator::generate_struct_definition(ofstream& out, } } } - indent_down(); - indent(out) << "} " << endl; + scope_down(out); } out << @@ -527,7 +526,7 @@ void t_cpp_generator::generate_struct_reader(ofstream& out, // Check for field STOP marker out << - indent() << "if (ftype == facebook::thrift::protocol::T_STOP) { " << endl << + indent() << "if (ftype == facebook::thrift::protocol::T_STOP) {" << endl << indent() << " break;" << endl << indent() << "}" << endl; @@ -820,7 +819,7 @@ void t_cpp_generator::generate_service_interface(t_service* tservice) { } f_header_ << "class " << service_name_ << "If" << extends << " {" << endl << - " public: " << endl; + " public:" << endl; indent_up(); f_header_ << indent() << "virtual ~" << service_name_ << "If() {}" << endl; @@ -832,7 +831,7 @@ void t_cpp_generator::generate_service_interface(t_service* tservice) { } indent_down(); f_header_ << - "}; " << endl << endl; + "};" << endl << endl; } /** @@ -847,7 +846,7 @@ void t_cpp_generator::generate_service_null(t_service* tservice) { } f_header_ << "class " << service_name_ << "Null : virtual public " << service_name_ << "If" << extends << " {" << endl << - " public: " << endl; + " public:" << endl; indent_up(); f_header_ << indent() << "virtual ~" << service_name_ << "Null() {}" << endl; @@ -878,7 +877,7 @@ void t_cpp_generator::generate_service_null(t_service* tservice) { } indent_down(); f_header_ << - "}; " << endl << endl; + "};" << endl << endl; } @@ -908,7 +907,7 @@ void t_cpp_generator::generate_service_multiface(t_service* tservice) { "class " << service_name_ << "Multiface : " << "virtual public " << service_name_ << "If" << extends_multiface << " {" << endl << - " public: " << endl; + " public:" << endl; indent_up(); f_header_ << indent() << service_name_ << "Multiface(" << list_type << "& ifaces) : ifaces_(ifaces) {" << endl; @@ -931,7 +930,7 @@ void t_cpp_generator::generate_service_multiface(t_service* tservice) { f_header_ << indent() << list_type << " ifaces_;" << endl << indent() << service_name_ << "Multiface() {}" << endl << - indent() << "void add(boost::shared_ptr<" << service_name_ << "If> iface) { " << endl; + indent() << "void add(boost::shared_ptr<" << service_name_ << "If> iface) {" << endl; if (!extends.empty()) { f_header_ << indent() << " " << extends << "Multiface::add(iface);" << endl; @@ -1029,7 +1028,7 @@ void t_cpp_generator::generate_service_client(t_service* tservice) { indent_up(); f_header_ << - indent() << service_name_ << "Client(boost::shared_ptr prot) : " << endl; + indent() << service_name_ << "Client(boost::shared_ptr prot) :" << endl; if (extends.empty()) { f_header_ << indent() << " piprot_(prot)," << endl << @@ -1043,7 +1042,7 @@ void t_cpp_generator::generate_service_client(t_service* tservice) { } f_header_ << - indent() << service_name_ << "Client(boost::shared_ptr iprot, boost::shared_ptr oprot) : " << endl; + indent() << service_name_ << "Client(boost::shared_ptr iprot, boost::shared_ptr oprot) :" << endl; if (extends.empty()) { f_header_ << indent() << " piprot_(iprot)," << endl << @@ -1334,7 +1333,7 @@ void t_cpp_generator::generate_service_processor(t_service* tservice) { indent_down(); f_header_ << - " public: " << endl << + " public:" << endl << indent() << service_name_ << "Processor(boost::shared_ptr<" << service_name_ << "If> iface) :" << endl; if (extends.empty()) { f_header_ << @@ -2080,15 +2079,18 @@ string t_cpp_generator::namespace_open(string ns) { return ""; } string result = ""; + string separator = ""; string::size_type loc; while ((loc = ns.find(".")) != string::npos) { + result += separator; result += "namespace "; result += ns.substr(0, loc); - result += " { "; + result += " {"; + separator = " "; ns = ns.substr(loc+1); } if (ns.size() > 0) { - result += "namespace " + ns + " { "; + result += separator + "namespace " + ns + " {"; } return result; } diff --git a/lib/cpp/cleanup.sh b/lib/cpp/cleanup.sh index 71151e9b..687b376c 100755 --- a/lib/cpp/cleanup.sh +++ b/lib/cpp/cleanup.sh @@ -27,4 +27,6 @@ install-sh \ libtool \ ltmain.sh \ Makefile.in \ -missing +missing \ +config.hin~ \ +stamp-h1 diff --git a/lib/cpp/src/concurrency/Mutex.h b/lib/cpp/src/concurrency/Mutex.h index bb2a6066..02accf90 100644 --- a/lib/cpp/src/concurrency/Mutex.h +++ b/lib/cpp/src/concurrency/Mutex.h @@ -66,9 +66,9 @@ class RWGuard { RWGuard(const ReadWriteMutex& value, bool write = 0) : rw_mutex_(value) { if (write) { rw_mutex_.acquireWrite(); - } else { + } else { rw_mutex_.acquireRead(); - } + } } ~RWGuard() { rw_mutex_.release(); diff --git a/lib/cpp/src/concurrency/ThreadManager.cpp b/lib/cpp/src/concurrency/ThreadManager.cpp index 3d87724c..d8b1e8c9 100644 --- a/lib/cpp/src/concurrency/ThreadManager.cpp +++ b/lib/cpp/src/concurrency/ThreadManager.cpp @@ -202,8 +202,8 @@ class ThreadManager::Worker: public Runnable { 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_; } } @@ -227,24 +227,24 @@ class ThreadManager::Worker: public Runnable { */ { Synchronized s(manager_->monitor_); - active = isActive(); + active = isActive(); - while (active && manager_->tasks_.empty()) { + while (active && manager_->tasks_.empty()) { manager_->idleCount_++; idle_ = true; manager_->monitor_.wait(); active = isActive(); idle_ = false; manager_->idleCount_--; - } + } - if (active) { + 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 we have a pending task max and we just dropped below it, wakeup any thread that might be blocked on add. */ @@ -252,22 +252,22 @@ class ThreadManager::Worker: public Runnable { manager_->tasks_.size() == manager_->pendingTaskCountMax_ - 1) { manager_->workerMonitor_.notify(); } - } - } else { - idle_ = true; - manager_->workerCount_--; + } + } else { + idle_ = true; + manager_->workerCount_--; notifyManager = (manager_->workerCount_ == manager_->workerMaxCount_); - } + } } if (task != NULL) { - if (task->state_ == ThreadManager::Task::EXECUTING) { - try { + if (task->state_ == ThreadManager::Task::EXECUTING) { + try { task->run(); } catch(...) { // XXX need to log this - } - } + } + } } } @@ -384,7 +384,7 @@ void ThreadManager::Impl::removeWorker(size_t value) { if (idleCount_ < value) { for (size_t ix = 0; ix < idleCount_; ix++) { - monitor_.notify(); + monitor_.notify(); } } else { monitor_.notifyAll(); diff --git a/lib/cpp/src/concurrency/TimerManager.cpp b/lib/cpp/src/concurrency/TimerManager.cpp index b9e604cc..4f77b2f5 100644 --- a/lib/cpp/src/concurrency/TimerManager.cpp +++ b/lib/cpp/src/concurrency/TimerManager.cpp @@ -74,8 +74,8 @@ class TimerManager::Dispatcher: public Runnable { { Synchronized s(manager_->monitor_); if (manager_->state_ == TimerManager::STARTING) { - manager_->state_ = TimerManager::STARTED; - manager_->monitor_.notifyAll(); + manager_->state_ = TimerManager::STARTED; + manager_->monitor_.notifyAll(); } } @@ -83,32 +83,32 @@ class TimerManager::Dispatcher: public Runnable { std::set > expiredTasks; { Synchronized s(manager_->monitor_); - task_iterator expiredTaskEnd; - int64_t now = Util::currentTime(); - while (manager_->state_ == TimerManager::STARTED && + task_iterator expiredTaskEnd; + int64_t now = Util::currentTime(); + while (manager_->state_ == TimerManager::STARTED && (expiredTaskEnd = manager_->taskMap_.upper_bound(now)) == manager_->taskMap_.begin()) { - int64_t timeout = 0LL; - if (!manager_->taskMap_.empty()) { + int64_t timeout = 0LL; + if (!manager_->taskMap_.empty()) { timeout = manager_->taskMap_.begin()->first - now; - } + } assert((timeout != 0 && manager_->taskCount_ > 0) || (timeout == 0 && manager_->taskCount_ == 0)); try { manager_->monitor_.wait(timeout); } catch (TimedOutException &e) {} - now = Util::currentTime(); - } - - if (manager_->state_ == TimerManager::STARTED) { + now = Util::currentTime(); + } + + if (manager_->state_ == TimerManager::STARTED) { for (task_iterator ix = manager_->taskMap_.begin(); ix != expiredTaskEnd; ix++) { - shared_ptr task = ix->second; + shared_ptr task = ix->second; expiredTasks.insert(task); - if (task->state_ == TimerManager::Task::WAITING) { - task->state_ = TimerManager::Task::EXECUTING; - } + if (task->state_ == TimerManager::Task::WAITING) { + task->state_ = TimerManager::Task::EXECUTING; + } manager_->taskCount_--; - } + } manager_->taskMap_.erase(manager_->taskMap_.begin(), expiredTaskEnd); - } + } } for (std::set >::iterator ix = expiredTasks.begin(); ix != expiredTasks.end(); ix++) { @@ -120,8 +120,8 @@ class TimerManager::Dispatcher: public Runnable { { Synchronized s(manager_->monitor_); if (manager_->state_ == TimerManager::STOPPING) { - manager_->state_ = TimerManager::STOPPED; - manager_->monitor_.notify(); + manager_->state_ = TimerManager::STOPPED; + manager_->monitor_.notify(); } } return; diff --git a/lib/cpp/src/concurrency/test/Tests.cpp b/lib/cpp/src/concurrency/test/Tests.cpp index a1604726..2b7b7f37 100644 --- a/lib/cpp/src/concurrency/test/Tests.cpp +++ b/lib/cpp/src/concurrency/test/Tests.cpp @@ -129,13 +129,13 @@ int main(int argc, char** argv) { for (size_t workerCount = minWorkerCount; workerCount < maxWorkerCount; workerCount*= 2) { - size_t taskCount = workerCount * tasksPerWorker; + size_t taskCount = workerCount * tasksPerWorker; - std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl; + std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl; - ThreadManagerTests threadManagerTests; + ThreadManagerTests threadManagerTests; - threadManagerTests.loadTest(taskCount, delay, workerCount); + threadManagerTests.loadTest(taskCount, delay, workerCount); } } } diff --git a/lib/cpp/src/concurrency/test/ThreadFactoryTests.h b/lib/cpp/src/concurrency/test/ThreadFactoryTests.h index 99bc94ec..0dcf0bb5 100644 --- a/lib/cpp/src/concurrency/test/ThreadFactoryTests.h +++ b/lib/cpp/src/concurrency/test/ThreadFactoryTests.h @@ -162,22 +162,22 @@ public: void run() { { Synchronized s(_monitor); - if (_state == SynchStartTask::STARTING) { - _state = SynchStartTask::STARTED; - _monitor.notify(); - } + if (_state == SynchStartTask::STARTING) { + _state = SynchStartTask::STARTED; + _monitor.notify(); + } } { Synchronized s(_monitor); while (_state == SynchStartTask::STARTED) { - _monitor.wait(); - } + _monitor.wait(); + } - if (_state == SynchStartTask::STOPPING) { + if (_state == SynchStartTask::STOPPING) { _state = SynchStartTask::STOPPED; _monitor.notifyAll(); - } + } } } @@ -208,7 +208,7 @@ public: { Synchronized s(monitor); while (state == SynchStartTask::STARTING) { - monitor.wait(); + monitor.wait(); } } @@ -224,13 +224,13 @@ public: if (state == SynchStartTask::STARTED) { - state = SynchStartTask::STOPPING; + state = SynchStartTask::STOPPING; - monitor.notify(); + monitor.notify(); } while (state == SynchStartTask::STOPPING) { - monitor.wait(); + monitor.wait(); } } diff --git a/lib/cpp/src/concurrency/test/ThreadManagerTests.h b/lib/cpp/src/concurrency/test/ThreadManagerTests.h index a8fdcdac..261ad5e5 100644 --- a/lib/cpp/src/concurrency/test/ThreadManagerTests.h +++ b/lib/cpp/src/concurrency/test/ThreadManagerTests.h @@ -65,14 +65,14 @@ public: { Synchronized s(_monitor); - // std::cout << "Thread " << _count << " completed " << std::endl; + // std::cout << "Thread " << _count << " completed " << std::endl; - _count--; + _count--; - if (_count == 0) { + if (_count == 0) { - _monitor.notify(); - } + _monitor.notify(); + } } } @@ -117,7 +117,7 @@ public: for (std::set >::iterator ix = tasks.begin(); ix != tasks.end(); ix++) { - threadManager->add(*ix); + threadManager->add(*ix); } { @@ -125,7 +125,7 @@ public: while(activeCount > 0) { - monitor.wait(); + monitor.wait(); } } @@ -147,19 +147,19 @@ public: assert(delta > 0); if (task->_startTime < firstTime) { - firstTime = task->_startTime; + firstTime = task->_startTime; } if (task->_endTime > lastTime) { - lastTime = task->_endTime; + lastTime = task->_endTime; } if (delta < minTime) { - minTime = delta; + minTime = delta; } if (delta > maxTime) { - maxTime = delta; + maxTime = delta; } averageTime+= delta; @@ -258,7 +258,7 @@ public: } for (std::set >::iterator ix = tasks.begin(); ix != tasks.end(); ix++) { - threadManager->add(*ix); + threadManager->add(*ix); } if(!(success = (threadManager->totalTaskCount() == pendingTaskMaxCount + workerCount))) { diff --git a/lib/cpp/src/concurrency/test/TimerManagerTests.h b/lib/cpp/src/concurrency/test/TimerManagerTests.h index e7948e43..bd959cdd 100644 --- a/lib/cpp/src/concurrency/test/TimerManagerTests.h +++ b/lib/cpp/src/concurrency/test/TimerManagerTests.h @@ -54,7 +54,7 @@ class TimerManagerTests { float error = delta / _timeout; if(error < ERROR) { - _success = true; + _success = true; } _done = true; @@ -62,7 +62,7 @@ class TimerManagerTests { std::cout << "\t\t\tTimerManagerTests::Task[" << this << "] done" << std::endl; //debug {Synchronized s(_monitor); - _monitor.notifyAll(); + _monitor.notifyAll(); } } @@ -99,11 +99,11 @@ class TimerManagerTests { { Synchronized s(_monitor); - timerManager.add(orphanTask, 10 * timeout); + timerManager.add(orphanTask, 10 * timeout); - timerManager.add(task, timeout); + timerManager.add(task, timeout); - _monitor.wait(); + _monitor.wait(); } assert(task->_done); diff --git a/lib/cpp/src/protocol/TBinaryProtocol.cpp b/lib/cpp/src/protocol/TBinaryProtocol.cpp index 69458513..30bbde62 100644 --- a/lib/cpp/src/protocol/TBinaryProtocol.cpp +++ b/lib/cpp/src/protocol/TBinaryProtocol.cpp @@ -193,8 +193,8 @@ uint32_t TBinaryProtocol::writeString(const string& str) { */ uint32_t TBinaryProtocol::readMessageBegin(std::string& name, - TMessageType& messageType, - int32_t& seqid) { + TMessageType& messageType, + int32_t& seqid) { uint32_t result = 0; int32_t sz; result += readI32(sz); diff --git a/lib/cpp/src/protocol/TBinaryProtocol.h b/lib/cpp/src/protocol/TBinaryProtocol.h index 5047e02d..01f7c3b2 100644 --- a/lib/cpp/src/protocol/TBinaryProtocol.h +++ b/lib/cpp/src/protocol/TBinaryProtocol.h @@ -127,8 +127,8 @@ class TBinaryProtocol : public TProtocol { uint32_t readMessageBegin(std::string& name, - TMessageType& messageType, - int32_t& seqid); + TMessageType& messageType, + int32_t& seqid); uint32_t readMessageEnd(); @@ -137,14 +137,14 @@ class TBinaryProtocol : public TProtocol { uint32_t readStructEnd(); uint32_t readFieldBegin(std::string& name, - TType& fieldType, - int16_t& fieldId); + TType& fieldType, + int16_t& fieldId); uint32_t readFieldEnd(); uint32_t readMapBegin(TType& keyType, - TType& valType, - uint32_t& size); + TType& valType, + uint32_t& size); uint32_t readMapEnd(); @@ -154,7 +154,7 @@ class TBinaryProtocol : public TProtocol { uint32_t readListEnd(); uint32_t readSetBegin(TType& elemType, - uint32_t& size); + uint32_t& size); uint32_t readSetEnd(); diff --git a/lib/cpp/src/protocol/TOneWayProtocol.h b/lib/cpp/src/protocol/TOneWayProtocol.h index c9280589..635744c8 100644 --- a/lib/cpp/src/protocol/TOneWayProtocol.h +++ b/lib/cpp/src/protocol/TOneWayProtocol.h @@ -35,8 +35,8 @@ class TWriteOnlyProtocol : public TProtocol { */ uint32_t readMessageBegin(std::string& name, - TMessageType& messageType, - int32_t& seqid) { + TMessageType& messageType, + int32_t& seqid) { throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, subclass_ + " does not support reading (yet)."); } @@ -57,8 +57,8 @@ class TWriteOnlyProtocol : public TProtocol { } uint32_t readFieldBegin(std::string& name, - TType& fieldType, - int16_t& fieldId) { + TType& fieldType, + int16_t& fieldId) { throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, subclass_ + " does not support reading (yet)."); } @@ -69,8 +69,8 @@ class TWriteOnlyProtocol : public TProtocol { } uint32_t readMapBegin(TType& keyType, - TType& valType, - uint32_t& size) { + TType& valType, + uint32_t& size) { throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, subclass_ + " does not support reading (yet)."); } @@ -92,7 +92,7 @@ class TWriteOnlyProtocol : public TProtocol { } uint32_t readSetBegin(TType& elemType, - uint32_t& size) { + uint32_t& size) { throw TProtocolException(TProtocolException::NOT_IMPLEMENTED, subclass_ + " does not support reading (yet)."); } diff --git a/lib/cpp/src/protocol/TProtocol.h b/lib/cpp/src/protocol/TProtocol.h index a7560ca5..7fa3de85 100644 --- a/lib/cpp/src/protocol/TProtocol.h +++ b/lib/cpp/src/protocol/TProtocol.h @@ -122,26 +122,26 @@ class TProtocol { virtual uint32_t writeStructEnd() = 0; virtual uint32_t writeFieldBegin(const std::string& name, - const TType fieldType, - const int16_t fieldId) = 0; + const TType fieldType, + const int16_t fieldId) = 0; virtual uint32_t writeFieldEnd() = 0; virtual uint32_t writeFieldStop() = 0; virtual uint32_t writeMapBegin(const TType keyType, - const TType valType, - const uint32_t size) = 0; + const TType valType, + const uint32_t size) = 0; virtual uint32_t writeMapEnd() = 0; virtual uint32_t writeListBegin(const TType elemType, - const uint32_t size) = 0; + const uint32_t size) = 0; virtual uint32_t writeListEnd() = 0; virtual uint32_t writeSetBegin(const TType elemType, - const uint32_t size) = 0; + const uint32_t size) = 0; virtual uint32_t writeSetEnd() = 0; @@ -164,8 +164,8 @@ class TProtocol { */ virtual uint32_t readMessageBegin(std::string& name, - TMessageType& messageType, - int32_t& seqid) = 0; + TMessageType& messageType, + int32_t& seqid) = 0; virtual uint32_t readMessageEnd() = 0; @@ -174,24 +174,24 @@ class TProtocol { virtual uint32_t readStructEnd() = 0; virtual uint32_t readFieldBegin(std::string& name, - TType& fieldType, - int16_t& fieldId) = 0; + TType& fieldType, + int16_t& fieldId) = 0; virtual uint32_t readFieldEnd() = 0; virtual uint32_t readMapBegin(TType& keyType, - TType& valType, - uint32_t& size) = 0; + TType& valType, + uint32_t& size) = 0; virtual uint32_t readMapEnd() = 0; virtual uint32_t readListBegin(TType& elemType, - uint32_t& size) = 0; + uint32_t& size) = 0; virtual uint32_t readListEnd() = 0; virtual uint32_t readSetBegin(TType& elemType, - uint32_t& size) = 0; + uint32_t& size) = 0; virtual uint32_t readSetEnd() = 0; -- 2.17.1