Thrift: standardize coding style

Summary: Standardize indentation, spacing, #defines etc.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664784 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/test/Tests.cc b/lib/cpp/src/concurrency/test/Tests.cc
index 5c4dd24..77e5551 100644
--- a/lib/cpp/src/concurrency/test/Tests.cc
+++ b/lib/cpp/src/concurrency/test/Tests.cc
@@ -14,13 +14,13 @@
 
   args[0] = "all";
 
-  for(int ix = 1; ix < argc; ix++) {
+  for (int ix = 1; ix < argc; ix++) {
     args[ix - 1] = std::string(argv[ix]);
   }
 
   bool runAll = args[0].compare("all") == 0;
 
-  if(runAll || args[0].compare("thread-factory") == 0) {
+  if (runAll || args[0].compare("thread-factory") == 0) {
 
     ThreadFactoryTests threadFactoryTests;
     
@@ -41,7 +41,7 @@
     assert(threadFactoryTests.monitorTimeoutTest());
   }
 
-  if(runAll || args[0].compare("util") == 0) {
+  if (runAll || args[0].compare("util") == 0) {
 
     std::cout << "Util tests..." << std::endl;
 
@@ -56,7 +56,7 @@
     time01 = time00;
     size_t count = 0;
     
-    while(time01 < time00 + 10) {
+    while (time01 < time00 + 10) {
       count++;
       time01 = Util::currentTime();
     }
@@ -65,7 +65,7 @@
   }
 
 
-  if(runAll || args[0].compare("timer-manager") == 0) {
+  if (runAll || args[0].compare("timer-manager") == 0) {
 
     std::cout << "TimerManager tests..." << std::endl;
 
@@ -76,7 +76,7 @@
     assert(timerManagerTests.test00());
   }
 
-  if(runAll || args[0].compare("thread-manager") == 0) {
+  if (runAll || args[0].compare("thread-manager") == 0) {
 
     std::cout << "ThreadManager tests..." << std::endl;
 
@@ -96,7 +96,7 @@
     }
   }
 
-  if(runAll || args[0].compare("thread-manager-benchmark") == 0) {
+  if (runAll || args[0].compare("thread-manager-benchmark") == 0) {
 
     std::cout << "ThreadManager benchmark tests..." << std::endl;
 
@@ -110,7 +110,7 @@
 
       long long delay = 10LL;
 
-      for(size_t workerCount = minWorkerCount; workerCount < maxWorkerCount; workerCount*= 2) {
+      for (size_t workerCount = minWorkerCount; workerCount < maxWorkerCount; workerCount*= 2) {
 
 	size_t taskCount = workerCount * tasksPerWorker;
 
diff --git a/lib/cpp/src/concurrency/test/ThreadFactoryTests.h b/lib/cpp/src/concurrency/test/ThreadFactoryTests.h
index 26e4c28..34b03d9 100644
--- a/lib/cpp/src/concurrency/test/ThreadFactoryTests.h
+++ b/lib/cpp/src/concurrency/test/ThreadFactoryTests.h
@@ -11,11 +11,12 @@
 
 using namespace facebook::thrift::concurrency;
 
-/** ThreadManagerTests class 
-
-    @author marc
-    @version $Id:$ */
-
+/**
+ * ThreadManagerTests class 
+ *
+ * @author marc
+ * @version $Id:$
+ */
 class ThreadFactoryTests {
 
 public:
@@ -33,8 +34,9 @@
     }
   };
 
-  /** Hello world test */
-
+  /**
+   * Hello world test
+   */
   bool helloWorldTest() {
 
     PosixThreadFactory threadFactory =  PosixThreadFactory();
@@ -52,28 +54,26 @@
     return true;
   }
 
-  /** Reap N threads  */
-
- class ReapNTask: public Runnable {
-
-  public:
-
-  ReapNTask(Monitor& monitor, int& activeCount) :
-    _monitor(monitor),
-      _count(activeCount) {
-      }
+  /**
+   * Reap N threads
+   */
+  class ReapNTask: public Runnable {
     
+   public:
+    
+    ReapNTask(Monitor& monitor, int& activeCount) :
+      _monitor(monitor),
+      _count(activeCount) {}
+      
     void run() {
-
-      {Synchronized s(_monitor);
-
-	_count--;
-
-	//std::cout << "\t\t\tthread count: " << _count << std::endl;
-
-	if(_count == 0) {
-	  _monitor.notify();
-	}
+      Synchronized s(_monitor);
+      
+      _count--;
+      
+      //std::cout << "\t\t\tthread count: " << _count << std::endl;
+      
+      if (_count == 0) {
+        _monitor.notify();
       }
     }
 
@@ -92,25 +92,24 @@
 
     std::set<shared_ptr<Thread> > threads;
 
-    for(int ix = 0; ix < count; ix++) {
+    for (int ix = 0; ix < count; ix++) {
       threads.insert(threadFactory.newThread(shared_ptr<Runnable>(new ReapNTask(*monitor, *activeCount))));
     }
 
-    for(std::set<shared_ptr<Thread> >::const_iterator thread = threads.begin(); thread != threads.end(); thread++) {
+    for (std::set<shared_ptr<Thread> >::const_iterator thread = threads.begin(); thread != threads.end(); thread++) {
 
       (*thread)->start();
     }
 
 
-    {Synchronized s(*monitor);
-
-      while(*activeCount > 0) {
+    {
+      Synchronized s(*monitor);
+      while (*activeCount > 0) {
 	monitor->wait(1000);
       }
     }
 
-    for(std::set<shared_ptr<Thread> >::const_iterator thread = threads.begin(); thread != threads.end(); thread++) {
-
+    for (std::set<shared_ptr<Thread> >::const_iterator thread = threads.begin(); thread != threads.end(); thread++) {
       threads.erase(*thread);
     }
 
@@ -119,10 +118,10 @@
     return true;
   }
 
- class SynchStartTask: public Runnable {
+  class SynchStartTask: public Runnable {
 
-  public:
-
+   public:
+    
     enum STATE {
       UNINITIALIZED,
       STARTING,
@@ -131,38 +130,33 @@
       STOPPED
     };
 
-  SynchStartTask(Monitor& monitor,
-		 volatile  STATE& state) :
-    _monitor(monitor),
-    _state(state) {
-    }
+    SynchStartTask(Monitor& monitor, volatile  STATE& state) :
+      _monitor(monitor),
+      _state(state) {}
 
     void run() {
-
-      {Synchronized s(_monitor);
-
-	if(_state == SynchStartTask::STARTING) {
+      {
+        Synchronized s(_monitor);
+	if (_state == SynchStartTask::STARTING) {
 	  _state = SynchStartTask::STARTED;
 	  _monitor.notify();
 	}
       }
 
-      {Synchronized s(_monitor);
-	
-	while(_state == SynchStartTask::STARTED) {
+      {
+        Synchronized s(_monitor);
+        while (_state == SynchStartTask::STARTED) {
 	  _monitor.wait();
 	}
 
-	if(_state == SynchStartTask::STOPPING) {
-	  
-	  _state = SynchStartTask::STOPPED;
-	  
-	  _monitor.notifyAll();
+	if (_state == SynchStartTask::STOPPING) {
+          _state = SynchStartTask::STOPPED;
+          _monitor.notifyAll();
 	}
       }
     }
 
-    private:
+   private:
     Monitor& _monitor;
     volatile  STATE& _state;
   };
@@ -179,34 +173,35 @@
 
     shared_ptr<Thread> thread = threadFactory.newThread(task);
 
-    if(state == SynchStartTask::UNINITIALIZED) {
+    if (state == SynchStartTask::UNINITIALIZED) {
 
       state = SynchStartTask::STARTING;
 
       thread->start();
     }
 
-    {Synchronized s(monitor);
-      
-      while(state == SynchStartTask::STARTING) {
+    {
+      Synchronized s(monitor);
+      while (state == SynchStartTask::STARTING) {
 	monitor.wait();
       }
     }
 
     assert(state != SynchStartTask::STARTING);
 
-    {Synchronized s(monitor);
+    {
+      Synchronized s(monitor);
 
       monitor.wait(100);
 
-      if(state == SynchStartTask::STARTED) {
+      if (state == SynchStartTask::STARTED) {
 
 	state = SynchStartTask::STOPPING;
 
 	monitor.notify();
       }
       
-      while(state == SynchStartTask::STOPPING) {
+      while (state == SynchStartTask::STOPPING) {
 	monitor.wait();
       }
     }
@@ -228,8 +223,9 @@
 
     long long startTime = Util::currentTime();
 
-    for(size_t ix = 0; ix < count; ix++) {
-      {Synchronized s(monitor);
+    for (size_t ix = 0; ix < count; ix++) {
+      {
+        Synchronized s(monitor);
 	monitor.wait(timeout);
       }
     }
@@ -238,7 +234,7 @@
 
     double error = ((endTime - startTime) - (count * timeout)) / (double)(count * timeout);
 
-    if(error < 0.0)  {
+    if (error < 0.0)  {
 
       error *= 1.0;
     }
diff --git a/lib/cpp/src/concurrency/test/ThreadManagerTests.h b/lib/cpp/src/concurrency/test/ThreadManagerTests.h
index 7e74aac..e174343 100644
--- a/lib/cpp/src/concurrency/test/ThreadManagerTests.h
+++ b/lib/cpp/src/concurrency/test/ThreadManagerTests.h
@@ -14,11 +14,12 @@
 
 using namespace facebook::thrift::concurrency;
 
-/** ThreadManagerTests class 
-
-    @author marc
-    @version $Id:$ */
-
+/**
+ * ThreadManagerTests class 
+ *
+ * @author marc
+ * @version $Id:$
+ */
 class ThreadManagerTests {
 
 public:
@@ -39,8 +40,8 @@
 
       _startTime = Util::currentTime();
 
-      {Synchronized s(_sleep);
-
+      {
+        Synchronized s(_sleep);
 
 	_sleep.wait(_timeout);
       }
@@ -49,13 +50,14 @@
 
       _done = true;
       
-      {Synchronized s(_monitor);
+      {
+        Synchronized s(_monitor);
 
 	// std::cout << "Thread " << _count << " completed " << std::endl;
       
 	_count--;
 
-	if(_count == 0) {
+	if (_count == 0) {
 	  
 	  _monitor.notify();
 	}
@@ -71,9 +73,11 @@
     Monitor _sleep;
   };
 
-  /** Dispatch count tasks, each of which blocks for timeout milliseconds then completes.
-      Verify that all tasks completed and that thread manager cleans up properly on delete. */
-
+  /**
+   * Dispatch count tasks, each of which blocks for timeout milliseconds then
+   * completes. Verify that all tasks completed and that thread manager cleans
+   * up properly on delete.
+   */
   bool loadTest(size_t count=100, long long timeout=100LL, size_t workerCount=4) {
 
     Monitor monitor;
@@ -92,20 +96,21 @@
       
     std::set<shared_ptr<ThreadManagerTests::Task> > tasks;
 
-    for(size_t ix = 0; ix < count; ix++) {
+    for (size_t ix = 0; ix < count; ix++) {
 
       tasks.insert(shared_ptr<ThreadManagerTests::Task>(new ThreadManagerTests::Task(monitor, activeCount, timeout)));
     }
 
     long long time00 = Util::currentTime();
 
-    for(std::set<shared_ptr<ThreadManagerTests::Task> >::iterator ix = tasks.begin(); ix != tasks.end(); ix++) {
+    for (std::set<shared_ptr<ThreadManagerTests::Task> >::iterator ix = tasks.begin(); ix != tasks.end(); ix++) {
 
 	threadManager->add(*ix);
     }
 
-    {Synchronized s(monitor);
-      
+    {
+      Synchronized s(monitor);
+
       while(activeCount > 0) {
 	
 	monitor.wait();
@@ -121,7 +126,7 @@
     long long minTime = 9223372036854775807LL;
     long long maxTime = 0;
 
-    for(std::set<shared_ptr<ThreadManagerTests::Task> >::iterator ix = tasks.begin(); ix != tasks.end(); ix++) {
+    for (std::set<shared_ptr<ThreadManagerTests::Task> >::iterator ix = tasks.begin(); ix != tasks.end(); ix++) {
       
       shared_ptr<ThreadManagerTests::Task> task = *ix;
 
@@ -129,19 +134,19 @@
 
       assert(delta > 0);
 
-      if(task->_startTime < firstTime) {
+      if (task->_startTime < firstTime) {
 	firstTime = task->_startTime;
       }
 
-      if(task->_endTime > lastTime) {
+      if (task->_endTime > lastTime) {
 	lastTime = task->_endTime;
       }
 
-      if(delta < minTime) {
+      if (delta < minTime) {
 	minTime = delta;
       }
 
-      if(delta > maxTime) {
+      if (delta > maxTime) {
 	maxTime = delta;
       }
 
@@ -156,7 +161,7 @@
 
     double error = ((time01 - time00) - expectedTime) / expectedTime;
 
-    if(error < 0) {
+    if (error < 0) {
       error*= -1.0;
     }
 
diff --git a/lib/cpp/src/concurrency/test/TimerManagerTests.h b/lib/cpp/src/concurrency/test/TimerManagerTests.h
index fe56d31..faab733 100644
--- a/lib/cpp/src/concurrency/test/TimerManagerTests.h
+++ b/lib/cpp/src/concurrency/test/TimerManagerTests.h
@@ -10,29 +10,29 @@
 
 using namespace facebook::thrift::concurrency;
 
-/** ThreadManagerTests class 
-
-    @author marc
-    @version $Id:$ */
-
+/**
+ * ThreadManagerTests class 
+ *
+ * @author marc
+ * @version $Id:$
+ */
 class TimerManagerTests {
 
  public:
 
   static const double ERROR;
 
- class Task: public Runnable {
-
-  public:
+  class Task: public Runnable {
+   public:
     
     Task(Monitor& monitor, long long timeout) : 
       _timeout(timeout),
       _startTime(Util::currentTime()),
       _monitor(monitor),
       _success(false),
-    _done(false) {}
+      _done(false) {}
 
-   ~Task() {std::cerr << this << std::endl;}
+    ~Task() { std::cerr << this << std::endl; }
 
     void run() {
 
@@ -58,9 +58,7 @@
       {Synchronized s(_monitor);
 	_monitor.notifyAll();
       }
-    }
-
-    
+    }  
 
     long long _timeout;
     long long _startTime;
@@ -70,10 +68,12 @@
     bool _done;
   };
 
-  /** This test creates two tasks and waits for the first to expire within 10% of the expected expiration time.  It then verifies that
-      the timer manager properly clean up itself and the remaining orphaned timeout task when the manager goes out of scope and its 
-      destructor is called. */
-
+  /**
+   * This test creates two tasks and waits for the first to expire within 10%
+   * of the expected expiration time. It then verifies that the timer manager
+   * properly clean up itself and the remaining orphaned timeout task when the
+   * manager goes out of scope and its destructor is called.
+   */
   bool test00(long long timeout=1000LL) {
 
     shared_ptr<TimerManagerTests::Task> orphanTask = shared_ptr<TimerManagerTests::Task>(new TimerManagerTests::Task(_monitor, 10 * timeout));
@@ -90,7 +90,8 @@
 
       shared_ptr<TimerManagerTests::Task> task = shared_ptr<TimerManagerTests::Task>(new TimerManagerTests::Task(_monitor, timeout));
 
-      {Synchronized s(_monitor);
+      {
+        Synchronized s(_monitor);
 
 	timerManager.add(orphanTask, 10 * timeout);