24
24
#include " base/strings/string_number_conversions.h"
25
25
#include " base/strings/string_util.h"
26
26
#include " base/threading/asio_event_dispatcher.h"
27
- #include " base/threading/simple_thread.h"
28
27
#include " base/win/scoped_com_initializer.h"
29
28
#include " base/win/security_helpers.h"
30
29
31
30
#include < sddl.h>
32
31
32
+ #include < QThread>
33
+
33
34
namespace base {
34
35
35
36
namespace {
@@ -82,15 +83,14 @@ std::string serviceStateToString(DWORD state)
82
83
}
83
84
}
84
85
85
- class ServiceThread
86
+ class ServiceThread final : public QThread
86
87
{
87
88
public:
88
89
ServiceThread (Service* service);
89
90
~ServiceThread ();
90
91
91
92
using EventCallback = std::function<void ()>;
92
93
93
- void start ();
94
94
void setStatus (DWORD status);
95
95
void doEvent (EventCallback callback, bool quit = false );
96
96
@@ -115,15 +115,14 @@ class ServiceThread
115
115
bool event_processed = false ;
116
116
117
117
protected:
118
- // SimpleThread implementation.
119
- void run ();
118
+ // QThread implementation.
119
+ void run () final ;
120
120
121
121
private:
122
122
static void WINAPI serviceMain (DWORD argc, LPWSTR* argv);
123
123
static DWORD WINAPI serviceControlHandler (
124
124
DWORD control_code, DWORD event_type, LPVOID event_data, LPVOID context);
125
125
126
- SimpleThread thread_;
127
126
Service* service_;
128
127
std::shared_ptr<TaskRunner> task_runner_;
129
128
@@ -162,18 +161,13 @@ ServiceThread::~ServiceThread()
162
161
163
162
setStatus (SERVICE_STOPPED);
164
163
165
- thread_.stop ();
164
+ terminate ();
165
+ wait ();
166
166
167
167
DCHECK (self);
168
168
self = nullptr ;
169
169
}
170
170
171
- // --------------------------------------------------------------------------------------------------
172
- void ServiceThread::start ()
173
- {
174
- thread_.start (std::bind (&ServiceThread::run, this ));
175
- }
176
-
177
171
// --------------------------------------------------------------------------------------------------
178
172
void ServiceThread::setStatus (DWORD status)
179
173
{
0 commit comments