Windows: Run Workers until empty task queue
authorJeffrey Altman <jaltman@your-file-system.com>
Sun, 29 Jan 2012 15:37:50 +0000 (10:37 -0500)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Sun, 29 Jan 2012 18:40:10 +0000 (10:40 -0800)
Do not allow a worker thread to sleep until the task queue is
empty.  It is better for the running thread to pick up and process
a task then to sleep this thread and wait for another one to wake
up to perform the work.

Change-Id: I776bb9408ab054b045acb9bc003b88436cc4266b
Reviewed-on: http://gerrit.openafs.org/6626
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Tested-by: Jeffrey Altman <jaltman@secure-endpoints.com>

src/WINNT/afsrdr/kernel/lib/AFSWorker.cpp

index 56a8e37..1c9df6e 100644 (file)
@@ -700,13 +700,24 @@ AFSWorkerThread( IN PVOID Context)
             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                           AFS_TRACE_LEVEL_ERROR,
                           "AFSWorkerThread Wait for queue items failed Status %08lX\n", ntStatus);
+
+            ntStatus = STATUS_SUCCESS;
         }
         else
         {
 
             pWorkItem = AFSRemoveWorkItem();
 
-            if( pWorkItem != NULL)
+            if( pWorkItem == NULL)
+            {
+
+                ntStatus = KeWaitForSingleObject( &pLibraryDevExt->Specific.Library.WorkerQueueHasItems,
+                                                  Executive,
+                                                  KernelMode,
+                                                  FALSE,
+                                                  NULL);
+            }
+            else
             {
 
                 freeWorkItem = TRUE;
@@ -802,15 +813,10 @@ AFSWorkerThread( IN PVOID Context)
 
                     ExFreePoolWithTag( pWorkItem, AFS_WORK_ITEM_TAG);
                 }
+
+                ntStatus = STATUS_SUCCESS;
             }
         }
-
-        ntStatus = KeWaitForSingleObject( &pLibraryDevExt->Specific.Library.WorkerQueueHasItems,
-                                          Executive,
-                                          KernelMode,
-                                          FALSE,
-                                          NULL);
-
     } // worker thread loop
 
     ClearFlag( pPoolContext->State, AFS_WORKER_INITIALIZED);
@@ -868,13 +874,24 @@ AFSIOWorkerThread( IN PVOID Context)
             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                           AFS_TRACE_LEVEL_ERROR,
                           "AFSIOWorkerThread Wait for queue items failed Status %08lX\n", ntStatus);
+
+            ntStatus = STATUS_SUCCESS;
         }
         else
         {
 
             pWorkItem = AFSRemoveIOWorkItem();
 
-            if( pWorkItem != NULL)
+            if( pWorkItem == NULL)
+            {
+
+                ntStatus = KeWaitForSingleObject( &pLibraryDevExt->Specific.Library.IOWorkerQueueHasItems,
+                                                  Executive,
+                                                  KernelMode,
+                                                  FALSE,
+                                                  NULL);
+            }
+            else
             {
 
                 freeWorkItem = TRUE;
@@ -930,15 +947,10 @@ AFSIOWorkerThread( IN PVOID Context)
 
                     ExFreePoolWithTag( pWorkItem, AFS_WORK_ITEM_TAG);
                 }
+
+                ntStatus = STATUS_SUCCESS;
             }
         }
-
-        ntStatus = KeWaitForSingleObject( &pLibraryDevExt->Specific.Library.IOWorkerQueueHasItems,
-                                          Executive,
-                                          KernelMode,
-                                          FALSE,
-                                          NULL);
-
     } // worker thread loop
 
     ClearFlag( pPoolContext->State, AFS_WORKER_INITIALIZED);