Author: dchapyshev
Date: Mon Sep 26 12:03:57 2016
New Revision: 72811

URL: http://svn.reactos.org/svn/reactos?rev=72811&view=rev
Log:
[NTOS:KE] Added *Thread versions of macros with ASSERT(_Thread == 
KeGetCurrentThread()). Use new macros in _KeAcquireGuardedMutex, 
_KeReleaseGuardedMutex, _KeTryToAcquireGuardedMutex. Thanks Alex!

Modified:
    trunk/reactos/ntoskrnl/include/internal/ke_x.h

Modified: trunk/reactos/ntoskrnl/include/internal/ke_x.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/ke_x.h?rev=72811&r1=72810&r2=72811&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ke_x.h      [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/ke_x.h      [iso-8859-1] Mon Sep 26 
12:03:57 2016
@@ -19,28 +19,32 @@
 //
 // Enters a Guarded Region
 //
+#define KeEnterGuardedRegionThread(_Thread)                                 \
+{                                                                           \
+    /* Sanity checks */                                                     \
+    ASSERT(KeGetCurrentIrql() <= APC_LEVEL);                                \
+    ASSERT(_Thread == KeGetCurrentThread());                                \
+    ASSERT((_Thread->SpecialApcDisable <= 0) &&                             \
+           (_Thread->SpecialApcDisable != -32768));                         \
+                                                                            \
+    /* Disable Special APCs */                                              \
+    _Thread->SpecialApcDisable--;                                           \
+}
+
 #define KeEnterGuardedRegion()                                              \
 {                                                                           \
     PKTHREAD _Thread = KeGetCurrentThread();                                \
-                                                                            \
+    KeEnterGuardedRegionThread(_Thread);                                    \
+}
+
+//
+// Leaves a Guarded Region
+//
+#define KeLeaveGuardedRegionThread(_Thread)                                 \
+{                                                                           \
     /* Sanity checks */                                                     \
     ASSERT(KeGetCurrentIrql() <= APC_LEVEL);                                \
-    ASSERT((_Thread->SpecialApcDisable <= 0) &&                             \
-           (_Thread->SpecialApcDisable != -32768));                         \
-                                                                            \
-    /* Disable Special APCs */                                              \
-    _Thread->SpecialApcDisable--;                                           \
-}
-
-//
-// Leaves a Guarded Region
-//
-#define KeLeaveGuardedRegion()                                              \
-{                                                                           \
-    PKTHREAD _Thread = KeGetCurrentThread();                                \
-                                                                            \
-    /* Sanity checks */                                                     \
-    ASSERT(KeGetCurrentIrql() <= APC_LEVEL);                                \
+    ASSERT(_Thread == KeGetCurrentThread());                                \
     ASSERT(_Thread->SpecialApcDisable < 0);                                 \
                                                                             \
     /* Leave region and check if APCs are OK now */                         \
@@ -56,29 +60,39 @@
     }                                                                       \
 }
 
+#define KeLeaveGuardedRegion()                                              \
+{                                                                           \
+    PKTHREAD _Thread = KeGetCurrentThread();                                \
+    KeLeaveGuardedRegionThread(_Thread);                                    \
+}
+
 //
 // Enters a Critical Region
 //
+#define KeEnterCriticalRegionThread(_Thread)                                \
+{                                                                           \
+    /* Sanity checks */                                                     \
+    ASSERT(_Thread == KeGetCurrentThread());                                \
+    ASSERT((_Thread->KernelApcDisable <= 0) &&                              \
+           (_Thread->KernelApcDisable != -32768));                          \
+                                                                            \
+    /* Disable Kernel APCs */                                               \
+    _Thread->KernelApcDisable--;                                            \
+}
+
 #define KeEnterCriticalRegion()                                             \
 {                                                                           \
     PKTHREAD _Thread = KeGetCurrentThread();                                \
-                                                                            \
+    KeEnterCriticalRegionThread(_Thread);                                   \
+}
+
+//
+// Leaves a Critical Region
+//
+#define KeLeaveCriticalRegionThread(_Thread)                                \
+{                                                                           \
     /* Sanity checks */                                                     \
-    ASSERT((_Thread->KernelApcDisable <= 0) &&                              \
-           (_Thread->KernelApcDisable != -32768));                          \
-                                                                            \
-    /* Disable Kernel APCs */                                               \
-    _Thread->KernelApcDisable--;                                            \
-}
-
-//
-// Leaves a Critical Region
-//
-#define KeLeaveCriticalRegion()                                             \
-{                                                                           \
-    PKTHREAD _Thread = KeGetCurrentThread();                                \
-                                                                            \
-    /* Sanity checks */                                                     \
+    ASSERT(_Thread == KeGetCurrentThread());                                \
     ASSERT(_Thread->KernelApcDisable < 0);                                  \
                                                                             \
     /* Enable Kernel APCs */                                                \
@@ -95,6 +109,12 @@
             KiCheckForKernelApcDelivery();                                  \
         }                                                                   \
     }                                                                       \
+}
+
+#define KeLeaveCriticalRegion()                                             \
+{                                                                           \
+    PKTHREAD _Thread = KeGetCurrentThread();                                \
+    KeLeaveCriticalRegionThread(_Thread);                                   \
 }
 
 #ifndef CONFIG_SMP
@@ -1559,7 +1579,7 @@
     ASSERT(GuardedMutex->Owner != Thread);
 
     /* Disable Special APCs */
-    KeEnterGuardedRegion();
+    KeEnterGuardedRegionThread(Thread);
 
     /* Remove the lock */
     if (!InterlockedBitTestAndReset(&GuardedMutex->Count, GM_LOCK_BIT_V))
@@ -1577,13 +1597,13 @@
 VOID
 _KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
 {
+    PKTHREAD Thread = KeGetCurrentThread();
     LONG OldValue, NewValue;
 
     /* Sanity checks */
     ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
     ASSERT(GuardedMutex->Owner == KeGetCurrentThread());
-    ASSERT(KeGetCurrentThread()->SpecialApcDisable ==
-           GuardedMutex->SpecialApcDisable);
+    ASSERT(Thread->SpecialApcDisable == GuardedMutex->SpecialApcDisable);
 
     /* Destroy the Owner */
     GuardedMutex->Owner = NULL;
@@ -1613,7 +1633,7 @@
     }
 
     /* Re-enable APCs */
-    KeLeaveGuardedRegion();
+    KeLeaveGuardedRegionThread(Thread);
 }
 
 FORCEINLINE
@@ -1623,13 +1643,13 @@
     PKTHREAD Thread = KeGetCurrentThread();
 
     /* Block APCs */
-    KeEnterGuardedRegion();
+    KeEnterGuardedRegionThread(Thread);
 
     /* Remove the lock */
     if (!InterlockedBitTestAndReset(&GuardedMutex->Count, GM_LOCK_BIT_V))
     {
         /* Re-enable APCs */
-        KeLeaveGuardedRegion();
+        KeLeaveGuardedRegionThread(Thread);
         YieldProcessor();
 
         /* Return failure */


Reply via email to