Sync with trunk r63174.
[reactos.git] / win32ss / gdi / eng / semaphor.c
index cb15505..9e16965 100644 (file)
@@ -8,26 +8,28 @@
  */
 HSEMAPHORE
 APIENTRY
-EngCreateSemaphore ( VOID )
+EngCreateSemaphore(VOID)
 {
-  // www.osr.com/ddk/graphics/gdifncs_95lz.htm
-  PERESOURCE psem = ExAllocatePoolWithTag( NonPagedPool, sizeof(ERESOURCE), GDITAG_SEMAPHORE );
-  if ( !psem )
-    return NULL;
-  if ( !NT_SUCCESS(ExInitializeResourceLite ( psem )) )
-  {
-    ExFreePoolWithTag ( psem, GDITAG_SEMAPHORE );
-    return NULL;
-  }
-  return (HSEMAPHORE)psem;
+    // www.osr.com/ddk/graphics/gdifncs_95lz.htm
+    PERESOURCE psem = ExAllocatePoolWithTag(NonPagedPool, sizeof(ERESOURCE), GDITAG_SEMAPHORE);
+    if (!psem)
+        return NULL;
+
+    if (!NT_SUCCESS(ExInitializeResourceLite(psem)))
+    {
+        ExFreePoolWithTag ( psem, GDITAG_SEMAPHORE );
+        return NULL;
+    }
+
+    return (HSEMAPHORE)psem;
 }
 
 VOID
 FASTCALL
-IntGdiAcquireSemaphore ( HSEMAPHORE hsem )
+IntGdiAcquireSemaphore(HSEMAPHORE hsem)
 {
-  KeEnterCriticalRegion();
-  ExAcquireResourceExclusiveLite ( (PERESOURCE)hsem, TRUE );
+    KeEnterCriticalRegion();
+    ExAcquireResourceExclusiveLite ((PERESOURCE)hsem, TRUE);
 }
 
 /*
@@ -35,14 +37,14 @@ IntGdiAcquireSemaphore ( HSEMAPHORE hsem )
  */
 VOID
 APIENTRY
-EngAcquireSemaphore ( IN HSEMAPHORE hsem )
+EngAcquireSemaphore(IN HSEMAPHORE hsem)
 {
-  // www.osr.com/ddk/graphics/gdifncs_14br.htm
-  PTHREADINFO W32Thread;
-  ASSERT(hsem);
-  IntGdiAcquireSemaphore ( hsem );
-  W32Thread = PsGetThreadWin32Thread(PsGetCurrentThread());
-  if (W32Thread) W32Thread->dwEngAcquireCount++;
+    // www.osr.com/ddk/graphics/gdifncs_14br.htm
+    PTHREADINFO W32Thread;
+    ASSERT(hsem);
+    IntGdiAcquireSemaphore(hsem);
+    W32Thread = PsGetThreadWin32Thread(PsGetCurrentThread());
+    if (W32Thread) W32Thread->dwEngAcquireCount++;
 }
 
 
@@ -50,8 +52,8 @@ VOID
 FASTCALL
 IntGdiReleaseSemaphore ( HSEMAPHORE hsem )
 {
-  ExReleaseResourceLite ( (PERESOURCE)hsem );
-  KeLeaveCriticalRegion();
+    ExReleaseResourceLite((PERESOURCE)hsem);
+    KeLeaveCriticalRegion();
 }
 
 /*
@@ -61,12 +63,12 @@ VOID
 APIENTRY
 EngReleaseSemaphore ( IN HSEMAPHORE hsem )
 {
-  // www.osr.com/ddk/graphics/gdifncs_5u3r.htm
-  PTHREADINFO W32Thread;
-  ASSERT(hsem);
-  W32Thread = PsGetThreadWin32Thread(PsGetCurrentThread());
-  if (W32Thread) --W32Thread->dwEngAcquireCount;
-  IntGdiReleaseSemaphore ( hsem );
+    // www.osr.com/ddk/graphics/gdifncs_5u3r.htm
+    PTHREADINFO W32Thread;
+    ASSERT(hsem);
+    W32Thread = PsGetThreadWin32Thread(PsGetCurrentThread());
+    if (W32Thread) --W32Thread->dwEngAcquireCount;
+    IntGdiReleaseSemaphore(hsem);
 }
 
 VOID
@@ -89,12 +91,11 @@ VOID
 APIENTRY
 EngDeleteSemaphore ( IN HSEMAPHORE hsem )
 {
-  // www.osr.com/ddk/graphics/gdifncs_13c7.htm
-  ASSERT ( hsem );
-
-  ExDeleteResourceLite((PERESOURCE)hsem);
+    // www.osr.com/ddk/graphics/gdifncs_13c7.htm
+    ASSERT(hsem);
 
-  ExFreePoolWithTag( (PVOID)hsem, GDITAG_SEMAPHORE);
+    ExDeleteResourceLite((PERESOURCE)hsem);
+    ExFreePoolWithTag((PVOID)hsem, GDITAG_SEMAPHORE);
 }
 
 /*
@@ -104,9 +105,9 @@ BOOL
 APIENTRY
 EngIsSemaphoreOwned ( IN HSEMAPHORE hsem )
 {
-  // www.osr.com/ddk/graphics/gdifncs_6wmf.htm
-  ASSERT(hsem);
-  return (((PERESOURCE)hsem)->ActiveCount > 0);
+    // www.osr.com/ddk/graphics/gdifncs_6wmf.htm
+    ASSERT(hsem);
+    return (((PERESOURCE)hsem)->ActiveCount > 0);
 }
 
 /*
@@ -116,9 +117,9 @@ BOOL
 APIENTRY
 EngIsSemaphoreOwnedByCurrentThread ( IN HSEMAPHORE hsem )
 {
-  // www.osr.com/ddk/graphics/gdifncs_9yxz.htm
-  ASSERT(hsem);
-  return ExIsResourceAcquiredExclusiveLite ( (PERESOURCE)hsem );
+    // www.osr.com/ddk/graphics/gdifncs_9yxz.htm
+    ASSERT(hsem);
+    return ExIsResourceAcquiredExclusiveLite((PERESOURCE)hsem);
 }
 
 /*
@@ -126,32 +127,32 @@ EngIsSemaphoreOwnedByCurrentThread ( IN HSEMAPHORE hsem )
  */
 BOOL APIENTRY
 EngInitializeSafeSemaphore(
-   OUT ENGSAFESEMAPHORE *Semaphore)
+    OUT ENGSAFESEMAPHORE *Semaphore)
 {
-   HSEMAPHORE hSem;
-
-   if (InterlockedIncrement(&Semaphore->lCount) == 1)
-   {
-      /* Create the semaphore */
-      hSem = EngCreateSemaphore();
-      if (hSem == 0)
-      {
-         InterlockedDecrement(&Semaphore->lCount);
-         return FALSE;
-      }
-      /* FIXME: Not thread-safe! Check result of InterlockedCompareExchangePointer
-                and delete semaphore if already initialized! */
-      (void)InterlockedExchangePointer((volatile PVOID *)&Semaphore->hsem, hSem);
-   }
-   else
-   {
-      /* Wait for the other thread to create the semaphore */
-      ASSERT(Semaphore->lCount > 1);
-      ASSERT_IRQL_LESS_OR_EQUAL(PASSIVE_LEVEL);
-      while (Semaphore->hsem == NULL);
-   }
-
-   return TRUE;
+    HSEMAPHORE hSem;
+
+    if (InterlockedIncrement(&Semaphore->lCount) == 1)
+    {
+        /* Create the semaphore */
+        hSem = EngCreateSemaphore();
+        if (hSem == 0)
+        {
+            InterlockedDecrement(&Semaphore->lCount);
+            return FALSE;
+        }
+        /* FIXME: Not thread-safe! Check result of InterlockedCompareExchangePointer
+                  and delete semaphore if already initialized! */
+        (void)InterlockedExchangePointer((volatile PVOID *)&Semaphore->hsem, hSem);
+    }
+    else
+    {
+        /* Wait for the other thread to create the semaphore */
+        ASSERT(Semaphore->lCount > 1);
+        ASSERT_IRQL_LESS_OR_EQUAL(PASSIVE_LEVEL);
+        while (Semaphore->hsem == NULL);
+    }
+
+    return TRUE;
 }
 
 /*
@@ -159,14 +160,14 @@ EngInitializeSafeSemaphore(
  */
 VOID APIENTRY
 EngDeleteSafeSemaphore(
-   IN OUT ENGSAFESEMAPHORE *Semaphore)
+    IN OUT ENGSAFESEMAPHORE *Semaphore)
 {
-   if (InterlockedDecrement(&Semaphore->lCount) == 0)
-   {
-      /* FIXME: Not thread-safe! Use result of InterlockedCompareExchangePointer! */
-      EngDeleteSemaphore(Semaphore->hsem);
-      (void)InterlockedExchangePointer((volatile PVOID *)&Semaphore->hsem, NULL);
-   }
+    if (InterlockedDecrement(&Semaphore->lCount) == 0)
+    {
+        /* FIXME: Not thread-safe! Use result of InterlockedCompareExchangePointer! */
+        EngDeleteSemaphore(Semaphore->hsem);
+        (void)InterlockedExchangePointer((volatile PVOID *)&Semaphore->hsem, NULL);
+    }
 }
 
 /* EOF */