2 * PROJECT: ReactOS Sound System "MME Buddy" Library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/sound/mmebuddy/reentrancy.c
6 * PURPOSE: Provides entry-point mutex guards.
8 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
18 HANDLE EntrypointMutexes
[SOUND_DEVICE_TYPES
];
21 Creates a set of mutexes which are used for the purpose of guarding the
22 device-type specific module entry-points. If any of these fail creation,
23 all of them will be destroyed and the failure reported.
26 InitEntrypointMutexes()
29 MMRESULT Result
= MMSYSERR_NOERROR
;
31 /* Blank all entries ni the table first */
32 for ( i
= 0; i
< SOUND_DEVICE_TYPES
; ++ i
)
34 EntrypointMutexes
[i
] = NULL
;
37 /* Now create the mutexes */
38 for ( i
= 0; i
< SOUND_DEVICE_TYPES
; ++ i
)
40 EntrypointMutexes
[i
] = CreateMutex(NULL
, FALSE
, NULL
);
42 if ( ! EntrypointMutexes
[i
] )
44 Result
= Win32ErrorToMmResult(GetLastError());
46 /* Clean up any mutexes we successfully created */
47 CleanupEntrypointMutexes();
56 Cleans up any of the entry-point guard mutexes. This will only close the
57 handles of mutexes which have been created, making it safe for use as a
58 cleanup routine even within the InitEntrypointMutexes routine above.
61 CleanupEntrypointMutexes()
65 /* Only clean up a mutex if it actually exists */
66 for ( i
= 0; i
< SOUND_DEVICE_TYPES
; ++ i
)
68 if ( EntrypointMutexes
[i
] )
70 CloseHandle(EntrypointMutexes
[i
]);
71 EntrypointMutexes
[i
] = NULL
;
77 Grabs an entry-point mutex.
80 AcquireEntrypointMutex(
81 IN MMDEVICE_TYPE DeviceType
)
85 SND_ASSERT( IS_VALID_SOUND_DEVICE_TYPE(DeviceType
) );
86 i
= SOUND_DEVICE_TYPE_TO_INDEX(DeviceType
);
88 SND_ASSERT( EntrypointMutexes
[i
] );
90 WaitForSingleObject(EntrypointMutexes
[i
], INFINITE
);
94 Releases an entry-point mutex.
97 ReleaseEntrypointMutex(
98 IN MMDEVICE_TYPE DeviceType
)
102 SND_ASSERT( IS_VALID_SOUND_DEVICE_TYPE(DeviceType
) );
103 i
= SOUND_DEVICE_TYPE_TO_INDEX(DeviceType
);
105 SND_ASSERT( EntrypointMutexes
[i
] );
107 ReleaseMutex(EntrypointMutexes
[i
]);