Skip to content

Commit d727a74

Browse files
committed
Using QThread.
1 parent eed6c51 commit d727a74

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

source/base/service_win.cc

+7-13
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
#include "base/strings/string_number_conversions.h"
2525
#include "base/strings/string_util.h"
2626
#include "base/threading/asio_event_dispatcher.h"
27-
#include "base/threading/simple_thread.h"
2827
#include "base/win/scoped_com_initializer.h"
2928
#include "base/win/security_helpers.h"
3029

3130
#include <sddl.h>
3231

32+
#include <QThread>
33+
3334
namespace base {
3435

3536
namespace {
@@ -82,15 +83,14 @@ std::string serviceStateToString(DWORD state)
8283
}
8384
}
8485

85-
class ServiceThread
86+
class ServiceThread final : public QThread
8687
{
8788
public:
8889
ServiceThread(Service* service);
8990
~ServiceThread();
9091

9192
using EventCallback = std::function<void()>;
9293

93-
void start();
9494
void setStatus(DWORD status);
9595
void doEvent(EventCallback callback, bool quit = false);
9696

@@ -115,15 +115,14 @@ class ServiceThread
115115
bool event_processed = false;
116116

117117
protected:
118-
// SimpleThread implementation.
119-
void run();
118+
// QThread implementation.
119+
void run() final;
120120

121121
private:
122122
static void WINAPI serviceMain(DWORD argc, LPWSTR* argv);
123123
static DWORD WINAPI serviceControlHandler(
124124
DWORD control_code, DWORD event_type, LPVOID event_data, LPVOID context);
125125

126-
SimpleThread thread_;
127126
Service* service_;
128127
std::shared_ptr<TaskRunner> task_runner_;
129128

@@ -162,18 +161,13 @@ ServiceThread::~ServiceThread()
162161

163162
setStatus(SERVICE_STOPPED);
164163

165-
thread_.stop();
164+
terminate();
165+
wait();
166166

167167
DCHECK(self);
168168
self = nullptr;
169169
}
170170

171-
//--------------------------------------------------------------------------------------------------
172-
void ServiceThread::start()
173-
{
174-
thread_.start(std::bind(&ServiceThread::run, this));
175-
}
176-
177171
//--------------------------------------------------------------------------------------------------
178172
void ServiceThread::setStatus(DWORD status)
179173
{

0 commit comments

Comments
 (0)