ReactOS Fundraising Campaign 2012
 
€ 3,303 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

NTSTATUS NTAPI RtlEnterCriticalSection ( PRTL_CRITICAL_SECTION  CriticalSection  ) 

Definition at line 444 of file critical.c.

00445 {
00446     HANDLE Thread = (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 thread
00453          * 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 to
00458                use the interlocked functions as only the thread who already owns
00459                the lock can modify this data. */
00460             CriticalSection->RecursionCount++;
00461             return STATUS_SUCCESS;
00462         }
00463 
00464         /* NOTE - CriticalSection->OwningThread can be NULL here because changing
00465                   this information is not serialized. This happens when thread a
00466                   acquires the lock (LockCount == 0) and thread b tries to
00467                   acquire it as well (LockCount == 1) but thread a hasn't had a
00468                   chance to set the OwningThread! So it's not an error when
00469                   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 because
00476        only one thread at a time can actually change it (the one who acquired
00477        the lock)! */
00478     CriticalSection->OwningThread = Thread;
00479     CriticalSection->RecursionCount = 1;
00480     return STATUS_SUCCESS;
00481 }


Generated on Tue May 15 06:12:49 2012 for ReactOS by doxygen 1.6.3

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.