- Small semaphore code simplification/optimization.
Modified: trunk/reactos/ntoskrnl/ke/kthread.c
Modified: trunk/reactos/ntoskrnl/ke/sem.c

Modified: trunk/reactos/ntoskrnl/ke/kthread.c
--- trunk/reactos/ntoskrnl/ke/kthread.c	2005-10-02 08:22:49 UTC (rev 18201)
+++ trunk/reactos/ntoskrnl/ke/kthread.c	2005-10-02 08:31:45 UTC (rev 18202)
@@ -473,7 +473,10 @@
     {
         /* Get the Mutant */
         Mutant = CONTAINING_RECORD(NextEntry, KMUTANT, MutantListEntry);
-        DPRINT1("Mutant: %p. Type, Size %x %x\n", Mutant, Mutant->Header.Type, Mutant->Header.Size);
+        DPRINT1("Mutant: %p. Type, Size %x %x\n",
+                 Mutant,
+                 Mutant->Header.Type,
+                 Mutant->Header.Size);
 
         /* Make sure it's not terminating with APCs off */
         if (Mutant->ApcDisable)

Modified: trunk/reactos/ntoskrnl/ke/sem.c
--- trunk/reactos/ntoskrnl/ke/sem.c	2005-10-02 08:22:49 UTC (rev 18201)
+++ trunk/reactos/ntoskrnl/ke/sem.c	2005-10-02 08:31:45 UTC (rev 18202)
@@ -1,11 +1,10 @@
-/* $Id$
- *
+/*
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/ke/sem.c
  * PURPOSE:         Implements kernel semaphores
- *
- * PROGRAMMERS:     David Welch (welch@mcmail.com)
+ * PROGRAMMERS:     Alex Ionescu (alex@relsoft.net)
+ *                  David Welch (welch@mcmail.com)
  */
 
 /* INCLUDES *****************************************************************/
@@ -25,13 +24,12 @@
                       LONG Count,
                       LONG Limit)
 {
-
     DPRINT("KeInitializeSemaphore Sem: %x\n", Semaphore);
 
     /* Simply Initialize the Header */
     KeInitializeDispatcherHeader(&Semaphore->Header,
                                  SemaphoreObject,
-                                 sizeof(KSEMAPHORE)/sizeof(ULONG),
+                                 sizeof(KSEMAPHORE) / sizeof(ULONG),
                                  Count);
 
     /* Set the Limit */
@@ -46,7 +44,7 @@
 KeReadStateSemaphore(PKSEMAPHORE Semaphore)
 {
     /* Just return the Signal State */
-    return(Semaphore->Header.SignalState);
+    return Semaphore->Header.SignalState;
 }
 
 /*
@@ -77,9 +75,8 @@
                    KPRIORITY Increment,
                    LONG Adjustment,
                    BOOLEAN Wait)
-
 {
-    ULONG InitialState;
+    LONG InitialState, ULONG State;
     KIRQL OldIrql;
     PKTHREAD CurrentThread;
 
@@ -92,36 +89,36 @@
     /* Lock the Dispatcher Database */
     OldIrql = KeAcquireDispatcherDatabaseLock();
 
-    /* Save the Old State */
+    /* Save the Old State and get new one */
     InitialState = Semaphore->Header.SignalState;
+    State = InitialState + Adjustement;
 
     /* Check if the Limit was exceeded */
-    if (Semaphore->Limit < (LONG) InitialState + Adjustment ||
-        InitialState > InitialState + Adjustment) {
-
+    if ((Semaphore->Limit < State) || (InitialState > State))
+    {
         /* Raise an error if it was exceeded */
         KeReleaseDispatcherDatabaseLock(OldIrql);
         ExRaiseStatus(STATUS_SEMAPHORE_LIMIT_EXCEEDED);
     }
 
     /* Now set the new state */
-    Semaphore->Header.SignalState += Adjustment;
+    Semaphore->Header.SignalState = State;
 
     /* Check if we should wake it */
-    if (InitialState == 0 && !IsListEmpty(&Semaphore->Header.WaitListHead)) {
-
+    if (!(InitialState) && !(IsListEmpty(&Semaphore->Header.WaitListHead))
+    {
         /* Wake the Semaphore */
         KiWaitTest(&Semaphore->Header, Increment);
     }
 
     /* If the Wait is true, then return with a Wait and don't unlock the Dispatcher Database */
-    if (Wait == FALSE) {
-
+    if (Wait == FALSE)
+    {
         /* Release the Lock */
         KeReleaseDispatcherDatabaseLock(OldIrql);
-
-    } else {
-
+    }
+    else
+    {
         /* Set a wait */
         CurrentThread = KeGetCurrentThread();
         CurrentThread->WaitNext = TRUE;