Author: ion
Date: Fri Jul 8 21:19:38 2011
New Revision: 52576
URL:
http://svn.reactos.org/svn/reactos?rev=52576&view=rev
Log:
[NTDLL]: Simplify LdrLockLoaderLock, fix its prototype, add an ASSERT, move cookie
generation into its own inline.
Modified:
trunk/reactos/dll/ntdll/ldr/ldrapi.c
Modified: trunk/reactos/dll/ntdll/ldr/ldrapi.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrapi.c?rev…
==============================================================================
--- trunk/reactos/dll/ntdll/ldr/ldrapi.c [iso-8859-1] (original)
+++ trunk/reactos/dll/ntdll/ldr/ldrapi.c [iso-8859-1] Fri Jul 8 21:19:38 2011
@@ -21,6 +21,15 @@
/* FUNCTIONS *****************************************************************/
+ULONG_PTR
+FORCEINLINE
+LdrpMakeCookie(VOID)
+{
+ /* Generate a cookie */
+ return (((ULONG_PTR)NtCurrentTeb()->RealClientId.UniqueThread & 0xFFF)
<< 16) |
+ _InterlockedIncrement(&LdrpLoaderLockAcquisitonCount);
+}
+
/*
* @implemented
*/
@@ -99,17 +108,16 @@
NTSTATUS
NTAPI
LdrLockLoaderLock(IN ULONG Flags,
- OUT PULONG Result OPTIONAL,
- OUT PULONG Cookie OPTIONAL)
-{
- LONG OldCount;
+ OUT PULONG Disposition OPTIONAL,
+ OUT PULONG_PTR Cookie OPTIONAL)
+{
NTSTATUS Status = STATUS_SUCCESS;
BOOLEAN InInit = LdrpInLdrInit;
- DPRINT("LdrLockLoaderLock(%x %p %p)\n", Flags, Result, Cookie);
+ DPRINT("LdrLockLoaderLock(%x %p %p)\n", Flags, Disposition, Cookie);
/* Zero out the outputs */
- if (Result) *Result = 0;
+ if (Disposition) *Disposition = LDR_LOCK_LOADER_LOCK_DISPOSITION_INVALID;
if (Cookie) *Cookie = 0;
/* Validate the flags */
@@ -140,9 +148,12 @@
/* A normal failure */
return STATUS_INVALID_PARAMETER_3;
}
+
+ /* Do or Do Not. There is no Try */
+ ASSERT((Disposition != NULL) || !(Flags & LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY));
/* If the flag is set, make sure we have a valid pointer to use */
- if ((Flags & LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY) && !(Result))
+ if ((Flags & LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY) && !(Disposition))
{
/* No pointer to return the data to */
if (Flags & LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS)
@@ -168,13 +179,13 @@
if (!RtlTryEnterCriticalSection(&LdrpLoaderLock))
{
/* It's locked */
- *Result = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_NOT_ACQUIRED;
- goto Quickie;
+ *Disposition = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_NOT_ACQUIRED;
}
else
{
/* It worked */
- *Result = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED;
+ *Disposition = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED;
+ *Cookie = LdrpMakeCookie();
}
}
else
@@ -183,14 +194,9 @@
RtlEnterCriticalSection(&LdrpLoaderLock);
/* See if result was requested */
- if (Result) *Result = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED;
- }
-
- /* Increase the acquisition count */
- OldCount = _InterlockedIncrement(&LdrpLoaderLockAcquisitonCount);
-
- /* Generate a cookie */
- *Cookie = (((ULONG)NtCurrentTeb()->RealClientId.UniqueThread & 0xFFF)
<< 16) | OldCount;
+ if (Disposition) *Disposition =
LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED;
+ *Cookie = LdrpMakeCookie();
+ }
}
else
{
@@ -204,13 +210,13 @@
if (!RtlTryEnterCriticalSection(&LdrpLoaderLock))
{
/* It's locked */
- *Result = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_NOT_ACQUIRED;
- _SEH2_YIELD(return STATUS_SUCCESS);
+ *Disposition = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_NOT_ACQUIRED;
}
else
{
/* It worked */
- *Result = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED;
+ *Disposition = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED;
+ *Cookie = LdrpMakeCookie();
}
}
else
@@ -219,14 +225,9 @@
RtlEnterCriticalSection(&LdrpLoaderLock);
/* See if result was requested */
- if (Result) *Result = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED;
- }
-
- /* Increase the acquisition count */
- OldCount = _InterlockedIncrement(&LdrpLoaderLockAcquisitonCount);
-
- /* Generate a cookie */
- *Cookie = (((ULONG)NtCurrentTeb()->RealClientId.UniqueThread & 0xFFF)
<< 16) | OldCount;
+ if (Disposition) *Disposition =
LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED;
+ *Cookie = LdrpMakeCookie();
+ }
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
@@ -236,7 +237,7 @@
_SEH2_END;
}
-Quickie:
+ /* Return status */
return Status;
}