Added an ISA bus mutex.

This commit is contained in:
Michael Möller
2010-08-04 20:27:05 +00:00
parent 146cbfe5eb
commit 56425669e8
4 changed files with 66 additions and 20 deletions
+12 -2
View File
@@ -87,9 +87,12 @@ namespace OpenHardwareMonitor.Hardware.LPC {
r.AppendLine();
r.Append("Base Adress: 0x"); r.AppendLine(address.ToString("X4"));
r.AppendLine();
if (!WinRing0.WaitIsaBusMutex())
return r.ToString();
r.AppendLine("Hardware Monitor Registers");
r.AppendLine();
r.AppendLine(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
r.AppendLine();
for (int i = 0; i <= 0xF; i++) {
@@ -101,10 +104,15 @@ namespace OpenHardwareMonitor.Hardware.LPC {
r.AppendLine();
}
r.AppendLine();
WinRing0.ReleaseIsaBusMutex();
return r.ToString();
}
public void Update() {
if (!WinRing0.WaitIsaBusMutex())
return;
for (int i = 0; i < voltages.Length; i++) {
int value = ReadByte((byte)(VOLTAGE_BASE_REG + i));
@@ -154,7 +162,9 @@ namespace OpenHardwareMonitor.Hardware.LPC {
fans[i] = (value < 0x0fff) ? 1.5e6f / value : 0;
else
fans[i] = null;
}
}
WinRing0.ReleaseIsaBusMutex();
}
}
}
+11 -2
View File
@@ -118,9 +118,12 @@ namespace OpenHardwareMonitor.Hardware.LPC {
r.Append("Chip Version: 0x"); r.AppendLine(version.ToString("X"));
r.Append("Base Address: 0x"); r.AppendLine(address.ToString("X4"));
r.AppendLine();
if (!WinRing0.WaitIsaBusMutex())
return r.ToString();
r.AppendLine("Environment Controller Registers");
r.AppendLine();
r.AppendLine(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
r.AppendLine();
for (int i = 0; i <= 0xA; i++) {
@@ -138,10 +141,14 @@ namespace OpenHardwareMonitor.Hardware.LPC {
}
r.AppendLine();
WinRing0.ReleaseIsaBusMutex();
return r.ToString();
}
public void Update() {
if (!WinRing0.WaitIsaBusMutex())
return;
for (int i = 0; i < voltages.Length; i++) {
bool valid;
@@ -182,7 +189,9 @@ namespace OpenHardwareMonitor.Hardware.LPC {
} else {
fans[i] = null;
}
}
}
WinRing0.ReleaseIsaBusMutex();
}
}
}
+10
View File
@@ -194,6 +194,8 @@ namespace OpenHardwareMonitor.Hardware.LPC {
public float?[] Fans { get { return fans; } }
public void Update() {
if (!WinRing0.WaitIsaBusMutex())
return;
for (int i = 0; i < voltages.Length; i++) {
if (voltageRegister[i] != VOLTAGE_VBAT_REG) {
@@ -279,6 +281,8 @@ namespace OpenHardwareMonitor.Hardware.LPC {
if (oldByte != newByte)
WriteByte(0, FAN_BIT_REG[i], newByte);
}
WinRing0.ReleaseIsaBusMutex();
}
public string GetReport() {
@@ -290,6 +294,10 @@ namespace OpenHardwareMonitor.Hardware.LPC {
r.Append("Chip revision: 0x"); r.AppendLine(revision.ToString("X"));
r.Append("Base Adress: 0x"); r.AppendLine(address.ToString("X4"));
r.AppendLine();
if (!WinRing0.WaitIsaBusMutex())
return r.ToString();
r.AppendLine("Hardware Monitor Registers");
r.AppendLine();
r.AppendLine(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
@@ -316,6 +324,8 @@ namespace OpenHardwareMonitor.Hardware.LPC {
}
r.AppendLine();
WinRing0.ReleaseIsaBusMutex();
return r.ToString();
}
}
+33 -16
View File
@@ -39,7 +39,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace OpenHardwareMonitor.Hardware {
@@ -56,6 +56,7 @@ namespace OpenHardwareMonitor.Hardware {
}
private static bool available = false;
public static Mutex isaBusMutex;
private static string GetDllName() {
int p = (int)System.Environment.OSVersion.Platform;
@@ -103,20 +104,22 @@ namespace OpenHardwareMonitor.Hardware {
private static InitializeOlsDelegate InitializeOls;
private static DeinitializeOlsDelegate DeinitializeOls;
public static GetDllStatusDelegate GetDllStatus;
public static IsCpuidDelegate IsCpuid;
public static CpuidDelegate Cpuid;
public static CpuidTxDelegate CpuidTx;
public static RdmsrDelegate Rdmsr;
public static RdmsrTxDelegate RdmsrTx;
public static ReadIoPortByteDelegate ReadIoPortByte;
public static WriteIoPortByteDelegate WriteIoPortByte;
public static SetPciMaxBusIndexDelegate SetPciMaxBusIndex;
public static FindPciDeviceByIdDelegate FindPciDeviceById;
public static ReadPciConfigDwordExDelegate ReadPciConfigDwordEx;
public static WritePciConfigDwordExDelegate WritePciConfigDwordEx;
public static RdtscTxDelegate RdtscTx;
public static RdtscDelegate Rdtsc;
public static readonly GetDllStatusDelegate GetDllStatus;
public static readonly IsCpuidDelegate IsCpuid;
public static readonly CpuidDelegate Cpuid;
public static readonly CpuidTxDelegate CpuidTx;
public static readonly RdmsrDelegate Rdmsr;
public static readonly RdmsrTxDelegate RdmsrTx;
public static readonly ReadIoPortByteDelegate ReadIoPortByte;
public static readonly WriteIoPortByteDelegate WriteIoPortByte;
public static readonly SetPciMaxBusIndexDelegate SetPciMaxBusIndex;
public static readonly FindPciDeviceByIdDelegate FindPciDeviceById;
public static readonly ReadPciConfigDwordExDelegate ReadPciConfigDwordEx;
public static readonly WritePciConfigDwordExDelegate WritePciConfigDwordEx;
public static readonly RdtscTxDelegate RdtscTx;
public static readonly RdtscDelegate Rdtsc;
private static void GetDelegate<T>(string entryPoint, out T newDelegate)
where T : class
@@ -150,18 +153,32 @@ namespace OpenHardwareMonitor.Hardware {
try {
if (InitializeOls != null && InitializeOls())
available = true;
} catch (DllNotFoundException) { }
} catch (DllNotFoundException) { }
isaBusMutex = new Mutex(false, "Access_ISABUS.HTP.Method");
}
public static bool IsAvailable {
get { return available; }
}
public static bool WaitIsaBusMutex() {
try {
return isaBusMutex.WaitOne(10);
} catch { return false; }
}
public static void ReleaseIsaBusMutex() {
isaBusMutex.ReleaseMutex();
}
private static Deinitializer deinitializer = new Deinitializer();
private class Deinitializer {
~Deinitializer() {
if (available)
DeinitializeOls();
isaBusMutex.Close();
}
}
}