Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenreentrancy.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Sound System "MME Buddy" Library 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: lib/sound/mmebuddy/reentrancy.c 00005 * 00006 * PURPOSE: Provides entry-point mutex guards. 00007 * 00008 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org) 00009 */ 00010 00011 #include "precomp.h" 00012 00013 HANDLE EntrypointMutexes[SOUND_DEVICE_TYPES]; 00014 00015 /* 00016 Creates a set of mutexes which are used for the purpose of guarding the 00017 device-type specific module entry-points. If any of these fail creation, 00018 all of them will be destroyed and the failure reported. 00019 */ 00020 MMRESULT 00021 InitEntrypointMutexes() 00022 { 00023 UCHAR i; 00024 MMRESULT Result = MMSYSERR_NOERROR; 00025 00026 /* Blank all entries ni the table first */ 00027 for ( i = 0; i < SOUND_DEVICE_TYPES; ++ i ) 00028 { 00029 EntrypointMutexes[i] = NULL; 00030 } 00031 00032 /* Now create the mutexes */ 00033 for ( i = 0; i < SOUND_DEVICE_TYPES; ++ i ) 00034 { 00035 EntrypointMutexes[i] = CreateMutex(NULL, FALSE, NULL); 00036 00037 if ( ! EntrypointMutexes[i] ) 00038 { 00039 Result = Win32ErrorToMmResult(GetLastError()); 00040 00041 /* Clean up any mutexes we successfully created */ 00042 CleanupEntrypointMutexes(); 00043 break; 00044 } 00045 } 00046 00047 return Result; 00048 } 00049 00050 /* 00051 Cleans up any of the entry-point guard mutexes. This will only close the 00052 handles of mutexes which have been created, making it safe for use as a 00053 cleanup routine even within the InitEntrypointMutexes routine above. 00054 */ 00055 VOID 00056 CleanupEntrypointMutexes() 00057 { 00058 UCHAR i; 00059 00060 /* Only clean up a mutex if it actually exists */ 00061 for ( i = 0; i < SOUND_DEVICE_TYPES; ++ i ) 00062 { 00063 if ( EntrypointMutexes[i] ) 00064 { 00065 CloseHandle(EntrypointMutexes[i]); 00066 EntrypointMutexes[i] = NULL; 00067 } 00068 } 00069 } 00070 00071 /* 00072 Grabs an entry-point mutex. 00073 */ 00074 VOID 00075 AcquireEntrypointMutex( 00076 IN MMDEVICE_TYPE DeviceType) 00077 { 00078 UCHAR i; 00079 00080 SND_ASSERT( IS_VALID_SOUND_DEVICE_TYPE(DeviceType) ); 00081 i = SOUND_DEVICE_TYPE_TO_INDEX(DeviceType); 00082 00083 SND_ASSERT( EntrypointMutexes[i] ); 00084 00085 WaitForSingleObject(EntrypointMutexes[i], INFINITE); 00086 } 00087 00088 /* 00089 Releases an entry-point mutex. 00090 */ 00091 VOID 00092 ReleaseEntrypointMutex( 00093 IN MMDEVICE_TYPE DeviceType) 00094 { 00095 UCHAR i; 00096 00097 SND_ASSERT( IS_VALID_SOUND_DEVICE_TYPE(DeviceType) ); 00098 i = SOUND_DEVICE_TYPE_TO_INDEX(DeviceType); 00099 00100 SND_ASSERT( EntrypointMutexes[i] ); 00101 00102 ReleaseMutex(EntrypointMutexes[i]); 00103 } Generated on Fri May 25 2012 04:34:39 for ReactOS by
1.7.6.1
|