Line data Source code
1 : #ifndef THINGER_ASIO_WORKER_THREAD_HPP
2 : #define THINGER_ASIO_WORKER_THREAD_HPP
3 :
4 : #include <thread>
5 : #include "io_worker.hpp"
6 :
7 : namespace thinger::asio{
8 : class worker_thread {
9 : public:
10 : worker_thread(std::string worker_name = "");
11 : virtual ~worker_thread();
12 :
13 : void set_thread_name(std::string worker_name);
14 :
15 : boost::asio::io_context& get_io_context();
16 :
17 : std::thread::id start();
18 : bool stop();
19 : // Once stopped: destroy the pending handlers, keeping the io_context (see io_worker)
20 : void shutdown();
21 : void run(std::function<void()> handler);
22 :
23 : protected:
24 22194 : virtual void async_worker(){};
25 :
26 : private:
27 : std::thread thread_;
28 : std::string worker_name_;
29 : io_worker worker_;
30 : };
31 : }
32 :
33 :
34 : #endif
|