OpenCBM
queue.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 2004 Spiro Trikaliotis
8  *
9  */
10 
19 #ifndef SRT_QUEUE_H
20 #define SRT_QUEUE_H
21 
22 #ifdef CSQ_STATIC
23 #include <csq.h>
24 #endif
25 
28 typedef NTSTATUS (*PCBMDRIVER_STARTIO)(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
29 
40 typedef
41 struct QUEUE
42 {
44  IO_CSQ IrpQueue;
45 
47  LIST_ENTRY IrpListHead;
48 
50  KSPIN_LOCK IrpListSpinlock;
51 
53  KEVENT NotEmptyEvent;
54 
55 #ifdef USE_FAST_START_THREAD
56 
59  KEVENT BackSignalEvent;
60 
61 #endif // #ifdef USE_FAST_START_THREAD
62 
65 
68  LONG IsStalled;
69 
73  LONG IsDropping;
74 
78 
80  PIRP CurrentIrp;
81 
82 } QUEUE, *PQUEUE;
83 
84 /* For performance reasons, these two functions are defined as macros
85  in release builds of the driver.
86  They do not need any protecting by synchronization primitives, as their
87  state could have changed on return in either way. This, the caller has
88  to make sure that is obtains exactly the state it wants to know.
89 */
90 #ifndef DBG
91 
93  #define QueueIsStalled(_Queue_) (_Queue_->IsStalled ? 1 : 0)
94 
96  #define QueueIsDropping(_Queue_) (_Queue_->IsDropping ? 1 : 0)
97 
98 #endif
99 
100 extern VOID
101 QueueInit(PQUEUE Queue, PCBMDRIVER_STARTIO DriverStartIo);
102 
103 extern NTSTATUS
104 QueueCompleteIrp(PQUEUE Queue, PIRP Irp, NTSTATUS StatusCode, ULONG_PTR Information);
105 
106 extern NTSTATUS
107 QueueStartPacket(PQUEUE Queue, PIRP Irp, BOOLEAN FastStart, PDEVICE_OBJECT Fdo);
108 
109 extern NTSTATUS
110 QueuePoll(PQUEUE Queue, PDEVICE_OBJECT Fdo);
111 
112 extern NTSTATUS
113 QueueSignal(PQUEUE Queue);
114 
115 extern NTSTATUS
116 QueueCleanup(PQUEUE Queue, PFILE_OBJECT FileObject);
117 
118 extern BOOLEAN
119 QueueShouldCancelCurrentIrp(PQUEUE Queue);
120 
121 #endif /* #ifndef SRT_QUEUE_H */
VOID QueueInit(PQUEUE Queue, PCBMDRIVER_STARTIO DriverStartIo)
Initialize a QUEUE object.
Definition: queue.c:388
KEVENT NotEmptyEvent
signal that the queue is not empty
Definition: queue.h:53
NTSTATUS(* PCBMDRIVER_STARTIO)(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.h:28
NTSTATUS QueueStartPacket(PQUEUE Queue, PIRP Irp, BOOLEAN FastStart, PDEVICE_OBJECT Fdo)
Insert an IRP into a QUEUE object.
Definition: queue.c:467
BOOLEAN QueueShouldCancelCurrentIrp(PQUEUE Queue)
Should the current IRP be cancelled?
Definition: queue.c:1041
A QUEUE object A QUEUE object is an object which can be used to queue IRPs for processing. This QUEUE object is optimized for being polled from an own worker thread. Anyway, a concept called FastStart is also implemented, which allows some IRPs to be completed immediately, without being queued, if no IRP is executed yet and the caller has stated that he wants this IRP to be started fast if possible.
Definition: queue.h:40
NTSTATUS QueuePoll(PQUEUE Queue, PDEVICE_OBJECT Fdo)
Poll the QUEUE.
Definition: queue.c:816
LIST_ENTRY IrpListHead
the list head for the IRP list
Definition: queue.h:47
KSPIN_LOCK IrpListSpinlock
the spin lock to protect the IRP list
Definition: queue.h:50
NTSTATUS QueueSignal(PQUEUE Queue)
Signal to the QUEUE need for processing.
Definition: queue.c:900
PIRP CurrentIrp
Pointer to the IRP which is currently processed.
Definition: queue.h:80
PCBMDRIVER_STARTIO DriverStartIo
pointer to the StartIo function to be called
Definition: queue.h:64
LONG IsStalled
counter; if != 0, this queue is stalled, that is, no entries are dequeued.
Definition: queue.h:68
IO_CSQ IrpQueue
the structure for the cancel-safe queue
Definition: queue.h:44
LONG IsDropping
counter; if != 0, this queue is dropping, that is, no new entries are queued into the queue; instead...
Definition: queue.h:73
NTSTATUS QueueCompleteIrp(PQUEUE Queue, PIRP Irp, NTSTATUS StatusCode, ULONG_PTR Information)
Complete an IRP which is on a QUEUE.
Definition: queue.c:756
NTSTATUS QueueCleanup(PQUEUE Queue, PFILE_OBJECT FileObject)
Process an IRP_MJ_CLEANUP on the QUEUE.
Definition: queue.c:998
struct QUEUE QUEUE
A QUEUE object A QUEUE object is an object which can be used to queue IRPs for processing. This QUEUE object is optimized for being polled from an own worker thread. Anyway, a concept called FastStart is also implemented, which allows some IRPs to be completed immediately, without being queued, if no IRP is executed yet and the caller has stated that he wants this IRP to be started fast if possible.
NTSTATUS DroppingReturnStatus
The NTSTATUS return code with which the IRP are completed if we are dropping IRPs.
Definition: queue.h:77