Revert "THRIFT-2729: C++ - .clang-format created and applied"
This reverts commit 74260aa9099c3bb209bc8e524b0e8ba603f62c41.
diff --git a/lib/cpp/test/concurrency/ThreadFactoryTests.h b/lib/cpp/test/concurrency/ThreadFactoryTests.h
old mode 100644
new mode 100755
index d7431a8..2d97337
--- a/lib/cpp/test/concurrency/ThreadFactoryTests.h
+++ b/lib/cpp/test/concurrency/ThreadFactoryTests.h
@@ -27,10 +27,7 @@
#include <iostream>
#include <set>
-namespace apache {
-namespace thrift {
-namespace concurrency {
-namespace test {
+namespace apache { namespace thrift { namespace concurrency { namespace test {
using boost::shared_ptr;
using namespace apache::thrift::concurrency;
@@ -43,14 +40,18 @@
class ThreadFactoryTests {
public:
+
static const double TEST_TOLERANCE;
- class Task : public Runnable {
+ class Task: public Runnable {
public:
+
Task() {}
- void run() { std::cout << "\t\t\tHello World" << std::endl; }
+ void run() {
+ std::cout << "\t\t\tHello World" << std::endl;
+ }
};
/**
@@ -76,17 +77,20 @@
/**
* Reap N threads
*/
- class ReapNTask : public Runnable {
+ class ReapNTask: public Runnable {
- public:
- ReapNTask(Monitor& monitor, int& activeCount) : _monitor(monitor), _count(activeCount) {}
+ 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;
+ //std::cout << "\t\t\tthread count: " << _count << std::endl;
if (_count == 0) {
_monitor.notify();
@@ -98,15 +102,15 @@
int& _count;
};
- bool reapNThreads(int loop = 1, int count = 10) {
+ bool reapNThreads(int loop=1, int count=10) {
- PlatformThreadFactory threadFactory = PlatformThreadFactory();
+ PlatformThreadFactory threadFactory = PlatformThreadFactory();
Monitor* monitor = new Monitor();
- for (int lix = 0; lix < loop; lix++) {
+ for(int lix = 0; lix < loop; lix++) {
- int* activeCount = new int(count);
+ int* activeCount = new int(count);
std::set<shared_ptr<Thread> > threads;
@@ -114,25 +118,20 @@
for (tix = 0; tix < count; tix++) {
try {
- threads.insert(
- threadFactory.newThread(shared_ptr<Runnable>(new ReapNTask(*monitor, *activeCount))));
- } catch (SystemResourceException& e) {
- std::cout << "\t\t\tfailed to create " << lix* count + tix << " thread " << e.what()
- << std::endl;
+ threads.insert(threadFactory.newThread(shared_ptr<Runnable>(new ReapNTask(*monitor, *activeCount))));
+ } catch(SystemResourceException& e) {
+ std::cout << "\t\t\tfailed to create " << lix * count + tix << " thread " << e.what() << std::endl;
throw e;
}
}
tix = 0;
- for (std::set<shared_ptr<Thread> >::const_iterator thread = threads.begin();
- thread != threads.end();
- tix++, ++thread) {
+ for (std::set<shared_ptr<Thread> >::const_iterator thread = threads.begin(); thread != threads.end(); tix++, ++thread) {
try {
(*thread)->start();
- } catch (SystemResourceException& e) {
- std::cout << "\t\t\tfailed to start " << lix* count + tix << " thread " << e.what()
- << std::endl;
+ } catch(SystemResourceException& e) {
+ std::cout << "\t\t\tfailed to start " << lix * count + tix << " thread " << e.what() << std::endl;
throw e;
}
}
@@ -144,7 +143,7 @@
}
}
delete activeCount;
- std::cout << "\t\t\treaped " << lix* count << " threads" << std::endl;
+ std::cout << "\t\t\treaped " << lix * count << " threads" << std::endl;
}
std::cout << "\t\t\tSuccess!" << std::endl;
@@ -152,12 +151,21 @@
return true;
}
- class SynchStartTask : public Runnable {
+ class SynchStartTask: public Runnable {
- public:
- enum STATE { UNINITIALIZED, STARTING, STARTED, STOPPING, STOPPED };
+ public:
- SynchStartTask(Monitor& monitor, volatile STATE& state) : _monitor(monitor), _state(state) {}
+ enum STATE {
+ UNINITIALIZED,
+ STARTING,
+ STARTED,
+ STOPPING,
+ STOPPED
+ };
+
+ SynchStartTask(Monitor& monitor, volatile STATE& state) :
+ _monitor(monitor),
+ _state(state) {}
void run() {
{
@@ -181,9 +189,9 @@
}
}
- private:
+ private:
Monitor& _monitor;
- volatile STATE& _state;
+ volatile STATE& _state;
};
bool synchStartTest() {
@@ -192,10 +200,9 @@
SynchStartTask::STATE state = SynchStartTask::UNINITIALIZED;
- shared_ptr<SynchStartTask> task
- = shared_ptr<SynchStartTask>(new SynchStartTask(monitor, state));
+ shared_ptr<SynchStartTask> task = shared_ptr<SynchStartTask>(new SynchStartTask(monitor, state));
- PlatformThreadFactory threadFactory = PlatformThreadFactory();
+ PlatformThreadFactory threadFactory = PlatformThreadFactory();
shared_ptr<Thread> thread = threadFactory.newThread(task);
@@ -219,8 +226,8 @@
Synchronized s(monitor);
try {
- monitor.wait(100);
- } catch (TimedOutException& e) {
+ monitor.wait(100);
+ } catch(TimedOutException& e) {
}
if (state == SynchStartTask::STARTED) {
@@ -246,7 +253,7 @@
/** See how accurate monitor timeout is. */
- bool monitorTimeoutTest(size_t count = 1000, int64_t timeout = 10) {
+ bool monitorTimeoutTest(size_t count=1000, int64_t timeout=10) {
Monitor monitor;
@@ -256,8 +263,8 @@
{
Synchronized s(monitor);
try {
- monitor.wait(timeout);
- } catch (TimedOutException& e) {
+ monitor.wait(timeout);
+ } catch(TimedOutException& e) {
}
}
}
@@ -266,32 +273,31 @@
double error = ((endTime - startTime) - (count * timeout)) / (double)(count * timeout);
- if (error < 0.0) {
+ if (error < 0.0) {
error *= 1.0;
}
bool success = error < ThreadFactoryTests::TEST_TOLERANCE;
- std::cout << "\t\t\t" << (success ? "Success" : "Failure")
- << "! expected time: " << count * timeout
- << "ms elapsed time: " << endTime - startTime << "ms error%: " << error * 100.0
- << std::endl;
+ std::cout << "\t\t\t" << (success ? "Success" : "Failure") << "! expected time: " << count * timeout << "ms elapsed time: "<< endTime - startTime << "ms error%: " << error * 100.0 << std::endl;
return success;
}
+
class FloodTask : public Runnable {
public:
- FloodTask(const size_t id) : _id(id) {}
- ~FloodTask() {
- if (_id % 1000 == 0) {
+
+ FloodTask(const size_t id) :_id(id) {}
+ ~FloodTask(){
+ if(_id % 1000 == 0) {
std::cout << "\t\tthread " << _id << " done" << std::endl;
}
}
- void run() {
- if (_id % 1000 == 0) {
+ void run(){
+ if(_id % 1000 == 0) {
std::cout << "\t\tthread " << _id << " started" << std::endl;
}
@@ -300,41 +306,42 @@
const size_t _id;
};
- void foo(PlatformThreadFactory* tf) { (void)tf; }
+ void foo(PlatformThreadFactory *tf) {
+ (void) tf;
+ }
- bool floodNTest(size_t loop = 1, size_t count = 100000) {
+ bool floodNTest(size_t loop=1, size_t count=100000) {
bool success = false;
- for (size_t lix = 0; lix < loop; lix++) {
+ for(size_t lix = 0; lix < loop; lix++) {
PlatformThreadFactory threadFactory = PlatformThreadFactory();
threadFactory.setDetached(true);
- for (size_t tix = 0; tix < count; tix++) {
+ for(size_t tix = 0; tix < count; tix++) {
- try {
+ try {
- shared_ptr<FloodTask> task(new FloodTask(lix * count + tix));
+ shared_ptr<FloodTask> task(new FloodTask(lix * count + tix ));
- shared_ptr<Thread> thread = threadFactory.newThread(task);
+ shared_ptr<Thread> thread = threadFactory.newThread(task);
- thread->start();
+ thread->start();
- THRIFT_SLEEP_USEC(1);
+ THRIFT_SLEEP_USEC(1);
- } catch (TException& e) {
+ } catch (TException& e) {
- std::cout << "\t\t\tfailed to start " << lix* count + tix << " thread " << e.what()
- << std::endl;
+ std::cout << "\t\t\tfailed to start " << lix * count + tix << " thread " << e.what() << std::endl;
- return success;
+ return success;
+ }
}
- }
- std::cout << "\t\t\tflooded " << (lix + 1) * count << " threads" << std::endl;
+ std::cout << "\t\t\tflooded " << (lix + 1) * count << " threads" << std::endl;
- success = true;
+ success = true;
}
return success;
@@ -342,7 +349,5 @@
};
const double ThreadFactoryTests::TEST_TOLERANCE = .20;
-}
-}
-}
-} // apache::thrift::concurrency::test
+
+}}}} // apache::thrift::concurrency::test