-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathasync_service.cpp
More file actions
59 lines (49 loc) · 941 Bytes
/
Copy pathasync_service.cpp
File metadata and controls
59 lines (49 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bitcoin/async_service.hpp>
namespace libbitcoin {
async_service::async_service()
: work_(nullptr)
{
}
async_service::async_service(size_t number_threads)
: work_(nullptr)
{
for (size_t i = 0; i < number_threads; ++i)
spawn();
}
async_service::~async_service()
{
delete work_;
}
void async_service::spawn()
{
if (!work_)
work_ = new io_service::work(ios_);
threads_.push_back(std::thread([this] { ios_.run(); }));
}
void async_service::stop()
{
ios_.stop();
}
void async_service::shutdown()
{
delete work_;
work_ = nullptr;
}
void async_service::join()
{
for (std::thread& t: threads_)
t.join();
}
io_service& async_service::get_service()
{
return ios_;
}
const io_service& async_service::get_service() const
{
return ios_;
}
async_strand::async_strand(async_service& service)
: ios_(service.get_service()), strand_(ios_)
{
}
} // namespace libbitcoin