services: Use threadpool timers for services delay loading.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47675
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2019-09-06 21:33:58 +02:00 committed by Alexandre Julliard
parent deb26091ef
commit 765815729f
1 changed files with 18 additions and 21 deletions

View File

@ -353,15 +353,13 @@ static void CALLBACK delayed_autostart_cancel_callback(void *object, void *userd
}
static void CALLBACK delayed_autostart_callback(TP_CALLBACK_INSTANCE *instance, void *context,
TP_WAIT *wait, TP_WAIT_RESULT result)
TP_TIMER *timer)
{
struct delayed_autostart_params *params = context;
struct service_entry *service;
unsigned int i;
DWORD err;
if (result == WAIT_TIMEOUT)
{
scmdatabase_lock_startup(active_database, INFINITE);
for (i = 0; i < params->count; i++)
@ -369,7 +367,7 @@ static void CALLBACK delayed_autostart_callback(TP_CALLBACK_INSTANCE *instance,
service = params->services[i];
if (service->status.dwCurrentState == SERVICE_STOPPED)
{
TRACE("Starting deleyed auto-start service %s\n", debugstr_w(service->name));
TRACE("Starting delayed auto-start service %s\n", debugstr_w(service->name));
err = service_start(service, 0, NULL);
if (err != ERROR_SUCCESS)
FIXME("Delayed auto-start service %s failed to start: %d\n",
@ -379,11 +377,10 @@ static void CALLBACK delayed_autostart_callback(TP_CALLBACK_INSTANCE *instance,
}
scmdatabase_unlock_startup(active_database);
}
heap_free(params->services);
heap_free(params);
CloseThreadpoolWait(wait);
CloseThreadpoolTimer(timer);
}
static BOOL schedule_delayed_autostart(struct service_entry **services, unsigned int count)
@ -391,7 +388,7 @@ static BOOL schedule_delayed_autostart(struct service_entry **services, unsigned
struct delayed_autostart_params *params;
TP_CALLBACK_ENVIRON environment;
LARGE_INTEGER timestamp;
TP_WAIT *wait;
TP_TIMER *timer;
FILETIME ft;
if (!(delayed_autostart_cleanup = CreateThreadpoolCleanupGroup()))
@ -413,14 +410,14 @@ static BOOL schedule_delayed_autostart(struct service_entry **services, unsigned
ft.dwLowDateTime = timestamp.u.LowPart;
ft.dwHighDateTime = timestamp.u.HighPart;
if (!(wait = CreateThreadpoolWait(delayed_autostart_callback, params, &environment)))
if (!(timer = CreateThreadpoolTimer(delayed_autostart_callback, params, &environment)))
{
ERR("CreateThreadpoolWait failed: %u\n", GetLastError());
heap_free(params);
return FALSE;
}
SetThreadpoolWait(wait, params, &ft);
SetThreadpoolTimer(timer, &ft, 0, 0);
return TRUE;
}