Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfmutex.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS HAL 00004 * FILE: ntoskrnl/hal/x86/fmutex.c 00005 * PURPOSE: Deprecated HAL Fast Mutex 00006 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net) 00007 */ 00008 00009 /* 00010 * NOTE: Even HAL itself has #defines to use the Exi* APIs inside NTOSKRNL. 00011 * These are only exported here for compatibility with really old 00012 * drivers. Also note that in theory, these can be made much faster 00013 * by using assembly and inlining all the operations, including 00014 * raising and lowering irql. 00015 */ 00016 00017 /* INCLUDES *****************************************************************/ 00018 00019 #include <hal.h> 00020 #define NDEBUG 00021 #include <debug.h> 00022 00023 #undef ExAcquireFastMutex 00024 #undef ExReleaseFastMutex 00025 00026 /* FUNCTIONS *****************************************************************/ 00027 00028 VOID 00029 FASTCALL 00030 ExAcquireFastMutex(PFAST_MUTEX FastMutex) 00031 { 00032 KIRQL OldIrql; 00033 00034 /* Raise IRQL to APC */ 00035 KeRaiseIrql(APC_LEVEL, &OldIrql); 00036 00037 /* Decrease the count */ 00038 if (InterlockedDecrement(&FastMutex->Count)) 00039 { 00040 /* Someone is still holding it, use slow path */ 00041 FastMutex->Contention++; 00042 KeWaitForSingleObject(&FastMutex->Event, 00043 WrExecutive, 00044 KernelMode, 00045 FALSE, 00046 NULL); 00047 } 00048 00049 /* Set the owner and IRQL */ 00050 FastMutex->Owner = KeGetCurrentThread(); 00051 FastMutex->OldIrql = OldIrql; 00052 } 00053 00054 VOID 00055 FASTCALL 00056 ExReleaseFastMutex(PFAST_MUTEX FastMutex) 00057 { 00058 KIRQL OldIrql; 00059 00060 /* Erase the owner */ 00061 FastMutex->Owner = (PVOID)1; 00062 OldIrql = FastMutex->OldIrql; 00063 00064 /* Increase the count */ 00065 if (InterlockedIncrement(&FastMutex->Count) <= 0) 00066 { 00067 /* Someone was waiting for it, signal the waiter */ 00068 KeSetEventBoostPriority(&FastMutex->Event, IO_NO_INCREMENT); 00069 } 00070 00071 /* Lower IRQL back */ 00072 KeLowerIrql(OldIrql); 00073 } 00074 00075 BOOLEAN 00076 FASTCALL 00077 ExiTryToAcquireFastMutex(PFAST_MUTEX FastMutex) 00078 { 00079 KIRQL OldIrql; 00080 00081 /* Raise to APC_LEVEL */ 00082 KeRaiseIrql(APC_LEVEL, &OldIrql); 00083 00084 /* Check if we can quickly acquire it */ 00085 if (InterlockedCompareExchange(&FastMutex->Count, 0, 1) == 1) 00086 { 00087 /* We have, set us as owners */ 00088 FastMutex->Owner = KeGetCurrentThread(); 00089 FastMutex->OldIrql = OldIrql; 00090 return TRUE; 00091 } 00092 else 00093 { 00094 /* Acquire attempt failed */ 00095 KeLowerIrql(OldIrql); 00096 return FALSE; 00097 } 00098 } 00099 00100 /* EOF */ Generated on Sun May 27 2012 04:28:40 for ReactOS by
1.7.6.1
|