ReactOS 0.4.16-dev-297-gc569aee
cmdelay.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for cmdelay.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

 _Function_class_ (KDEFERRED_ROUTINE)
 
 _Function_class_ (WORKER_THREAD_ROUTINE)
 
VOID NTAPI CmpInitializeDelayedCloseTable (VOID)
 
VOID NTAPI CmpInitDelayDerefKCBEngine (VOID)
 
VOID NTAPI CmpDelayDerefKeyControlBlock (IN PCM_KEY_CONTROL_BLOCK Kcb)
 
VOID NTAPI CmpArmDelayedCloseTimer (VOID)
 
VOID NTAPI CmpAddToDelayedClose (IN PCM_KEY_CONTROL_BLOCK Kcb, IN BOOLEAN LockHeldExclusively)
 
VOID NTAPI CmpRemoveFromDelayedClose (IN PCM_KEY_CONTROL_BLOCK Kcb)
 

Variables

WORK_QUEUE_ITEM CmpDelayDerefKCBWorkItem
 
ULONG CmpDelayedCloseSize = 2048
 
ULONG CmpDelayedCloseElements
 
KGUARDED_MUTEX CmpDelayedCloseTableLock
 
BOOLEAN CmpDelayCloseWorkItemActive
 
WORK_QUEUE_ITEM CmpDelayCloseWorkItem
 
LIST_ENTRY CmpDelayedLRUListHead
 
ULONG CmpDelayCloseIntervalInSeconds = 5
 
KDPC CmpDelayCloseDpc
 
KTIMER CmpDelayCloseTimer
 
KGUARDED_MUTEX CmpDelayDerefKCBLock
 
BOOLEAN CmpDelayDerefKCBWorkItemActive
 
LIST_ENTRY CmpDelayDerefKCBListHead
 
ULONG CmpDelayDerefKCBIntervalInSeconds = 5
 
KDPC CmpDelayDerefKCBDpc
 
KTIMER CmpDelayDerefKCBTimer
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file cmdelay.c.

Function Documentation

◆ _Function_class_() [1/2]

_Function_class_ ( KDEFERRED_ROUTINE  )

Definition at line 38 of file cmdelay.c.

45{
46 /* Sanity check */
48
49 /* Queue the work item */
51}
WORK_QUEUE_ITEM CmpDelayCloseWorkItem
Definition: cmdelay.c:23
BOOLEAN CmpDelayCloseWorkItemActive
Definition: cmdelay.c:22
#define ASSERT(a)
Definition: mode.c:44
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
@ DelayedWorkQueue
Definition: extypes.h:190

◆ _Function_class_() [2/2]

_Function_class_ ( WORKER_THREAD_ROUTINE  )

Definition at line 53 of file cmdelay.c.

57{
59 ULONG i, ConvKey;
60 PAGED_CODE();
61
62 /* Sanity check */
64
65 /* Lock the registry */
67
68 /* Acquire the delayed close table lock */
70
71 /* Iterate */
72 for (i = 0; i < (CmpDelayedCloseSize >> 2); i++)
73 {
74 /* Break out of the loop if there is nothing to process */
76
77 /* Sanity check */
79
80 /* Get the entry */
83 DelayedLRUList);
84
85 /* Save the ConvKey value of the KCB */
86 ConvKey = ListEntry->KeyControlBlock->ConvKey;
87
88 /* Release the delayed close table lock */
90
91 /* Acquire the KCB lock */
93
94 /* Reacquire the delayed close table lock */
96
97 /* Get the entry */
100 DelayedLRUList);
101
102 /* Is the entry we have still the first one? */
104 {
105 /* No, someone already inserted an entry there */
106 CmpReleaseKcbLockByKey(ConvKey);
107 break;
108 }
109
110 /* Is it a different entry? */
111 if (ConvKey != ListEntry->KeyControlBlock->ConvKey)
112 {
113 /* Release the delayed close table lock */
115
116 /* Release the KCB lock */
117 CmpReleaseKcbLockByKey(ConvKey);
118
119 /* Reacquire the delayed close table lock */
121
122 /* Iterate again */
123 continue;
124 }
125
126 /* Remove it from the end of the list */
127 ListEntry =
129
130 /* Get the containing entry */
131 ListEntry = CONTAINING_RECORD(ListEntry,
133 DelayedLRUList);
134
135 /* Process the entry */
136 if ((ListEntry->KeyControlBlock->RefCount) ||
138 {
139 /* Add it to the beginning of the list */
141
142 /* Release the delayed close table lock */
144 }
145 else
146 {
147 /* Release the delayed close table lock */
149
150 /* Zero out the DelayCloseEntry pointer */
152
153 /* Cleanup the KCB cache */
155
156 /* Free the delay item */
157 CmpFreeDelayItem(ListEntry);
158
159 /* Decrement delayed close elements count */
161 }
162
163 /* Release the KCB lock */
164 CmpReleaseKcbLockByKey(ConvKey);
165
166 /* Reacquire the delayed close table lock */
168 }
169
171 {
172 /* We're not active anymore */
174 }
175 else
176 {
177 /* We didn't process all things, so reschedule for the next time */
179 }
180
181 /* Release the delayed close table lock */
183
184 /* Unlock the registry */
186}
#define PAGED_CODE()
#define InterlockedDecrement
Definition: armddk.h:52
struct _CM_DELAYED_CLOSE_ENTRY * PCM_DELAYED_CLOSE_ENTRY
FORCEINLINE VOID CmpAcquireKcbLockExclusiveByKey(IN ULONG ConvKey)
Definition: cm_x.h:143
FORCEINLINE VOID CmpReleaseKcbLockByKey(ULONG ConvKey)
Definition: cm_x.h:212
VOID NTAPI CmpFreeDelayItem(PVOID Entry)
Definition: cmalloc.c:267
ULONG CmpDelayedCloseSize
Definition: cmdelay.c:19
VOID NTAPI CmpArmDelayedCloseTimer(VOID)
Definition: cmdelay.c:335
LIST_ENTRY CmpDelayedLRUListHead
Definition: cmdelay.c:24
KGUARDED_MUTEX CmpDelayedCloseTableLock
Definition: cmdelay.c:21
ULONG CmpDelayedCloseElements
Definition: cmdelay.c:20
VOID NTAPI CmpCleanUpKcbCacheWithLock(IN PCM_KEY_CONTROL_BLOCK Kcb, IN BOOLEAN LockHeldExclusively)
Definition: cmkcbncb.c:476
VOID NTAPI CmpUnlockRegistry(VOID)
Definition: cmsysini.c:2056
VOID NTAPI CmpLockRegistry(VOID)
Definition: cmsysini.c:1970
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define InsertHeadList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveTailList(ListHead)
Definition: env_spec_w32.h:975
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
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
Definition: cm.h:369
LIST_ENTRY DelayedLRUList
Definition: cm.h:370
PCM_KEY_CONTROL_BLOCK KeyControlBlock
Definition: cm.h:371
ULONG DelayedCloseIndex
Definition: cm.h:278
ULONG RefCount
Definition: cm.h:272
PVOID DelayCloseEntry
Definition: cm.h:308
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
int32_t * PLONG
Definition: typedefs.h:58
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59

◆ CmpAddToDelayedClose()

VOID NTAPI CmpAddToDelayedClose ( IN PCM_KEY_CONTROL_BLOCK  Kcb,
IN BOOLEAN  LockHeldExclusively 
)

Definition at line 350 of file cmdelay.c.

352{
353 ULONG i;
354 ULONG OldRefCount, NewRefCount;
356 PAGED_CODE();
357
358 /* Sanity check */
360
361 /* Make sure it's valid */
362 if (Kcb->DelayedCloseIndex != CmpDelayedCloseSize) ASSERT(FALSE);
363
364 /* Sanity checks */
365 ASSERT(Kcb->RefCount == 0);
366 ASSERT(IsListEmpty(&Kcb->KeyBodyListHead) == TRUE);
367 for (i = 0; i < 4; i++) ASSERT(Kcb->KeyBodyArray[i] == NULL);
368
369 /* Allocate a delay item */
371 if (!Entry)
372 {
373 /* Cleanup immediately */
374 CmpCleanUpKcbCacheWithLock(Kcb, LockHeldExclusively);
375 return;
376 }
377
378 /* Sanity check */
379 if (Kcb->InDelayClose) ASSERT(FALSE);
380
381 /* Get the previous reference count */
382 OldRefCount = *(PLONG)&Kcb->InDelayClose;
383 ASSERT(OldRefCount == 0);
384
385 /* Write the new one */
386 NewRefCount = 1;
387 if (InterlockedCompareExchange((PLONG)&Kcb->InDelayClose,
388 NewRefCount,
389 OldRefCount) != OldRefCount)
390 {
391 /* Sanity check */
392 ASSERT(FALSE);
393 }
394
395 /* Reset the delayed close index */
396 Kcb->DelayedCloseIndex = 0;
397
398 /* Set up the close entry */
399 Kcb->DelayCloseEntry = Entry;
400 Entry->KeyControlBlock = Kcb;
401
402 /* Increase the number of elements */
404
405 /* Acquire the delayed close table lock */
407
408 /* Insert the entry into the list */
409 InsertHeadList(&CmpDelayedLRUListHead, &Entry->DelayedLRUList);
410
411 /* Check if we need to enable anything */
414 {
415 /* Yes, we have too many elements to close, and no work item */
417 }
418
419 /* Release the table lock */
421}
#define InterlockedIncrement
Definition: armddk.h:53
#define CMP_ASSERT_KCB_LOCK(k)
Definition: cm_x.h:278
PVOID NTAPI CmpAllocateDelayItem(VOID)
Definition: cmalloc.c:199
#define TRUE
Definition: types.h:120
#define InterlockedCompareExchange
Definition: interlocked.h:104
base of all file and directory entries
Definition: entries.h:83

Referenced by CmpDereferenceKeyControlBlockWithLock().

◆ CmpArmDelayedCloseTimer()

VOID NTAPI CmpArmDelayedCloseTimer ( VOID  )

Definition at line 335 of file cmdelay.c.

336{
338 PAGED_CODE();
339
340 /* Set the worker active */
342
343 /* Setup the interval */
344 Timeout.QuadPart = CmpDelayCloseIntervalInSeconds * -10000000;
346}
KDPC CmpDelayCloseDpc
Definition: cmdelay.c:26
ULONG CmpDelayCloseIntervalInSeconds
Definition: cmdelay.c:25
KTIMER CmpDelayCloseTimer
Definition: cmdelay.c:27
static ULONG Timeout
Definition: ping.c:61
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281

Referenced by _Function_class_(), and CmpAddToDelayedClose().

◆ CmpDelayDerefKeyControlBlock()

VOID NTAPI CmpDelayDerefKeyControlBlock ( IN PCM_KEY_CONTROL_BLOCK  Kcb)

Definition at line 286 of file cmdelay.c.

287{
288 LONG OldRefCount, NewRefCount;
291 PAGED_CODE();
293 "%s - Dereferencing KCB: %p\n", __FUNCTION__, Kcb);
294
295 /* Get the previous reference count */
296 OldRefCount = *(PLONG)&Kcb->RefCount;
297 NewRefCount = OldRefCount - 1;
298 if (((NewRefCount & 0xFFFF) > 0) &&
299 (InterlockedCompareExchange((PLONG)&Kcb->RefCount,
300 NewRefCount,
301 OldRefCount) == OldRefCount))
302 {
303 /* KCB still had references, so we're done */
304 return;
305 }
306
307 /* Allocate a delay item */
309 if (!Entry) return;
310
311 /* Set the KCB */
312 Entry->Kcb = Kcb;
313
314 /* Acquire the delayed deref table lock */
316
317 /* Insert the entry into the list */
319
320 /* Check if we need to enable anything */
322 {
323 /* Yes, we have no work item, setup the interval */
325 Timeout.QuadPart = CmpDelayDerefKCBIntervalInSeconds * -10000000;
327 }
328
329 /* Release the table lock */
331}
#define CMTRACE(x, fmt,...)
Definition: cm.h:40
#define CM_REFERENCE_DEBUG
Definition: cm.h:26
KTIMER CmpDelayDerefKCBTimer
Definition: cmdelay.c:34
KGUARDED_MUTEX CmpDelayDerefKCBLock
Definition: cmdelay.c:29
ULONG CmpDelayDerefKCBIntervalInSeconds
Definition: cmdelay.c:32
BOOLEAN CmpDelayDerefKCBWorkItemActive
Definition: cmdelay.c:30
LIST_ENTRY CmpDelayDerefKCBListHead
Definition: cmdelay.c:31
KDPC CmpDelayDerefKCBDpc
Definition: cmdelay.c:33
#define __FUNCTION__
Definition: types.h:116
#define InsertTailList(ListHead, Entry)
if(dx< 0)
Definition: linetemp.h:194
long LONG
Definition: pedump.c:60

Referenced by CmpCleanUpKcbCacheWithLock(), CmpCleanUpKcbValueCache(), and CmpDeleteKeyObject().

◆ CmpInitDelayDerefKCBEngine()

VOID NTAPI CmpInitDelayDerefKCBEngine ( VOID  )

Definition at line 268 of file cmdelay.c.

269{
270 /* Initialize lock and list */
273
274 /* Setup the work item */
276 CmpDelayDerefKCBWorker,
277 NULL);
278
279 /* Setup the DPC and timer for it */
280 KeInitializeDpc(&CmpDelayDerefKCBDpc, CmpDelayDerefKCBDpcRoutine, NULL);
282}
WORK_QUEUE_ITEM CmpDelayDerefKCBWorkItem
Definition: cmdelay.c:17
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265

Referenced by CmInitSystem1().

◆ CmpInitializeDelayedCloseTable()

VOID NTAPI CmpInitializeDelayedCloseTable ( VOID  )

Definition at line 191 of file cmdelay.c.

192{
193
194 /* Setup the delayed close lock */
196
197 /* Setup the work item */
198 ExInitializeWorkItem(&CmpDelayCloseWorkItem, CmpDelayCloseWorker, NULL);
199
200 /* Setup the list head */
202
203 /* Setup the DPC and its timer */
204 KeInitializeDpc(&CmpDelayCloseDpc, CmpDelayCloseDpcRoutine, NULL);
206}

Referenced by CmpInitializeCache().

◆ CmpRemoveFromDelayedClose()

VOID NTAPI CmpRemoveFromDelayedClose ( IN PCM_KEY_CONTROL_BLOCK  Kcb)

Definition at line 425 of file cmdelay.c.

426{
428 ULONG NewRefCount, OldRefCount;
429 PAGED_CODE();
430
431 /* Sanity checks */
433 if (Kcb->DelayedCloseIndex == CmpDelayedCloseSize) ASSERT(FALSE);
434
435 /* Get the entry and lock the table */
436 Entry = Kcb->DelayCloseEntry;
437 ASSERT(Entry);
439
440 /* Remove the entry */
441 RemoveEntryList(&Entry->DelayedLRUList);
442
443 /* Release the lock */
445
446 /* Free the entry */
448
449 /* Reduce the number of elements */
451
452 /* Sanity check */
453 if (!Kcb->InDelayClose) ASSERT(FALSE);
454
455 /* Get the previous reference count */
456 OldRefCount = *(PLONG)&Kcb->InDelayClose;
457 ASSERT(OldRefCount == 1);
458
459 /* Write the new one */
460 NewRefCount = 0;
461 if (InterlockedCompareExchange((PLONG)&Kcb->InDelayClose,
462 NewRefCount,
463 OldRefCount) != OldRefCount)
464 {
465 /* Sanity check */
466 ASSERT(FALSE);
467 }
468
469 /* Remove the link to the entry */
470 Kcb->DelayCloseEntry = NULL;
471
472 /* Set new delay size and remove the delete flag */
473 Kcb->DelayedCloseIndex = CmpDelayedCloseSize;
474}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986

Referenced by CmpEnumerateOpenSubKeys(), CmpLookInCache(), and CmpReferenceKeyControlBlock().

Variable Documentation

◆ CmpDelayCloseDpc

KDPC CmpDelayCloseDpc

Definition at line 26 of file cmdelay.c.

Referenced by CmpArmDelayedCloseTimer(), and CmpInitializeDelayedCloseTable().

◆ CmpDelayCloseIntervalInSeconds

ULONG CmpDelayCloseIntervalInSeconds = 5

Definition at line 25 of file cmdelay.c.

Referenced by CmpArmDelayedCloseTimer().

◆ CmpDelayCloseTimer

KTIMER CmpDelayCloseTimer

Definition at line 27 of file cmdelay.c.

Referenced by CmpArmDelayedCloseTimer(), and CmpInitializeDelayedCloseTable().

◆ CmpDelayCloseWorkItem

WORK_QUEUE_ITEM CmpDelayCloseWorkItem

Definition at line 23 of file cmdelay.c.

Referenced by _Function_class_(), and CmpInitializeDelayedCloseTable().

◆ CmpDelayCloseWorkItemActive

BOOLEAN CmpDelayCloseWorkItemActive

Definition at line 22 of file cmdelay.c.

Referenced by _Function_class_(), CmpAddToDelayedClose(), and CmpArmDelayedCloseTimer().

◆ CmpDelayDerefKCBDpc

KDPC CmpDelayDerefKCBDpc

Definition at line 33 of file cmdelay.c.

Referenced by CmpDelayDerefKeyControlBlock(), and CmpInitDelayDerefKCBEngine().

◆ CmpDelayDerefKCBIntervalInSeconds

ULONG CmpDelayDerefKCBIntervalInSeconds = 5

Definition at line 32 of file cmdelay.c.

Referenced by CmpDelayDerefKeyControlBlock().

◆ CmpDelayDerefKCBListHead

LIST_ENTRY CmpDelayDerefKCBListHead

Definition at line 31 of file cmdelay.c.

Referenced by CmpDelayDerefKeyControlBlock(), and CmpInitDelayDerefKCBEngine().

◆ CmpDelayDerefKCBLock

KGUARDED_MUTEX CmpDelayDerefKCBLock

Definition at line 29 of file cmdelay.c.

Referenced by CmpDelayDerefKeyControlBlock(), and CmpInitDelayDerefKCBEngine().

◆ CmpDelayDerefKCBTimer

KTIMER CmpDelayDerefKCBTimer

Definition at line 34 of file cmdelay.c.

Referenced by CmpDelayDerefKeyControlBlock(), and CmpInitDelayDerefKCBEngine().

◆ CmpDelayDerefKCBWorkItem

WORK_QUEUE_ITEM CmpDelayDerefKCBWorkItem

Definition at line 17 of file cmdelay.c.

Referenced by CmpInitDelayDerefKCBEngine().

◆ CmpDelayDerefKCBWorkItemActive

BOOLEAN CmpDelayDerefKCBWorkItemActive

Definition at line 30 of file cmdelay.c.

Referenced by CmpDelayDerefKeyControlBlock().

◆ CmpDelayedCloseElements

ULONG CmpDelayedCloseElements

Definition at line 20 of file cmdelay.c.

Referenced by _Function_class_(), CmpAddToDelayedClose(), and CmpRemoveFromDelayedClose().

◆ CmpDelayedCloseSize

◆ CmpDelayedCloseTableLock

KGUARDED_MUTEX CmpDelayedCloseTableLock

◆ CmpDelayedLRUListHead

LIST_ENTRY CmpDelayedLRUListHead