-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathioservicehandler.h
More file actions
40 lines (36 loc) · 1.09 KB
/
Copy pathioservicehandler.h
File metadata and controls
40 lines (36 loc) · 1.09 KB
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
//Class to handle the main io_Service for the program and
//provide the main threads that will be calling run
#ifndef IOSERVICEHANDLER_H
#define IOSERVICEHANDLER_H
#include <algorithm>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <iostream>
#include <memory>
#include <set>
#include <thread>
#include "globals.h"
class IOServiceHandler
{
// Shared pointer to io_service. Other classes may need to access, hence shared.
std::shared_ptr<boost::asio::io_service> ptrIo;
// Vector to hold threads calling io_service.run();
std::vector<std::thread> threadPool;
// Number of threads to call run();
std::size_t numThreads;
// Work to keep io_service running
std::unique_ptr<boost::asio::io_service::work> work;
//calls io service run
void runThread();
public:
IOServiceHandler(std::size_t);
// Start thread pool
void start();
// Stop thread pool
void stop();
// get shared ptr to io_service
std::shared_ptr<boost::asio::io_service> getIoService();
// Destructor... calls stop()
~IOServiceHandler();
};
#endif // IOSERVICEHANDLER_H