1c2c66affSColin Finck /*
2c2c66affSColin Finck  * PROJECT:     ReactOS
3c2c66affSColin Finck  * LICENSE:     GPL - See COPYING in the top level directory
4c2c66affSColin Finck  * PURPOSE:     Audio Service Plug and Play list locking mechanism
5c2c66affSColin Finck  * COPYRIGHT:   Copyright 2007 Andrew Greenwood
6c2c66affSColin Finck  */
7c2c66affSColin Finck 
8c2c66affSColin Finck #include "audiosrv.h"
9c2c66affSColin Finck 
10c2c66affSColin Finck #include <assert.h>
11c2c66affSColin Finck 
12c2c66affSColin Finck static HANDLE audio_device_list_lock = NULL;
13c2c66affSColin Finck 
14c2c66affSColin Finck BOOL
InitializeAudioDeviceListLock(VOID)15*353e05a4SEric Kohl InitializeAudioDeviceListLock(VOID)
16c2c66affSColin Finck {
17c2c66affSColin Finck     /* The security stuff is to make sure the mutex can be grabbed by
18c2c66affSColin Finck        other processes - is this the best idea though ??? */
19c2c66affSColin Finck 
20c2c66affSColin Finck     SECURITY_DESCRIPTOR security_descriptor;
21c2c66affSColin Finck     SECURITY_ATTRIBUTES security;
22c2c66affSColin Finck 
23c2c66affSColin Finck     InitializeSecurityDescriptor(&security_descriptor, SECURITY_DESCRIPTOR_REVISION);
24c2c66affSColin Finck     SetSecurityDescriptorDacl(&security_descriptor, TRUE, 0, FALSE);
25c2c66affSColin Finck 
26c2c66affSColin Finck     security.nLength = sizeof(SECURITY_ATTRIBUTES);
27c2c66affSColin Finck     security.lpSecurityDescriptor = &security_descriptor;
28c2c66affSColin Finck     security.bInheritHandle = FALSE;
29c2c66affSColin Finck 
30c2c66affSColin Finck     audio_device_list_lock = CreateMutex(&security,
31c2c66affSColin Finck                                          FALSE,
32c2c66affSColin Finck                                          AUDIO_LIST_LOCK_NAME);
33c2c66affSColin Finck 
34c2c66affSColin Finck     return (audio_device_list_lock != NULL);
35c2c66affSColin Finck }
36c2c66affSColin Finck 
37c2c66affSColin Finck VOID
KillAudioDeviceListLock(VOID)38*353e05a4SEric Kohl KillAudioDeviceListLock(VOID)
39c2c66affSColin Finck {
40c2c66affSColin Finck     CloseHandle(audio_device_list_lock);
41c2c66affSColin Finck     audio_device_list_lock = NULL;
42c2c66affSColin Finck }
43c2c66affSColin Finck 
44c2c66affSColin Finck VOID
LockAudioDeviceList(VOID)45*353e05a4SEric Kohl LockAudioDeviceList(VOID)
46c2c66affSColin Finck {
47c2c66affSColin Finck     assert(audio_device_list_lock != NULL);
48c2c66affSColin Finck     WaitForSingleObject(audio_device_list_lock, INFINITE);
49c2c66affSColin Finck }
50c2c66affSColin Finck 
51c2c66affSColin Finck VOID
UnlockAudioDeviceList(VOID)52*353e05a4SEric Kohl UnlockAudioDeviceList(VOID)
53c2c66affSColin Finck {
54c2c66affSColin Finck     assert(audio_device_list_lock != NULL);
55c2c66affSColin Finck     ReleaseMutex(audio_device_list_lock);
56c2c66affSColin Finck }
57