ReactOS  0.4.14-dev-297-g23e575c
workqueue.c File Reference
#include <ntddk.h>
#include <chew/chew.h>
Include dependency graph for workqueue.c:

Go to the source code of this file.

Classes

struct  _WORK_ITEM
 

Macros

#define NDEBUG
 
#define FOURCC(w, x, y, z)   (((w) << 24) | ((x) << 16) | ((y) << 8) | (z))
 
#define CHEW_TAG   FOURCC('C','H','E','W')
 

Typedefs

typedef struct _WORK_ITEM WORK_ITEM
 
typedef struct _WORK_ITEMPWORK_ITEM
 

Functions

VOID ChewInit (PDEVICE_OBJECT DeviceObject)
 
VOID ChewShutdown (VOID)
 
VOID NTAPI ChewWorkItem (PDEVICE_OBJECT DeviceObject, PVOID ChewItem)
 
BOOLEAN ChewCreate (VOID(*Worker)(PVOID), PVOID WorkerContext)
 

Variables

PDEVICE_OBJECT WorkQueueDevice
 
LIST_ENTRY WorkQueue
 
KSPIN_LOCK WorkQueueLock
 
KEVENT WorkQueueClear
 

Macro Definition Documentation

◆ CHEW_TAG

#define CHEW_TAG   FOURCC('C','H','E','W')

Definition at line 17 of file workqueue.c.

◆ FOURCC

#define FOURCC (   w,
  x,
  y,
  z 
)    (((w) << 24) | ((x) << 16) | ((y) << 8) | (z))

Definition at line 16 of file workqueue.c.

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file workqueue.c.

Typedef Documentation

◆ PWORK_ITEM

◆ WORK_ITEM

Function Documentation

◆ ChewCreate()

BOOLEAN ChewCreate ( VOID(*)(PVOID Worker,
PVOID  WorkerContext 
)

Creates and queues a work item.

Definition at line 65 of file workqueue.c.

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 }
#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
KSPIN_LOCK WorkQueueLock
Definition: workqueue.c:21
LIST_ENTRY WorkQueue
Definition: workqueue.c:20
PIO_WORKITEM WorkItem
Definition: workqueue.c:27
PVOID WorkerContext
Definition: workqueue.c:29
PDEVICE_OBJECT WorkQueueDevice
Definition: workqueue.c:19
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VOID NTAPI ChewWorkItem(PDEVICE_OBJECT DeviceObject, PVOID ChewItem)
Definition: workqueue.c:45
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
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

Referenced by CompleteBucket(), LanSubmitReceiveWork(), LoopTransmit(), and ProtocolStatus().

◆ ChewInit()

VOID ChewInit ( PDEVICE_OBJECT  DeviceObject)

Initialize CHEW, given a device object (since IoAllocateWorkItem relies on it).

Definition at line 32 of file workqueue.c.

33 {
38 }
#define TRUE
Definition: types.h:120
KSPIN_LOCK WorkQueueLock
Definition: workqueue.c:21
LIST_ENTRY WorkQueue
Definition: workqueue.c:20
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
PDEVICE_OBJECT WorkQueueDevice
Definition: workqueue.c:19
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
KEVENT WorkQueueClear
Definition: workqueue.c:22

Referenced by DriverEntry().

◆ ChewShutdown()

VOID ChewShutdown ( VOID  )

Shutdown CHEW, waits for remaining work items.

Definition at line 40 of file workqueue.c.

41 {
43 }
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
smooth NULL
Definition: ftsmooth.c:416
KEVENT WorkQueueClear
Definition: workqueue.c:22

Referenced by TiUnload().

◆ ChewWorkItem()

VOID NTAPI ChewWorkItem ( PDEVICE_OBJECT  DeviceObject,
PVOID  ChewItem 
)

Definition at line 45 of file workqueue.c.

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 }
VOID(* Worker)(PVOID WorkerContext)
Definition: workqueue.c:28
#define CHEW_TAG
Definition: workqueue.c:17
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
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
LIST_ENTRY WorkQueue
Definition: workqueue.c:20
PIO_WORKITEM WorkItem
Definition: workqueue.c:27
PVOID WorkerContext
Definition: workqueue.c:29
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
LIST_ENTRY Entry
Definition: workqueue.c:26
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
KEVENT WorkQueueClear
Definition: workqueue.c:22

Referenced by ChewCreate().

Variable Documentation

◆ WorkQueue

◆ WorkQueueClear

KEVENT WorkQueueClear

Definition at line 22 of file workqueue.c.

Referenced by ChewCreate(), ChewInit(), ChewShutdown(), and ChewWorkItem().

◆ WorkQueueDevice

PDEVICE_OBJECT WorkQueueDevice

Definition at line 19 of file workqueue.c.

Referenced by ChewCreate(), and ChewInit().

◆ WorkQueueLock

KSPIN_LOCK WorkQueueLock

Definition at line 21 of file workqueue.c.

Referenced by ChewCreate(), ChewInit(), and ChewWorkItem().