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