Debian Codegraph @

LspCpp/include/LibLsp/lsp/ProcessIoService.h

raw
1 #pragma once
2 #include <LibLsp/lsp/asio.h>
3 #include <iostream>
4
5 namespace lsp
6 {
7 class ProcessIoService
8 {
9 public:
10 using IOService = asio::io_context;
11 using Work = asio::executor_work_guard<asio::io_context::executor_type>;
12 using WorkPtr = std::unique_ptr<Work>;
13
14 ProcessIoService()
15 {
16
17 work_ = std::unique_ptr<Work>(new Work(ioService_.get_executor()));
18 auto temp_thread_ = new std::thread([this] { ioService_.run(); });
19 thread_ = std::unique_ptr<std::thread>(temp_thread_);
20 }
21
22 ProcessIoService(ProcessIoService const&) = delete;
23 ProcessIoService& operator=(ProcessIoService const&) = delete;
24
25 asio::io_context& getIOService()
26 {
27 return ioService_;
28 }
29
30 void stop()
31 {
32
33 work_.reset();
34
35 thread_->join();
36 }
37
38 private:
39 IOService ioService_;
40 WorkPtr work_;
41 std::unique_ptr<std::thread> thread_;
42 };
43
44 } // namespace lsp