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