ReactOS  0.4.14-dev-50-g13bb5e2
iotimer.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for iotimer.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI IopTimerDispatch (IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
VOID NTAPI IopRemoveTimerFromTimerList (IN PIO_TIMER Timer)
 
NTSTATUS NTAPI IoInitializeTimer (IN PDEVICE_OBJECT DeviceObject, IN PIO_TIMER_ROUTINE TimerRoutine, IN PVOID Context)
 
VOID NTAPI IoStartTimer (IN PDEVICE_OBJECT DeviceObject)
 
VOID NTAPI IoStopTimer (PDEVICE_OBJECT DeviceObject)
 

Variables

KSPIN_LOCK IopTimerLock
 
LIST_ENTRY IopTimerQueueHead
 
KDPC IopTimerDpc
 
KTIMER IopTimer
 
ULONG IopTimerCount = 0
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file iotimer.c.

Function Documentation

◆ IoInitializeTimer()

NTSTATUS NTAPI IoInitializeTimer ( IN PDEVICE_OBJECT  DeviceObject,
IN PIO_TIMER_ROUTINE  TimerRoutine,
IN PVOID  Context 
)

Definition at line 92 of file iotimer.c.

95 {
96  PIO_TIMER IoTimer = DeviceObject->Timer;
97  PAGED_CODE();
98 
99  /* Check if we don't have a timer yet */
100  if (!IoTimer)
101  {
102  /* Allocate Timer */
104  sizeof(IO_TIMER),
105  TAG_IO_TIMER);
106  if (!IoTimer) return STATUS_INSUFFICIENT_RESOURCES;
107 
108  /* Set up the Timer Structure */
109  RtlZeroMemory(IoTimer, sizeof(IO_TIMER));
110  IoTimer->Type = IO_TYPE_TIMER;
111  IoTimer->DeviceObject = DeviceObject;
112  DeviceObject->Timer = IoTimer;
113  }
114 
115  /* Setup the timer routine and context */
116  IoTimer->TimerRoutine = TimerRoutine;
117  IoTimer->Context = Context;
118 
119  /* Add it to the Timer List */
121  &IoTimer->IoTimerList,
122  &IopTimerLock);
123 
124  /* Return Success */
125  return STATUS_SUCCESS;
126 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
PIO_TIMER_ROUTINE TimerRoutine
Definition: iotypes.h:804
#define TAG_IO_TIMER
Definition: tag.h:101
#define PAGED_CODE()
Definition: video.h:57
#define IO_TYPE_TIMER
LIST_ENTRY IopTimerQueueHead
Definition: iotimer.c:19
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:806
KSPIN_LOCK IopTimerLock
Definition: iotimer.c:18
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
USHORT Type
Definition: iotypes.h:801
_In_ PIO_TIMER_ROUTINE TimerRoutine
Definition: iofuncs.h:1076
LIST_ENTRY IoTimerList
Definition: iotypes.h:803
PVOID Context
Definition: iotypes.h:805
struct tagContext Context
Definition: acpixf.h:1024
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by ClasspEnableTimer(), CreateCdRomDeviceObject(), IntVideoPortSetupTimer(), PcAddAdapterDevice(), ScsiPortInitialize(), USBSTOR_AddDevice(), and WdmaudAddDevice().

◆ IopRemoveTimerFromTimerList()

VOID NTAPI IopRemoveTimerFromTimerList ( IN PIO_TIMER  Timer)

Definition at line 70 of file iotimer.c.

71 {
72  KIRQL OldIrql;
73 
74  /* Lock Timers */
76 
77  /* Remove Timer from the List and Drop the Timer Count if Enabled */
78  RemoveEntryList(&Timer->IoTimerList);
79  if (Timer->TimerEnabled) IopTimerCount--;
80 
81  /* Unlock the Timers */
83 }
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
KSPIN_LOCK IopTimerLock
Definition: iotimer.c:18
#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
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
ULONG IopTimerCount
Definition: iotimer.c:26

Referenced by IoDeleteDevice().

◆ IopTimerDispatch()

VOID NTAPI IopTimerDispatch ( IN PKDPC  Dpc,
IN PVOID  DeferredContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 32 of file iotimer.c.

36 {
37  KIRQL OldIrql;
38  PLIST_ENTRY TimerEntry;
40  ULONG i;
41 
42  /* Check if any Timers are actualyl enabled as of now */
43  if (IopTimerCount)
44  {
45  /* Lock the Timers */
47 
48  /* Call the Timer Routine of each enabled Timer */
49  for (TimerEntry = IopTimerQueueHead.Flink, i = IopTimerCount;
50  (TimerEntry != &IopTimerQueueHead) && i;
51  TimerEntry = TimerEntry->Flink)
52  {
53  /* Get the timer and check if it's enabled */
54  Timer = CONTAINING_RECORD(TimerEntry, IO_TIMER, IoTimerList);
55  if (Timer->TimerEnabled)
56  {
57  /* Call the timer routine */
58  Timer->TimerRoutine(Timer->DeviceObject, Timer->Context);
59  i--;
60  }
61  }
62 
63  /* Unlock the Timers */
65  }
66 }
UCHAR KIRQL
Definition: env_spec_w32.h:591
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LIST_ENTRY IopTimerQueueHead
Definition: iotimer.c:19
KSPIN_LOCK IopTimerLock
Definition: iotimer.c:18
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#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
Definition: typedefs.h:117
UINT Timer
Definition: capclock.c:11
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
ULONG IopTimerCount
Definition: iotimer.c:26
unsigned int ULONG
Definition: retypes.h:1

Referenced by IoInitSystem().

◆ IoStartTimer()

VOID NTAPI IoStartTimer ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 133 of file iotimer.c.

134 {
135  KIRQL OldIrql;
136  PIO_TIMER IoTimer = DeviceObject->Timer;
137 
138  /* Make sure the device isn't unloading */
139  if (!(((PEXTENDED_DEVOBJ_EXTENSION)(DeviceObject->DeviceObjectExtension))->
140  ExtensionFlags & (DOE_UNLOAD_PENDING |
144  {
145  /* Lock Timers */
147 
148  /* Check if the timer isn't already enabled */
149  if (!IoTimer->TimerEnabled)
150  {
151  /* Enable it and increase the timer count */
152  IoTimer->TimerEnabled = TRUE;
153  IopTimerCount++;
154  }
155 
156  /* Unlock Timers */
158  }
159 }
#define TRUE
Definition: types.h:120
UCHAR KIRQL
Definition: env_spec_w32.h:591
KSPIN_LOCK IopTimerLock
Definition: iotimer.c:18
USHORT TimerEnabled
Definition: iotypes.h:802
#define DOE_UNLOAD_PENDING
Definition: iotypes.h:149
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define DOE_DELETE_PENDING
Definition: iotypes.h:150
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define DOE_REMOVE_PENDING
Definition: iotypes.h:151
#define DOE_REMOVE_PROCESSED
Definition: iotypes.h:152
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
ULONG IopTimerCount
Definition: iotimer.c:26

Referenced by ClasspEnableTimer(), CreateCdRomDeviceObject(), PcAddAdapterDevice(), ScsiPortInitialize(), VideoPortStartTimer(), and WdmaudAddDevice().

◆ IoStopTimer()

VOID NTAPI IoStopTimer ( PDEVICE_OBJECT  DeviceObject)

Definition at line 166 of file iotimer.c.

167 {
168  KIRQL OldIrql;
169  PIO_TIMER IoTimer = DeviceObject->Timer;
170 
171  /* Lock Timers */
173 
174  /* Check if the timer is enabled */
175  if (IoTimer->TimerEnabled)
176  {
177  /* Disable it and decrease the timer count */
178  IoTimer->TimerEnabled = FALSE;
179  IopTimerCount--;
180  }
181 
182  /* Unlock Timers */
184 }
UCHAR KIRQL
Definition: env_spec_w32.h:591
KSPIN_LOCK IopTimerLock
Definition: iotimer.c:18
USHORT TimerEnabled
Definition: iotypes.h:802
#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
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
ULONG IopTimerCount
Definition: iotimer.c:26

Referenced by ClassDispatchPnp(), ClasspDisableTimer(), SpiCleanupAfterInit(), USBSTOR_FdoHandlePnp(), and VideoPortStopTimer().

Variable Documentation

◆ IopTimer

KTIMER IopTimer

Definition at line 23 of file iotimer.c.

Referenced by IoInitSystem().

◆ IopTimerCount

ULONG IopTimerCount = 0

Definition at line 26 of file iotimer.c.

Referenced by IopRemoveTimerFromTimerList(), IopTimerDispatch(), IoStartTimer(), and IoStopTimer().

◆ IopTimerDpc

KDPC IopTimerDpc

Definition at line 22 of file iotimer.c.

Referenced by IoInitSystem().

◆ IopTimerLock

◆ IopTimerQueueHead

LIST_ENTRY IopTimerQueueHead

Definition at line 19 of file iotimer.c.

Referenced by IoInitializeTimer(), IoInitSystem(), and IopTimerDispatch().