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.

svn path=/trunk/; revision=20127
This commit is contained in:
Art Yerkes 2005-12-12 22:01:32 +00:00
parent 0e5dec753d
commit 9b271017a5
2 changed files with 47 additions and 12 deletions

View file

@ -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 ChewShutdown() {
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 @@ VOID STDCALL ChewWorkItem( PDEVICE_OBJECT DeviceObject, PVOID ChewItem ) {
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 @@ BOOLEAN ChewCreate
( &WorkQueue, &Item->Entry, &WorkQueueLock );
IoQueueWorkItem
( Item->WorkItem, ChewWorkItem, CriticalWorkQueue, Item );
*ItemPtr = Item;
if( ItemPtr )
*ItemPtr = Item;
return TRUE;
} else
} else {
return FALSE;
}
}
}

View file

@ -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*/