-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathworker_impl.h
47 lines (36 loc) · 1.18 KB
/
worker_impl.h
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
#pragma once
#include <future>
#include <thread>
#include "envoy/api/api.h"
#include "envoy/common/time.h"
#include "envoy/stats/store.h"
#include "nighthawk/common/worker.h"
#include "external/envoy/source/common/common/lock_guard.h"
#include "external/envoy/source/common/common/logger.h"
#include "external/envoy/source/common/common/thread.h"
namespace Nighthawk {
class WorkerImpl : virtual public Worker, public Envoy::Logger::Loggable<Envoy::Logger::Id::main> {
public:
WorkerImpl(Envoy::Api::Api& api, Envoy::ThreadLocal::Instance& tls, Envoy::Stats::Store& store);
~WorkerImpl() override;
void start() override;
void waitForCompletion() override;
void shutdown() override;
protected:
/**
* Perform the actual work on the associated thread initiated by start().
*/
virtual void work() PURE;
Envoy::Thread::ThreadFactory& thread_factory_;
Envoy::Event::DispatcherPtr dispatcher_;
Envoy::ThreadLocal::Instance& tls_;
Envoy::Stats::Store& store_;
Envoy::TimeSource& time_source_;
private:
std::thread thread_;
bool started_{};
std::promise<void> complete_;
std::promise<void> signal_thread_to_exit_;
bool shutdown_{true};
};
} // namespace Nighthawk