One could have the impression that I am bored ;-)
Modified: trunk/reactos/ntoskrnl/ex/power.c
_____
Modified: trunk/reactos/ntoskrnl/ex/power.c
--- trunk/reactos/ntoskrnl/ex/power.c 2005-02-19 14:30:32 UTC (rev
13643)
+++ trunk/reactos/ntoskrnl/ex/power.c 2005-02-19 16:36:51 UTC (rev
13644)
@@ -168,7 +168,9 @@
"Just go forward in all your beliefs, and prove to me that I am
not mistaken in mine.\n",
"Lowest possible energy state reached! Switch off now to achive
a Bose-Einstein condensate.\n",
"Hasta la vista, BABY!\n",
- "They live, we sleep!\n"
+ "They live, we sleep!\n",
+ "I have come here to chew bubble gum and kick ass.\n"
+ "And I'm all out of bubble gum!\n"
};
LARGE_INTEGER Now;
revert my changes to RtlTryEnterCriticalSection()
Modified: trunk/reactos/lib/ntdll/rtl/critical.c
_____
Modified: trunk/reactos/lib/ntdll/rtl/critical.c
--- trunk/reactos/lib/ntdll/rtl/critical.c 2005-02-19 13:44:56 UTC
(rev 13642)
+++ trunk/reactos/lib/ntdll/rtl/critical.c 2005-02-19 14:30:32 UTC
(rev 13643)
@@ -360,29 +360,29 @@
* None
*
*--*/
-BOOLEAN
+BOOLEAN
STDCALL
RtlTryEnterCriticalSection(
PRTL_CRITICAL_SECTION CriticalSection)
-{
+{
/* Try to take control */
- if (InterlockedCompareExchange(&CriticalSection->LockCount, 0, -1)
== -1) {
+ if (InterlockedCompareExchange(&CriticalSection->LockCount,
+ 0,
+ -1) == -1) {
- /* It's ours. Changing this information does not have to be
serialized
- because we just obtained the lock. */
+ /* It's ours */
CriticalSection->OwningThread =
NtCurrentTeb()->Cid.UniqueThread;
CriticalSection->RecursionCount = 1;
return TRUE;
-
+
} else if (CriticalSection->OwningThread ==
NtCurrentTeb()->Cid.UniqueThread) {
-
- /* It's already ours, just increment the recursion counter.
This doesn't
- have to be serialized because only the thread who already
holds the
- lock can do this. */
+
+ /* It's already ours */
+ InterlockedIncrement(&CriticalSection->LockCount);
CriticalSection->RecursionCount++;
return TRUE;
}
-
+
/* It's not ours */
return FALSE;
}
don't increment the lock count twice in RtlTryEnterCriticalSection() and
added some more comments
Modified: trunk/reactos/lib/ntdll/rtl/critical.c
_____
Modified: trunk/reactos/lib/ntdll/rtl/critical.c
--- trunk/reactos/lib/ntdll/rtl/critical.c 2005-02-19 13:13:17 UTC
(rev 13641)
+++ trunk/reactos/lib/ntdll/rtl/critical.c 2005-02-19 13:44:56 UTC
(rev 13642)
@@ -305,27 +305,33 @@
RtlLeaveCriticalSection(
PRTL_CRITICAL_SECTION CriticalSection)
{
+#ifndef NDEBUG
HANDLE Thread = (HANDLE)NtCurrentTeb()->Cid.UniqueThread;
+ /* In win this case isn't checked. However it's a valid check so it
should only
+ be performed in debug builds! */
if (Thread != CriticalSection->OwningThread)
{
DPRINT1("Releasing critical section not owned!\n");
- /* FIXME: raise exception */
return STATUS_INVALID_PARAMETER;
}
+#endif
- /* Decrease the Recursion Count */
+ /* Decrease the Recursion Count. No need to do this atomically
because only
+ the thread who holds the lock can call this function (unless the
program
+ is totally screwed... */
if (--CriticalSection->RecursionCount) {
- /* Someone still owns us, but we are free */
+ /* Someone still owns us, but we are free. This needs to be
done atomically. */
InterlockedDecrement(&CriticalSection->LockCount);
} else {
- /* Nobody owns us anymore */
+ /* Nobody owns us anymore. No need to do this atomically. See
comment
+ above. */
CriticalSection->OwningThread = 0;
- /* Was someone wanting us? */
+ /* Was someone wanting us? This needs to be done atomically. */
if (InterlockedDecrement(&CriticalSection->LockCount) >= 0) {
/* Let him have us */
@@ -360,19 +366,19 @@
PRTL_CRITICAL_SECTION CriticalSection)
{
/* Try to take control */
- if (InterlockedCompareExchange(&CriticalSection->LockCount,
- 0,
- -1) == -1) {
+ if (InterlockedCompareExchange(&CriticalSection->LockCount, 0, -1)
== -1) {
- /* It's ours */
+ /* It's ours. Changing this information does not have to be
serialized
+ because we just obtained the lock. */
CriticalSection->OwningThread =
NtCurrentTeb()->Cid.UniqueThread;
CriticalSection->RecursionCount = 1;
return TRUE;
} else if (CriticalSection->OwningThread ==
NtCurrentTeb()->Cid.UniqueThread) {
- /* It's already ours */
- InterlockedIncrement(&CriticalSection->LockCount);
+ /* It's already ours, just increment the recursion counter.
This doesn't
+ have to be serialized because only the thread who already
holds the
+ lock can do this. */
CriticalSection->RecursionCount++;
return TRUE;
}
fixed RtlEnterCriticalSection not to fail on wrong assumptions and added
comment on why the debug message "Critical section not initialized
(guess)" is wrong
Modified: trunk/reactos/lib/ntdll/rtl/critical.c
_____
Modified: trunk/reactos/lib/ntdll/rtl/critical.c
--- trunk/reactos/lib/ntdll/rtl/critical.c 2005-02-19 11:13:41 UTC
(rev 13640)
+++ trunk/reactos/lib/ntdll/rtl/critical.c 2005-02-19 13:13:17 UTC
(rev 13641)
@@ -144,23 +144,27 @@
*/
if (Thread == CriticalSection->OwningThread) {
- /* You own it, so you'll get it when you're done with it!
*/
+ /* You own it, so you'll get it when you're done with it!
No need to
+ use the interlocked functions as only the thread who
already owns
+ the lock can modify this data. */
CriticalSection->RecursionCount++;
return STATUS_SUCCESS;
}
- else if (CriticalSection->OwningThread == (HANDLE)0)
- {
- /* No one else owns it either! */
- DPRINT1("Critical section not initialized (guess)!\n");
- /* FIXME: raise exception */
- return STATUS_INVALID_PARAMETER;
- }
+
+ /* NOTE - CriticalSection->OwningThread can be NULL here
because changing
+ this information is not serialized. This happens when
thread a
+ acquires the lock (LockCount == 0) and thread b tries
to
+ acquire it as well (LockCount == 1) but thread a
hasn't had a
+ chance to set the OwningThread! So it's not an error
when
+ OwningThread is NULL here! */
/* We don't own it, so we must wait for it */
RtlpWaitForCriticalSection(CriticalSection);
}
- /* Lock successful */
+ /* Lock successful. Changing this information has not to be
serialized because
+ only one thread at a time can actually change it (the one who
acquired
+ the lock)! */
CriticalSection->OwningThread = Thread;
CriticalSection->RecursionCount = 1;
return STATUS_SUCCESS;