https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e5b0087c8ea87c1952a1e…
commit e5b0087c8ea87c1952a1edd4daee29839198d33c
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Sun Mar 3 23:14:07 2019 +0100
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Sun Mar 3 23:14:37 2019 +0100
[DCOMLAUNCH][WMISVC] Stop busy waiting shutdown
---
base/services/dcomlaunch/dcomlaunch.c | 15 +++++++++------
base/services/wmisvc/wmisvc.c | 15 +++++++++------
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/base/services/dcomlaunch/dcomlaunch.c
b/base/services/dcomlaunch/dcomlaunch.c
index 280dbff3eb..49c8541c0c 100644
--- a/base/services/dcomlaunch/dcomlaunch.c
+++ b/base/services/dcomlaunch/dcomlaunch.c
@@ -25,6 +25,7 @@ static WCHAR ServiceName[] = L"dcomlaunch";
static SERVICE_STATUS_HANDLE ServiceStatusHandle;
static SERVICE_STATUS ServiceStatus;
+static HANDLE ShutdownEvent;
/* FUNCTIONS *****************************************************************/
@@ -62,7 +63,8 @@ ServiceControlHandler(DWORD dwControl,
{
case SERVICE_CONTROL_STOP:
DPRINT1(" SERVICE_CONTROL_STOP received\n");
- UpdateServiceStatus(SERVICE_STOPPED);
+ SetEvent(ShutdownEvent);
+ UpdateServiceStatus(SERVICE_STOP_PENDING);
return ERROR_SUCCESS;
case SERVICE_CONTROL_PAUSE:
@@ -83,7 +85,8 @@ ServiceControlHandler(DWORD dwControl,
case SERVICE_CONTROL_SHUTDOWN:
DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n");
- UpdateServiceStatus(SERVICE_STOPPED);
+ SetEvent(ShutdownEvent);
+ UpdateServiceStatus(SERVICE_STOP_PENDING);
return ERROR_SUCCESS;
default :
@@ -111,14 +114,14 @@ ServiceMain(DWORD argc, LPTSTR *argv)
return;
}
+ ShutdownEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
+
DealWithDeviceEvent();
UpdateServiceStatus(SERVICE_RUNNING);
- do
- {
- Sleep(1);
- } while (1);
+ WaitForSingleObject(ShutdownEvent, INFINITE);
+ CloseHandle(ShutdownEvent);
UpdateServiceStatus(SERVICE_STOPPED);
}
diff --git a/base/services/wmisvc/wmisvc.c b/base/services/wmisvc/wmisvc.c
index 8ac9d9b733..042ff84e3d 100644
--- a/base/services/wmisvc/wmisvc.c
+++ b/base/services/wmisvc/wmisvc.c
@@ -44,6 +44,7 @@ static WCHAR ServiceName[] = L"winmgmt";
static SERVICE_STATUS_HANDLE ServiceStatusHandle;
static SERVICE_STATUS ServiceStatus;
+static HANDLE ShutdownEvent;
/* FUNCTIONS *****************************************************************/
@@ -81,7 +82,8 @@ ServiceControlHandler(DWORD dwControl,
{
case SERVICE_CONTROL_STOP:
DPRINT1(" SERVICE_CONTROL_STOP received\n");
- UpdateServiceStatus(SERVICE_STOPPED);
+ SetEvent(ShutdownEvent);
+ UpdateServiceStatus(SERVICE_STOP_PENDING);
return ERROR_SUCCESS;
case SERVICE_CONTROL_PAUSE:
@@ -102,7 +104,8 @@ ServiceControlHandler(DWORD dwControl,
case SERVICE_CONTROL_SHUTDOWN:
DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n");
- UpdateServiceStatus(SERVICE_STOPPED);
+ SetEvent(ShutdownEvent);
+ UpdateServiceStatus(SERVICE_STOP_PENDING);
return ERROR_SUCCESS;
default :
@@ -128,12 +131,12 @@ ServiceMain(DWORD argc, LPTSTR *argv)
return;
}
+ ShutdownEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
+
UpdateServiceStatus(SERVICE_RUNNING);
- do
- {
- Sleep(1);
- } while (1);
+ WaitForSingleObject(ShutdownEvent, INFINITE);
+ CloseHandle(ShutdownEvent);
UpdateServiceStatus(SERVICE_STOPPED);
}