Kaydet (Commit) 04f02c65 authored tarafından Markus Mohrhard's avatar Markus Mohrhard

use std::thread instead of own solution

Change-Id: Id3d71897127c7af39688c9071dbb0e04b08fb327
üst 7d16d987
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "readstrings.h" #include "readstrings.h"
#include "errors.h" #include "errors.h"
#include "bzlib.h" #include "bzlib.h"
#include <thread>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
...@@ -214,68 +215,6 @@ struct MARChannelStringTable { ...@@ -214,68 +215,6 @@ struct MARChannelStringTable {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
typedef void (* ThreadFunc)(void *param);
#ifdef _WIN32
#include <process.h>
class Thread
{
public:
int Run(ThreadFunc func, void *param)
{
mThreadFunc = func;
mThreadParam = param;
unsigned int threadID;
mThread = (HANDLE) _beginthreadex(nullptr, 0, ThreadMain, this, 0,
&threadID);
return mThread ? 0 : -1;
}
int Join()
{
WaitForSingleObject(mThread, INFINITE);
CloseHandle(mThread);
return 0;
}
private:
static unsigned __stdcall ThreadMain(void *p)
{
Thread *self = (Thread *) p;
self->mThreadFunc(self->mThreadParam);
return 0;
}
HANDLE mThread;
ThreadFunc mThreadFunc;
void *mThreadParam;
};
#elif defined(UNIX)
#include <pthread.h>
class Thread
{
public:
int Run(ThreadFunc func, void *param)
{
return pthread_create(&thr, nullptr, (void* (*)(void *)) func, param);
}
int Join()
{
void *result;
return pthread_join(thr, &result);
}
private:
pthread_t thr;
};
#else
#error "Unsupported platform"
#endif
//-----------------------------------------------------------------------------
static NS_tchar* gPatchDirPath; static NS_tchar* gPatchDirPath;
static NS_tchar gInstallDirPath[MAXPATHLEN]; static NS_tchar gInstallDirPath[MAXPATHLEN];
static NS_tchar gWorkingDirPath[MAXPATHLEN]; static NS_tchar gWorkingDirPath[MAXPATHLEN];
...@@ -2751,12 +2690,11 @@ int NS_main(int argc, NS_tchar **argv) ...@@ -2751,12 +2690,11 @@ int NS_main(int argc, NS_tchar **argv)
// has still not stopped then show an indeterminate progress bar. // has still not stopped then show an indeterminate progress bar.
DWORD lastState = WaitForServiceStop(SVC_NAME, 5); DWORD lastState = WaitForServiceStop(SVC_NAME, 5);
if (lastState != SERVICE_STOPPED) { if (lastState != SERVICE_STOPPED) {
Thread t1; std::thread waitThread(WaitForServiceFinishThread, nullptr);
if (t1.Run(WaitForServiceFinishThread, nullptr) == 0 && if (showProgressUI) {
showProgressUI) {
ShowProgressUI(true, false); ShowProgressUI(true, false);
} }
t1.Join(); waitThread.join();
} }
lastState = WaitForServiceStop(SVC_NAME, 1); lastState = WaitForServiceStop(SVC_NAME, 1);
...@@ -3101,13 +3039,12 @@ int NS_main(int argc, NS_tchar **argv) ...@@ -3101,13 +3039,12 @@ int NS_main(int argc, NS_tchar **argv)
// Run update process on a background thread. ShowProgressUI may return // Run update process on a background thread. ShowProgressUI may return
// before QuitProgressUI has been called, so wait for UpdateThreadFunc to // before QuitProgressUI has been called, so wait for UpdateThreadFunc to
// terminate. Avoid showing the progress UI when staging an update. // terminate. Avoid showing the progress UI when staging an update.
Thread t; std::thread updateThread(UpdateThreadFunc, nullptr);
if (t.Run(UpdateThreadFunc, nullptr) == 0) { if (!sStagedUpdate && !sReplaceRequest)
if (!sStagedUpdate && !sReplaceRequest) { {
ShowProgressUI(); ShowProgressUI();
}
} }
t.Join(); updateThread.join();
#ifdef _WIN32 #ifdef _WIN32
if (argc > callbackIndex && !sReplaceRequest) { if (argc > callbackIndex && !sReplaceRequest) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment