Working work item library.
- Slightly changed semantics of ChewCreate: the work may be performed 
  inline if we're in the right irql already.
- The user data is copied automatically if the call succeeds and a work 
  item is created.
- The address of the work item is returned through an argument if it
  was allocated.
Modified: trunk/reactos/drivers/lib/chew/workqueue.c
Modified: trunk/reactos/include/chew/chew.h

Modified: trunk/reactos/drivers/lib/chew/workqueue.c
--- trunk/reactos/drivers/lib/chew/workqueue.c	2005-12-12 22:00:16 UTC (rev 20126)
+++ trunk/reactos/drivers/lib/chew/workqueue.c	2005-12-12 22:01:32 UTC (rev 20127)
@@ -1,16 +1,15 @@
 /*
- * COPYRIGHT:   See COPYING in the top level directory
- * PROJECT:     ReactOS TCP/IP protocol driver
- * FILE:        tcpip/main.c
- * PURPOSE:     Common Highlevel Executive Worker
- * PROGRAMMERS: Art Yerkes
- * REVISIONS:
- *   CSH 10/12-2005 Created
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS kernel
+ * FILE:            drivers/lib/chew/workqueue.c
+ * PURPOSE:         Common Highlevel Executive Worker
+ *
+ * PROGRAMMERS:     arty (ayerkes@speakeasy.net)
  */
 #include <ntddk.h>
 #include <chew/chew.h>
 
-//#define NDEBUG
+#define NDEBUG
 
 #define FOURCC(w,x,y,z) (((w) << 24) | ((x) << 16) | ((y) << 8) | (z))
 
@@ -51,6 +50,8 @@
 VOID STDCALL ChewWorkItem( PDEVICE_OBJECT DeviceObject, PVOID ChewItem ) {
     PWORK_ITEM WorkItem = ChewItem;
 
+    RemoveEntryList( &WorkItem->Entry );
+
     if( WorkItem->Worker ) 
 	WorkItem->Worker( WorkItem->UserSpace );
 
@@ -61,8 +62,10 @@
 BOOLEAN ChewCreate
 ( PVOID *ItemPtr, UINT Bytes, VOID (*Worker)( PVOID ), PVOID UserSpace ) {
     PWORK_ITEM Item;
+    
     if( KeGetCurrentIrql() == PASSIVE_LEVEL ) {
-	*ItemPtr = NULL;
+	if( ItemPtr )
+	    *ItemPtr = NULL;
 	Worker(UserSpace);
 	return TRUE;
     } else {
@@ -85,12 +88,14 @@
 		( &WorkQueue, &Item->Entry, &WorkQueueLock );
 	    IoQueueWorkItem
 		( Item->WorkItem, ChewWorkItem, CriticalWorkQueue, Item );
+	    
+	    if( ItemPtr ) 
+		*ItemPtr = Item;
 
-	    *ItemPtr = Item;
-
 	    return TRUE;
-	} else
+	} else {
 	    return FALSE;
+	}
     }
 }
 

Modified: trunk/reactos/include/chew/chew.h
--- trunk/reactos/include/chew/chew.h	2005-12-12 22:00:16 UTC (rev 20126)
+++ trunk/reactos/include/chew/chew.h	2005-12-12 22:01:32 UTC (rev 20127)
@@ -1,10 +1,40 @@
+/*
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS kernel
+ * FILE:            include/chew/chew.h
+ * PURPOSE:         Common Highlevel Executive Worker
+ *
+ * PROGRAMMERS:     arty (ayerkes@speakeasy.net)
+ */
+
 #ifndef _REACTOS_CHEW_H
 #define _REACTOS_CHEW_H
 
+/**
+ * Initialize CHEW, given a device object (since IoAllocateWorkItem relies on
+ * it).
+ */
 VOID ChewInit( PDEVICE_OBJECT DeviceObject );
+/**
+ * Shutdown CHEW, including removing remaining work items.
+ */
 VOID ChewShutdown();
+/**
+ * Create a work item, or perform the work, based on IRQL.
+ * At passive level, Worker is called directly on UserSpace.
+ * At greater than passive level, a work item is created with Bytes
+ * context area and data copied from UserSpace.
+ * If a work item is created, Item contains the address and the function
+ * returns true.
+ * If the work is performed immediately, Item contains NULL and the
+ * function returns true.
+ * Else, the function returns false and Item is undefined.
+ */
 BOOLEAN ChewCreate
 ( PVOID *Item, UINT Bytes, VOID (*Worker)(PVOID), PVOID UserSpace );
+/**
+ * Remove a work item, given the pointer returned to Item in ChewCreate.
+ */
 VOID ChewRemove( PVOID Item );
 
 #endif/*_REACTOS_CHEW_H*/