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)
13 HANDLE EntrypointMutexes
[SOUND_DEVICE_TYPES
];
16 Creates a set of mutexes which are used for the purpose of guarding the
17 device-type specific module entry-points. If any of these fail creation,
18 all of them will be destroyed and the failure reported.
21 InitEntrypointMutexes()
24 MMRESULT Result
= MMSYSERR_NOERROR
;
26 /* Blank all entries ni the table first */
27 for ( i
= 0; i
< SOUND_DEVICE_TYPES
; ++ i
)
29 EntrypointMutexes
[i
] = NULL
;
32 /* Now create the mutexes */
33 for ( i
= 0; i
< SOUND_DEVICE_TYPES
; ++ i
)
35 EntrypointMutexes
[i
] = CreateMutex(NULL
, FALSE
, NULL
);
37 if ( ! EntrypointMutexes
[i
] )
39 Result
= Win32ErrorToMmResult(GetLastError());
41 /* Clean up any mutexes we successfully created */
42 CleanupEntrypointMutexes();
51 Cleans up any of the entry-point guard mutexes. This will only close the
52 handles of mutexes which have been created, making it safe for use as a
53 cleanup routine even within the InitEntrypointMutexes routine above.
56 CleanupEntrypointMutexes()
60 /* Only clean up a mutex if it actually exists */
61 for ( i
= 0; i
< SOUND_DEVICE_TYPES
; ++ i
)
63 if ( EntrypointMutexes
[i
] )
65 CloseHandle(EntrypointMutexes
[i
]);
66 EntrypointMutexes
[i
] = NULL
;
72 Grabs an entry-point mutex.
75 AcquireEntrypointMutex(
76 IN MMDEVICE_TYPE DeviceType
)
80 SND_ASSERT( IS_VALID_SOUND_DEVICE_TYPE(DeviceType
) );
81 i
= SOUND_DEVICE_TYPE_TO_INDEX(DeviceType
);
83 SND_ASSERT( EntrypointMutexes
[i
] );
85 WaitForSingleObject(EntrypointMutexes
[i
], INFINITE
);
89 Releases an entry-point mutex.
92 ReleaseEntrypointMutex(
93 IN MMDEVICE_TYPE DeviceType
)
97 SND_ASSERT( IS_VALID_SOUND_DEVICE_TYPE(DeviceType
) );
98 i
= SOUND_DEVICE_TYPE_TO_INDEX(DeviceType
);
100 SND_ASSERT( EntrypointMutexes
[i
] );
102 ReleaseMutex(EntrypointMutexes
[i
]);