- Update to r53061
[reactos.git] / base / services / audiosrv / pnp_list_lock.c
1 /*
2 * PROJECT: ReactOS
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/services/audiosrv/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 static HANDLE audio_device_list_lock = NULL;
12
13 BOOL
14 InitializeAudioDeviceListLock()
15 {
16 /* The security stuff is to make sure the mutex can be grabbed by
17 other processes - is this the best idea though ??? */
18
19 SECURITY_DESCRIPTOR security_descriptor;
20 SECURITY_ATTRIBUTES security;
21
22 InitializeSecurityDescriptor(&security_descriptor, SECURITY_DESCRIPTOR_REVISION);
23 SetSecurityDescriptorDacl(&security_descriptor, TRUE, 0, FALSE);
24
25 security.nLength = sizeof(SECURITY_ATTRIBUTES);
26 security.lpSecurityDescriptor = &security_descriptor;
27 security.bInheritHandle = FALSE;
28
29 audio_device_list_lock = CreateMutex(&security,
30 FALSE,
31 AUDIO_LIST_LOCK_NAME);
32
33 return ( audio_device_list_lock != NULL );
34 }
35
36 VOID
37 KillAudioDeviceListLock()
38 {
39 CloseHandle(audio_device_list_lock);
40 audio_device_list_lock = NULL;
41 }
42
43 VOID
44 LockAudioDeviceList()
45 {
46 assert( audio_device_list_lock != NULL );
47 WaitForSingleObject(audio_device_list_lock, INFINITE);
48 }
49
50 VOID
51 UnlockAudioDeviceList()
52 {
53 assert( audio_device_list_lock != NULL );
54 ReleaseMutex(audio_device_list_lock);
55 }
56