00445 {
00446 HANDLEThread = (HANDLE)NtCurrentTeb()->ClientId.UniqueThread;
00447
00448 /* Try to Lock it */00449 if (InterlockedIncrement(&CriticalSection->LockCount) != 0) {
00450
00451 /*00452 * We've failed to lock it! Does this thread00453 * actually own it?00454 */00455 if (Thread == CriticalSection->OwningThread) {
00456
00457 /* You own it, so you'll get it when you're done with it! No need to00458 use the interlocked functions as only the thread who already owns00459 the lock can modify this data. */00460 CriticalSection->RecursionCount++;
00461 returnSTATUS_SUCCESS;
00462 }
00463
00464 /* NOTE - CriticalSection->OwningThread can be NULL here because changing00465 this information is not serialized. This happens when thread a00466 acquires the lock (LockCount == 0) and thread b tries to00467 acquire it as well (LockCount == 1) but thread a hasn't had a00468 chance to set the OwningThread! So it's not an error when00469 OwningThread is NULL here! */00470
00471 /* We don't own it, so we must wait for it */00472 RtlpWaitForCriticalSection(CriticalSection);
00473 }
00474
00475 /* Lock successful. Changing this information has not to be serialized because00476 only one thread at a time can actually change it (the one who acquired00477 the lock)! */00478 CriticalSection->OwningThread = Thread;
00479 CriticalSection->RecursionCount = 1;
00480 returnSTATUS_SUCCESS;
00481 }
Generated on Tue May 15 06:12:49 2012 for ReactOS by
1.6.3
ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.