@@ -11,7 +11,7 @@ namespace AuroraRgb.Nodes.Razer;
1111
1212internal abstract class RazerFetcher : IDisposable
1313{
14- private const string ? GLOBAL_RAZERLINKREADWRITEGUARDMUTEX = "Global\\ RazerLinkReadWriteGuardMutex" ;
14+ private const string GlobalRazerlinkreadwriteguardmutex = "Global\\ RazerLinkReadWriteGuardMutex" ;
1515
1616 private const int HidReqSetReport = 0x09 ;
1717 private const int HidReqGetReport = 0x01 ; // Add GET_REPORT request
@@ -23,15 +23,12 @@ internal abstract class RazerFetcher : IDisposable
2323 private const int UsbTypeRequestIn = UsbTypeClass | UsbRecipInterface | UsbDirIn ;
2424 private const int RazerUsbReportLen = 90 ; // Example length, set this according to actual length
2525
26- private readonly Mutex _mutex ;
26+ private static readonly Mutex Mutex ;
2727
2828 static RazerFetcher ( )
2929 {
3030 UsbDevice . ForceLibUsbWinBack = true ;
31- }
3231
33- protected RazerFetcher ( )
34- {
3532 var rule = new MutexAccessRule ( new SecurityIdentifier ( WellKnownSidType . WorldSid , null ) ,
3633 MutexRights . Synchronize | MutexRights . Modify | MutexRights . FullControl | MutexRights . ReadPermissions | MutexRights . TakeOwnership ,
3734 AccessControlType . Allow ) ;
@@ -40,31 +37,16 @@ protected RazerFetcher()
4037 mutexSecurity . AddAccessRule ( rule ) ;
4138
4239 // Create a mutex with a well-known name use acl
43- _mutex = MutexAcl . Create ( false , GLOBAL_RAZERLINKREADWRITEGUARDMUTEX , out _ , mutexSecurity ) ;
44-
45- try
46- {
47- if ( ! _mutex . WaitOne ( TimeSpan . FromMilliseconds ( 2000 ) , false ) )
48- {
49- _mutex . ReleaseMutex ( ) ;
50- return ;
51- }
52- }
53- catch ( AbandonedMutexException )
54- {
55- //continue
56- }
57-
58- _mutex . ReleaseMutex ( ) ;
40+ Mutex = MutexAcl . Create ( false , GlobalRazerlinkreadwriteguardmutex , out _ , mutexSecurity ) ;
5941 }
6042
6143 protected byte [ ] ? Update ( )
6244 {
6345 try
6446 {
65- if ( ! _mutex . WaitOne ( TimeSpan . FromMilliseconds ( 2000 ) , false ) )
47+ if ( ! Mutex . WaitOne ( TimeSpan . FromMilliseconds ( 2000 ) , false ) )
6648 {
67- _mutex . ReleaseMutex ( ) ;
49+ Mutex . ReleaseMutex ( ) ;
6850 return null ;
6951 }
7052 }
@@ -74,7 +56,7 @@ protected RazerFetcher()
7456 }
7557
7658 var report = UpdateLocked ( ) ;
77- _mutex . ReleaseMutex ( ) ;
59+ Mutex . ReleaseMutex ( ) ;
7860
7961 return report ;
8062 }
@@ -169,9 +151,6 @@ private static string GetDeviceProductKeyString(UsbRegistry device)
169151
170152 protected virtual void Dispose ( bool disposing )
171153 {
172- if ( ! disposing ) return ;
173- _mutex . Close ( ) ;
174- _mutex . Dispose ( ) ;
175154 }
176155
177156 public void Dispose ( )
0 commit comments