improved PhfSetEvent

git-svn-id: svn://svn.code.sf.net/p/processhacker/code@3490 21ef857c-d57f-4fe0-8362-d861dc6d29cd
This commit is contained in:
wj32
2010-08-10 08:53:17 +00:00
parent f422617141
commit ac4c19f747
4 changed files with 14 additions and 24 deletions
+1
View File
@@ -396,6 +396,7 @@ FORCEINLINE VOID PhReleaseMutex(
// event
#define PH_EVENT_SET 0x1
#define PH_EVENT_SET_SHIFT 0
#define PH_EVENT_REFCOUNT_SHIFT 1
#define PH_EVENT_REFCOUNT_INC 0x2
+1 -1
View File
@@ -98,7 +98,7 @@ FORCEINLINE BOOLEAN PhTryAcquireResourceLockExclusive(
__inout PPH_RESOURCE_LOCK Lock
)
{
if (!_interlockedbittestandset(&Lock->Value, PH_RESOURCE_LOCK_OWNED_SHIFT))
if (!_interlockedbittestandset((PLONG)&Lock->Value, PH_RESOURCE_LOCK_OWNED_SHIFT))
{
return TRUE;
}
+1 -1
View File
@@ -209,7 +209,7 @@ FORCEINLINE BOOLEAN PhTryAcquireQueuedLockExclusive(
if (!_interlockedbittestandset64((PLONG64)&QueuedLock->Value, PH_QUEUED_LOCK_OWNED_SHIFT))
#endif
{
return TRUE;
return TRUE;
}
else
{
+11 -22
View File
@@ -71,32 +71,21 @@ VOID FASTCALL PhfSetEvent(
__inout PPH_EVENT Event
)
{
ULONG value;
HANDLE eventHandle;
// Try to set the bit.
do
// Only proceed if the event isn't set already.
if (!_interlockedbittestandset((PLONG)&Event->Value, PH_EVENT_SET_SHIFT))
{
value = Event->Value;
// Do an up-to-date read.
eventHandle = *(volatile HANDLE *)&Event->EventHandle;
// Has the event already been set?
if (value & PH_EVENT_SET)
return;
} while (_InterlockedCompareExchange(
&Event->Value,
value + PH_EVENT_SET,
value
) != value);
if (eventHandle)
{
NtSetEvent(eventHandle, NULL);
}
// Do an up-to-date read.
eventHandle = *(volatile HANDLE *)(&Event->EventHandle);
if (eventHandle)
{
NtSetEvent(eventHandle, NULL);
PhpDereferenceEvent(Event);
}
PhpDereferenceEvent(Event);
}
/**
@@ -134,7 +123,7 @@ BOOLEAN FASTCALL PhfWaitForEvent(
// Prevent the event from being invalidated.
PhpReferenceEvent(Event);
eventHandle = *(volatile HANDLE *)(&Event->EventHandle);
eventHandle = *(volatile HANDLE *)&Event->EventHandle;
// Don't bother creating an event if we already have one.
if (!eventHandle)
@@ -156,7 +145,7 @@ BOOLEAN FASTCALL PhfWaitForEvent(
// Essential: check the event one last time to see if
// it is set.
if (!(*(volatile ULONG *)(&Event->Value) & PH_EVENT_SET))
if (!(*(volatile ULONG *)&Event->Value & PH_EVENT_SET))
{
result = NtWaitForSingleObject(Event->EventHandle, FALSE, Timeout) == STATUS_WAIT_0;
}