THRIFT-2729: C++ - .clang-format created and applied
Client: C++
Patch: Konrad Grochowski
make style command added
diff --git a/lib/cpp/test/concurrency/ThreadFactoryTests.h b/lib/cpp/test/concurrency/ThreadFactoryTests.h
old mode 100755
new mode 100644
index 2d97337..d7431a8
--- a/lib/cpp/test/concurrency/ThreadFactoryTests.h
+++ b/lib/cpp/test/concurrency/ThreadFactoryTests.h
@@ -27,7 +27,10 @@
#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;
@@ -40,18 +43,14 @@
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; }
};
/**
@@ -77,20 +76,17 @@
/**
* 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();
@@ -102,15 +98,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;
@@ -118,20 +114,25 @@
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;
}
}
@@ -143,7 +144,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;
@@ -151,21 +152,12 @@
return true;
}
- class SynchStartTask: public Runnable {
+ class SynchStartTask : public Runnable {
- public:
+ public:
+ enum STATE { UNINITIALIZED, STARTING, STARTED, STOPPING, STOPPED };
- enum STATE {
- UNINITIALIZED,
- STARTING,
- STARTED,
- STOPPING,
- STOPPED
- };
-
- SynchStartTask(Monitor& monitor, volatile STATE& state) :
- _monitor(monitor),
- _state(state) {}
+ SynchStartTask(Monitor& monitor, volatile STATE& state) : _monitor(monitor), _state(state) {}
void run() {
{
@@ -189,9 +181,9 @@
}
}
- private:
+ private:
Monitor& _monitor;
- volatile STATE& _state;
+ volatile STATE& _state;
};
bool synchStartTest() {
@@ -200,9 +192,10 @@
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);
@@ -226,8 +219,8 @@
Synchronized s(monitor);
try {
- monitor.wait(100);
- } catch(TimedOutException& e) {
+ monitor.wait(100);
+ } catch (TimedOutException& e) {
}
if (state == SynchStartTask::STARTED) {
@@ -253,7 +246,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;
@@ -263,8 +256,8 @@
{
Synchronized s(monitor);
try {
- monitor.wait(timeout);
- } catch(TimedOutException& e) {
+ monitor.wait(timeout);
+ } catch (TimedOutException& e) {
}
}
}
@@ -273,31 +266,32 @@
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;
}
@@ -306,42 +300,41 @@
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;
@@ -349,5 +342,7 @@
};
const double ThreadFactoryTests::TEST_TOLERANCE = .20;
-
-}}}} // apache::thrift::concurrency::test
+}
+}
+}
+} // apache::thrift::concurrency::test