[MOUNTMGR] Fix invalid WorkerReferences check in QueueWorkItem()

This fixes shutting down ReactOS under certain circumstances, where
the references were incremented, but no worker thread started.
Also, took the opportunity to clarify the WorkerReferences comparisons
where relevant.

CORE-16446
This commit is contained in:
Pierre Schweitzer 2019-10-22 21:51:04 +02:00
parent c8cbd566f9
commit 457612702b
No known key found for this signature in database
GPG key ID: 7545556C3D585B0B
2 changed files with 4 additions and 4 deletions

View file

@ -1268,8 +1268,8 @@ QueueWorkItem(IN PDEVICE_EXTENSION DeviceExtension,
/* When called, lock is already acquired */
/* If noone, start to work */
if (InterlockedIncrement(&(DeviceExtension->WorkerReferences)))
/* If noone (-1 as references), start to work */
if (InterlockedIncrement(&(DeviceExtension->WorkerReferences)) == 0)
{
IoQueueWorkItem(WorkItem->WorkItem, WorkerThread, DelayedWorkQueue, DeviceExtension);
}

View file

@ -822,7 +822,7 @@ MountMgrUnload(IN struct _DRIVER_OBJECT *DriverObject)
KeInitializeEvent(&UnloadEvent, NotificationEvent, FALSE);
/* Wait for workers to finish */
if (InterlockedIncrement(&DeviceExtension->WorkerReferences))
if (InterlockedIncrement(&DeviceExtension->WorkerReferences) > 0)
{
KeReleaseSemaphore(&(DeviceExtension->WorkerSemaphore),
IO_NO_INCREMENT, 1, FALSE);
@ -1770,7 +1770,7 @@ MountMgrShutdown(IN PDEVICE_OBJECT DeviceObject,
KeInitializeEvent(&UnloadEvent, NotificationEvent, FALSE);
/* Wait for workers */
if (InterlockedIncrement(&(DeviceExtension->WorkerReferences)))
if (InterlockedIncrement(&(DeviceExtension->WorkerReferences)) > 0)
{
KeReleaseSemaphore(&(DeviceExtension->WorkerSemaphore),
IO_NO_INCREMENT,