Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6329f83

Browse files
committed
Run clang-format on concurrency/
1 parentb230c76 commit6329f83

File tree

4 files changed

+112
-121
lines changed

4 files changed

+112
-121
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-
namespacenetwork {namespaceconcurrency {
18+
namespacenetwork {
19+
namespaceconcurrency {
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-
structthread_pool_pimpl;
25+
structthread_pool_pimpl;
2526

26-
structthread_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+
structthread_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_poolconst&) = delete;
32-
#endif// !defined(BOOST_NO_CXX11_DELETEED_FUNCTIONS)
33-
thread_pool(thread_pool &&other);
33+
thread_pool(thread_poolconst&) = 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_poolconst&) =delete;
36-
#endif// !defined(BOOST_NO_CXX11_DELETEED_FUNCTIONS)
37-
thread_pool&operator=(thread_pool &&other);
38-
std::size_tconstthread_count()const;
39-
voidpost(std::function<void()> f);
40-
~thread_pool();
41-
voidswap(thread_pool & other);
42-
protected:
43-
thread_pool_pimpl * pimpl;
44-
};
45-
46-
inlinevoidswap(thread_pool & l, thread_pool & r) {
47-
l.swap(r);
48-
}
37+
thread_pool&operator=(thread_poolconst&) =delete;
38+
#endif// !defined(BOOST_NO_CXX11_DELETEED_FUNCTIONS)
39+
thread_pool&operator=(thread_pool && other);
40+
std::size_tconstthread_count()const;
41+
voidpost(std::function<void()> f);
42+
~thread_pool();
43+
voidswap(thread_pool& other);
44+
protected:
45+
thread_pool_pimpl* pimpl;
46+
};
47+
48+
inlinevoidswap(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-
namespacenetwork {namespaceconcurrency {
17-
18-
structthread_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(newboost::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+
namespacenetwork {
17+
namespaceconcurrency {
18+
19+
structthread_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_ENDif (!io_service_.get())
40+
io_service_.reset(new boost::asio::io_service);
41+
if (!sentinel_.get())
42+
sentinel_.reset(newboost::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_pimplconst&) = delete;
51-
thread_pool_pimpl&operator=(thread_pool_pimplconst&) =delete;
52-
#endif// !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
53+
thread_pool_pimpl(thread_pool_pimplconst&) = delete;
54+
thread_pool_pimpl&operator=(thread_pool_pimplconst&) =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_tconstthread_count()const {
59-
return threads_;
60-
}
59+
std::size_tconstthread_count()const {return threads_; }
6160

62-
voidpost(std::function<void()> f) {
63-
io_service_->post(f);
64-
}
61+
voidpost(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-
voidswap(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_tconstthread_pool::thread_count()const {
98-
return pimpl->thread_count();
9974
}
10075

101-
voidthread_pool::post(std::function<void()> f) {
102-
pimpl->post(f);
76+
voidswap(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-
voidthread_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_tconstthread_pool::thread_count()const {
99+
return pimpl->thread_count();
100+
}
101+
102+
voidthread_pool::post(std::function<void()> f) { pimpl->post(f); }
103+
104+
voidthread_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
namespacenetwork {
1312
namespaceutils {
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
structfoo {
2929
foo() : val_(0) {}
30-
voidbar(int val) {
31-
val_ += val;
32-
}
33-
intconstval()const {
34-
return val_;
35-
}
36-
protected:
30+
voidbar(int val) { val_ += val; }
31+
intconstval()const {return val_; }
32+
protected:
3733
int val_;
3834
};
3935

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp