/* Performs an atomic decrement operation for semaphore. The compare exchange operation must be performed using MP safe mechanisms. */
VOID LibWaitForSemaphore(IN OUT volatile UINT32 *Sem)
/* Performs an atomic decrement operation for semaphore. The compare exchange operation must be performed using MP safe mechanisms. */
VOID LibWaitForSemaphore(IN OUT volatile UINT32 *Sem)
{
  UINT32  Value;
  do {
    Value = *Sem;
  } while (Value == 0 ||
           InterlockedCompareExchange32 (
             Sem,
             Value,
             Value - 1
             ) != Value);
}