char dir[MAX_PATH];\r
bool stopping;\r
unsigned long throttle_delay;\r
-CRITICAL_SECTION throttle_section;\r
-CONDITION_VARIABLE throttle_condition;\r
+HANDLE throttle_timer;\r
+LARGE_INTEGER throttle_duetime;\r
\r
static enum { NSSM_EXIT_RESTART, NSSM_EXIT_IGNORE, NSSM_EXIT_REALLY, NSSM_EXIT_UNCLEAN } exit_actions;\r
static const char *exit_action_strings[] = { "Restart", "Ignore", "Exit", "Suicide", 0 };\r
set_service_recovery(service_name);\r
\r
/* Used for signalling a resume if the service pauses when throttled. */\r
- InitializeCriticalSection(&throttle_section);\r
+ throttle_timer = CreateWaitableTimer(0, 1, 0);\r
\r
monitor_service();\r
}\r
\r
case SERVICE_CONTROL_CONTINUE:\r
throttle = 0;\r
- WakeConditionVariable(&throttle_condition);\r
+ ZeroMemory(&throttle_duetime, sizeof(throttle_duetime));\r
+ SetWaitableTimer(throttle_timer, &throttle_duetime, 0, 0, 0, 0);\r
service_status.dwCurrentState = SERVICE_CONTINUE_PENDING;\r
service_status.dwWaitHint = throttle_milliseconds() + NSSM_WAITHINT_MARGIN;\r
log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_RESET_THROTTLE, service_name, 0);\r
_snprintf(milliseconds, sizeof(milliseconds), "%d", ms);\r
log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_THROTTLED, service_name, threshold, milliseconds, 0);\r
\r
- EnterCriticalSection(&throttle_section);\r
+ ZeroMemory(&throttle_duetime, sizeof(throttle_duetime));\r
+ throttle_duetime.QuadPart = 0 - (ms * 10000);\r
+ SetWaitableTimer(throttle_timer, &throttle_duetime, 0, 0, 0, 0);\r
\r
service_status.dwCurrentState = SERVICE_PAUSED;\r
SetServiceStatus(service_handle, &service_status);\r
\r
- SleepConditionVariableCS(&throttle_condition, &throttle_section, ms);\r
-\r
- LeaveCriticalSection(&throttle_section);\r
+ WaitForSingleObject(throttle_timer, INFINITE);\r
}\r