ReactOS  0.4.14-dev-384-g5b37caa
workqueue.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: lib/drivers/chew/workqueue.c
5  * PURPOSE: Common Highlevel Executive Worker
6  *
7  * PROGRAMMERS: arty (ayerkes@speakeasy.net)
8  */
9 
10 #include <ntddk.h>
11 #include <chew/chew.h>
12 
13 #define NDEBUG
14 //#include <debug.h>
15 
16 #define FOURCC(w,x,y,z) (((w) << 24) | ((x) << 16) | ((y) << 8) | (z))
17 #define CHEW_TAG FOURCC('C','H','E','W')
18 
23 
24 typedef struct _WORK_ITEM
25 {
31 
33 {
38 }
39 
41 {
43 }
44 
46 {
47  PWORK_ITEM WorkItem = ChewItem;
48  KIRQL OldIrql;
49 
50  WorkItem->Worker(WorkItem->WorkerContext);
51 
52  IoFreeWorkItem(WorkItem->WorkItem);
53 
55  RemoveEntryList(&WorkItem->Entry);
56 
57  if (IsListEmpty(&WorkQueue))
59 
61 
62  ExFreePoolWithTag(WorkItem, CHEW_TAG);
63 }
64 
65 BOOLEAN ChewCreate(VOID (*Worker)(PVOID), PVOID WorkerContext)
66 {
67  PWORK_ITEM Item;
69  sizeof(WORK_ITEM),
70  CHEW_TAG);
71 
72  if (Item)
73  {
75  if (!Item->WorkItem)
76  {
77  ExFreePool(Item);
78  return FALSE;
79  }
80 
81  Item->Worker = Worker;
82  Item->WorkerContext = WorkerContext;
86 
87  return TRUE;
88  }
89  else
90  {
91  return FALSE;
92  }
93 }
struct _WORK_ITEM WORK_ITEM
#define TRUE
Definition: types.h:120
VOID(* Worker)(PVOID WorkerContext)
Definition: workqueue.c:28
#define CHEW_TAG
Definition: workqueue.c:17
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
KSPIN_LOCK WorkQueueLock
Definition: workqueue.c:21
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
LIST_ENTRY WorkQueue
Definition: workqueue.c:20
PIO_WORKITEM WorkItem
Definition: workqueue.c:27
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
PVOID WorkerContext
Definition: workqueue.c:29
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
PDEVICE_OBJECT WorkQueueDevice
Definition: workqueue.c:19
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
VOID NTAPI ChewWorkItem(PDEVICE_OBJECT DeviceObject, PVOID ChewItem)
Definition: workqueue.c:45
#define VOID
Definition: acefi.h:82
Definition: typedefs.h:117
struct _WORK_ITEM * PWORK_ITEM
LIST_ENTRY Entry
Definition: workqueue.c:26
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
VOID ChewInit(PDEVICE_OBJECT DeviceObject)
Definition: workqueue.c:32
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
BOOLEAN ChewCreate(VOID(*Worker)(PVOID), PVOID WorkerContext)
Definition: workqueue.c:65
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
KEVENT WorkQueueClear
Definition: workqueue.c:22
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
VOID ChewShutdown(VOID)
Definition: workqueue.c:40