Skip to content

Commit 7f63e41

Browse files
committed
Merge remote-tracking branch 'deanberris/clang-format-everything'
2 parents 0ed9ead + bec19e1 commit 7f63e41

File tree

223 files changed

+8941
-8814
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

223 files changed

+8941
-8814
lines changed

concurrency/src/network/concurrency/thread_pool.hpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,37 @@
1515
#include <vector>
1616
#include <boost/asio/io_service.hpp>
1717

18-
namespace network { namespace concurrency {
18+
namespace network {
19+
namespace concurrency {
1920

20-
typedef std::shared_ptr<boost::asio::io_service> io_service_ptr;
21-
typedef std::shared_ptr<std::vector<std::thread>> worker_threads_ptr;
22-
typedef std::shared_ptr<boost::asio::io_service::work> sentinel_ptr;
21+
typedef std::shared_ptr<boost::asio::io_service> io_service_ptr;
22+
typedef std::shared_ptr<std::vector<std::thread>> worker_threads_ptr;
23+
typedef std::shared_ptr<boost::asio::io_service::work> sentinel_ptr;
2324

24-
struct thread_pool_pimpl;
25+
struct thread_pool_pimpl;
2526

26-
struct thread_pool {
27-
thread_pool(std::size_t threads = 1,
28-
io_service_ptr io_service = io_service_ptr(),
29-
std::vector<std::thread> worker_threads = std::vector<std::thread>());
27+
struct thread_pool {
28+
thread_pool(
29+
std::size_t threads = 1,
30+
io_service_ptr io_service = io_service_ptr(),
31+
std::vector<std::thread> worker_threads = std::vector<std::thread>());
3032
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
31-
thread_pool(thread_pool const&) = delete;
32-
#endif // !defined(BOOST_NO_CXX11_DELETEED_FUNCTIONS)
33-
thread_pool(thread_pool &&other);
33+
thread_pool(thread_pool const&) = delete;
34+
#endif // !defined(BOOST_NO_CXX11_DELETEED_FUNCTIONS)
35+
thread_pool(thread_pool && other);
3436
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
35-
thread_pool& operator=(thread_pool const&) = delete;
36-
#endif // !defined(BOOST_NO_CXX11_DELETEED_FUNCTIONS)
37-
thread_pool& operator=(thread_pool &&other);
38-
std::size_t const thread_count() const;
39-
void post(std::function<void()> f);
40-
~thread_pool();
41-
void swap(thread_pool & other);
42-
protected:
43-
thread_pool_pimpl * pimpl;
44-
};
45-
46-
inline void swap(thread_pool & l, thread_pool & r) {
47-
l.swap(r);
48-
}
37+
thread_pool& operator=(thread_pool const&) = delete;
38+
#endif // !defined(BOOST_NO_CXX11_DELETEED_FUNCTIONS)
39+
thread_pool& operator=(thread_pool && other);
40+
std::size_t const thread_count() const;
41+
void post(std::function<void()> f);
42+
~thread_pool();
43+
void swap(thread_pool& other);
44+
protected:
45+
thread_pool_pimpl* pimpl;
46+
};
47+
48+
inline void swap(thread_pool& l, thread_pool& r) { l.swap(r); }
4949

5050
} // namespace concurrency
5151
} // namespace network

concurrency/src/network/concurrency/thread_pool.ipp

Lines changed: 79 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -13,102 +13,99 @@
1313
#include <network/concurrency/thread_pool.hpp>
1414
#include <boost/scope_exit.hpp>
1515

16-
namespace network { namespace concurrency {
17-
18-
struct thread_pool_pimpl {
19-
thread_pool_pimpl(std::size_t threads = 1,
20-
io_service_ptr io_service = io_service_ptr(),
21-
std::vector<std::thread> worker_threads = std::vector<std::thread>())
22-
: threads_(threads)
23-
, io_service_(io_service)
24-
, worker_threads_(std::move(worker_threads))
25-
, sentinel_()
26-
{
27-
bool commit = false;
28-
BOOST_SCOPE_EXIT((&commit)(&io_service_)(&worker_threads_)(&sentinel_)) {
29-
if (!commit) {
30-
sentinel_.reset();
31-
io_service_.reset();
32-
for (auto& thread : worker_threads_)
33-
if (thread.joinable()) thread.join();
34-
worker_threads_.clear();
35-
}
36-
} BOOST_SCOPE_EXIT_END
37-
38-
if (!io_service_.get()) io_service_.reset(new boost::asio::io_service);
39-
if (!sentinel_.get())
40-
sentinel_.reset(new boost::asio::io_service::work(*io_service_));
41-
auto local_io_service = io_service_;
42-
for (std::size_t counter = 0; counter < threads_; ++counter)
43-
worker_threads_.emplace_back([local_io_service](){
44-
local_io_service->run();});
45-
46-
commit = true;
16+
namespace network {
17+
namespace concurrency {
18+
19+
struct thread_pool_pimpl {
20+
thread_pool_pimpl(
21+
std::size_t threads = 1,
22+
io_service_ptr io_service = io_service_ptr(),
23+
std::vector<std::thread> worker_threads = std::vector<std::thread>())
24+
: threads_(threads),
25+
io_service_(io_service),
26+
worker_threads_(std::move(worker_threads)),
27+
sentinel_() {
28+
bool commit = false;
29+
BOOST_SCOPE_EXIT((&commit)(&io_service_)(&worker_threads_)(&sentinel_)) {
30+
if (!commit) {
31+
sentinel_.reset();
32+
io_service_.reset();
33+
for (auto& thread : worker_threads_)
34+
if (thread.joinable())
35+
thread.join();
36+
worker_threads_.clear();
37+
}
4738
}
39+
BOOST_SCOPE_EXIT_END if (!io_service_.get())
40+
io_service_.reset(new boost::asio::io_service);
41+
if (!sentinel_.get())
42+
sentinel_.reset(new boost::asio::io_service::work(*io_service_));
43+
auto local_io_service = io_service_;
44+
for (std::size_t counter = 0; counter < threads_; ++counter)
45+
worker_threads_.emplace_back([local_io_service]() {
46+
local_io_service->run();
47+
});
48+
49+
commit = true;
50+
}
4851

4952
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
50-
thread_pool_pimpl(thread_pool_pimpl const &) = delete;
51-
thread_pool_pimpl & operator=(thread_pool_pimpl const &) = delete;
52-
#endif // !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
53+
thread_pool_pimpl(thread_pool_pimpl const&) = delete;
54+
thread_pool_pimpl& operator=(thread_pool_pimpl const&) = delete;
55+
#endif // !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
5356

54-
thread_pool_pimpl(thread_pool_pimpl&& other) {
55-
other.swap(*this);
56-
}
57+
thread_pool_pimpl(thread_pool_pimpl && other) { other.swap(*this); }
5758

58-
std::size_t const thread_count() const {
59-
return threads_;
60-
}
59+
std::size_t const thread_count() const { return threads_; }
6160

62-
void post(std::function<void()> f) {
63-
io_service_->post(f);
64-
}
61+
void post(std::function<void()> f) { io_service_->post(f); }
6562

66-
~thread_pool_pimpl() {
67-
sentinel_.reset();
68-
try {
69-
for (auto& thread : worker_threads_) thread.join();
70-
} catch (...) {
71-
BOOST_ASSERT(false && "A handler was not supposed to throw, but one did.");
72-
std::abort();
73-
}
63+
~thread_pool_pimpl() {
64+
sentinel_.reset();
65+
try {
66+
for (auto& thread : worker_threads_)
67+
thread.join();
7468
}
75-
76-
void swap(thread_pool_pimpl & other) {
77-
using std::swap;
78-
swap(other.threads_, threads_);
79-
swap(other.io_service_, io_service_);
80-
swap(other.worker_threads_, worker_threads_);
81-
swap(other.sentinel_, sentinel_);
69+
catch (...) {
70+
BOOST_ASSERT(false &&
71+
"A handler was not supposed to throw, but one did.");
72+
std::abort();
8273
}
83-
84-
protected:
85-
std::size_t threads_;
86-
io_service_ptr io_service_;
87-
std::vector<std::thread> worker_threads_;
88-
sentinel_ptr sentinel_;
89-
};
90-
91-
thread_pool::thread_pool(std::size_t threads,
92-
io_service_ptr io_service,
93-
std::vector<std::thread> worker_threads)
94-
: pimpl(new (std::nothrow) thread_pool_pimpl(threads, io_service, std::move(worker_threads)))
95-
{}
96-
97-
std::size_t const thread_pool::thread_count() const {
98-
return pimpl->thread_count();
9974
}
10075

101-
void thread_pool::post(std::function<void()> f) {
102-
pimpl->post(f);
76+
void swap(thread_pool_pimpl& other) {
77+
using std::swap;
78+
swap(other.threads_, threads_);
79+
swap(other.io_service_, io_service_);
80+
swap(other.worker_threads_, worker_threads_);
81+
swap(other.sentinel_, sentinel_);
10382
}
10483

105-
void thread_pool::swap(thread_pool & other) {
106-
std::swap(other.pimpl, this->pimpl);
107-
}
84+
protected:
85+
std::size_t threads_;
86+
io_service_ptr io_service_;
87+
std::vector<std::thread> worker_threads_;
88+
sentinel_ptr sentinel_;
89+
};
10890

109-
thread_pool::~thread_pool() {
110-
delete pimpl;
111-
}
91+
thread_pool::thread_pool(std::size_t threads,
92+
io_service_ptr io_service,
93+
std::vector<std::thread> worker_threads)
94+
: pimpl(
95+
new (std::nothrow)
96+
thread_pool_pimpl(threads, io_service, std::move(worker_threads))) {}
97+
98+
std::size_t const thread_pool::thread_count() const {
99+
return pimpl->thread_count();
100+
}
101+
102+
void thread_pool::post(std::function<void()> f) { pimpl->post(f); }
103+
104+
void thread_pool::swap(thread_pool& other) {
105+
std::swap(other.pimpl, this->pimpl);
106+
}
107+
108+
thread_pool::~thread_pool() { delete pimpl; }
112109

113110
} // namespace concurrency
114111
} // namespace network

concurrency/src/network/utils/thread_pool.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
// (See accompanying file LICENSE_1_0.txt or copy at
44
// http://www.boost.org/LICENSE_1_0.txt)
55

6-
76
#ifndef __NETWORK_UTILS_THREAD_POOL_INC__
87
#define __NETWORK_UTILS_THREAD_POOL_INC__
98

109
#include <network/concurrency/thread_pool.hpp>
1110

1211
namespace network {
1312
namespace utils {
14-
typedef ::network::concurrency::thread_pool thread_pool;
15-
} // namespace utils
16-
} // namespace network
17-
13+
typedef ::network::concurrency::thread_pool thread_pool;
14+
} // namespace utils
15+
} // namespace network
1816

19-
#endif // __NETWORK_UTILS_THREAD_POOL_INC__
17+
#endif // __NETWORK_UTILS_THREAD_POOL_INC__

concurrency/test/thread_pool_test.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@ TEST(concurrency_test, default_constructor) {
2727

2828
struct foo {
2929
foo() : val_(0) {}
30-
void bar(int val) {
31-
val_ += val;
32-
}
33-
int const val() const {
34-
return val_;
35-
}
36-
protected:
30+
void bar(int val) { val_ += val; }
31+
int const val() const { return val_; }
32+
protected:
3733
int val_;
3834
};
3935

0 commit comments

Comments
 (0)