Hardware/WinRing0.cs
changeset 162 2129ccee0bd1
parent 90 3333b29a1746
child 163 67be1c62f950
     1.1 --- a/Hardware/WinRing0.cs	Wed Aug 04 19:10:20 2010 +0000
     1.2 +++ b/Hardware/WinRing0.cs	Wed Aug 04 20:27:05 2010 +0000
     1.3 @@ -39,7 +39,7 @@
     1.4  using System.Collections.Generic;
     1.5  using System.IO;
     1.6  using System.Runtime.InteropServices;
     1.7 -using System.Text;
     1.8 +using System.Threading;
     1.9  
    1.10  namespace OpenHardwareMonitor.Hardware {
    1.11  
    1.12 @@ -56,6 +56,7 @@
    1.13      }
    1.14  
    1.15      private static bool available = false;
    1.16 +    public static Mutex isaBusMutex;
    1.17  
    1.18      private static string GetDllName() {   
    1.19        int p = (int)System.Environment.OSVersion.Platform;
    1.20 @@ -103,20 +104,22 @@
    1.21      private static InitializeOlsDelegate InitializeOls;
    1.22      private static DeinitializeOlsDelegate DeinitializeOls;
    1.23  
    1.24 -    public static GetDllStatusDelegate GetDllStatus;
    1.25 -    public static IsCpuidDelegate IsCpuid;
    1.26 -    public static CpuidDelegate Cpuid;
    1.27 -    public static CpuidTxDelegate CpuidTx;
    1.28 -    public static RdmsrDelegate Rdmsr;
    1.29 -    public static RdmsrTxDelegate RdmsrTx;
    1.30 -    public static ReadIoPortByteDelegate ReadIoPortByte;
    1.31 -    public static WriteIoPortByteDelegate WriteIoPortByte;
    1.32 -    public static SetPciMaxBusIndexDelegate SetPciMaxBusIndex;
    1.33 -    public static FindPciDeviceByIdDelegate FindPciDeviceById;
    1.34 -    public static ReadPciConfigDwordExDelegate ReadPciConfigDwordEx;
    1.35 -    public static WritePciConfigDwordExDelegate WritePciConfigDwordEx;
    1.36 -    public static RdtscTxDelegate RdtscTx;
    1.37 -    public static RdtscDelegate Rdtsc;
    1.38 +    public static readonly GetDllStatusDelegate GetDllStatus;
    1.39 +    public static readonly IsCpuidDelegate IsCpuid;
    1.40 +    public static readonly CpuidDelegate Cpuid;
    1.41 +    public static readonly CpuidTxDelegate CpuidTx;
    1.42 +    public static readonly RdmsrDelegate Rdmsr;
    1.43 +    public static readonly RdmsrTxDelegate RdmsrTx;
    1.44 +    public static readonly ReadIoPortByteDelegate ReadIoPortByte;
    1.45 +    public static readonly WriteIoPortByteDelegate WriteIoPortByte;
    1.46 +    public static readonly SetPciMaxBusIndexDelegate SetPciMaxBusIndex;
    1.47 +    public static readonly FindPciDeviceByIdDelegate FindPciDeviceById;
    1.48 +    public static readonly ReadPciConfigDwordExDelegate ReadPciConfigDwordEx;
    1.49 +    public static readonly WritePciConfigDwordExDelegate WritePciConfigDwordEx;
    1.50 +    public static readonly RdtscTxDelegate RdtscTx;
    1.51 +    public static readonly RdtscDelegate Rdtsc;
    1.52 +
    1.53 +    
    1.54  
    1.55      private static void GetDelegate<T>(string entryPoint, out T newDelegate) 
    1.56        where T : class 
    1.57 @@ -150,18 +153,32 @@
    1.58        try {
    1.59          if (InitializeOls != null && InitializeOls())
    1.60            available = true;
    1.61 -      } catch (DllNotFoundException) { }       
    1.62 +      } catch (DllNotFoundException) { }
    1.63 +
    1.64 +      isaBusMutex = new Mutex(false, "Access_ISABUS.HTP.Method");
    1.65      }
    1.66      
    1.67      public static bool IsAvailable {
    1.68        get { return available; }
    1.69      }
    1.70  
    1.71 +    public static bool WaitIsaBusMutex() {
    1.72 +      try {
    1.73 +        return isaBusMutex.WaitOne(10);
    1.74 +      } catch { return false; }
    1.75 +    }
    1.76 +
    1.77 +    public static void ReleaseIsaBusMutex() {
    1.78 +      isaBusMutex.ReleaseMutex();
    1.79 +    }
    1.80 +
    1.81      private static Deinitializer deinitializer = new Deinitializer();
    1.82      private class Deinitializer {
    1.83        ~Deinitializer() {
    1.84          if (available)
    1.85            DeinitializeOls();
    1.86 +        
    1.87 +        isaBusMutex.Close();
    1.88        }
    1.89      }
    1.90    }