Hardware/Ring0.cs
changeset 285 0820c0558727
parent 283 fb88cac4a9aa
child 293 9c1b242b1c63
     1.1 --- a/Hardware/Ring0.cs	Sun May 15 16:44:14 2011 +0000
     1.2 +++ b/Hardware/Ring0.cs	Sun May 15 17:06:55 2011 +0000
     1.3 @@ -39,6 +39,7 @@
     1.4  using System.IO;
     1.5  using System.Reflection;
     1.6  using System.Runtime.InteropServices;
     1.7 +using System.Security.AccessControl;
     1.8  using System.Threading;
     1.9  using System.Text;
    1.10  
    1.11 @@ -172,7 +173,14 @@
    1.12        if (!driver.IsOpen) 
    1.13          driver = null;
    1.14  
    1.15 -      isaBusMutex = new Mutex(false, "Global\\Access_ISABUS.HTP.Method");
    1.16 +      string mutexName = "Global\\Access_ISABUS.HTP.Method";
    1.17 +      try {
    1.18 +        isaBusMutex = new Mutex(false, mutexName);
    1.19 +      } catch (UnauthorizedAccessException) {
    1.20 +        try {
    1.21 +          isaBusMutex = Mutex.OpenExisting(mutexName, MutexRights.Synchronize);
    1.22 +        } catch { }
    1.23 +      }
    1.24      }
    1.25  
    1.26      public static bool IsOpen {
    1.27 @@ -193,7 +201,10 @@
    1.28  
    1.29        driver = null;
    1.30  
    1.31 -      isaBusMutex.Close();
    1.32 +      if (isaBusMutex != null) {
    1.33 +        isaBusMutex.Close();
    1.34 +        isaBusMutex = null;
    1.35 +      }
    1.36  
    1.37        // try to delete temporary driver file again if failed during open
    1.38        if (fileName != null && File.Exists(fileName)) {
    1.39 @@ -218,6 +229,8 @@
    1.40      }
    1.41  
    1.42      public static bool WaitIsaBusMutex(int millisecondsTimeout) {
    1.43 +      if (isaBusMutex == null)
    1.44 +        return true;
    1.45        try {
    1.46          return isaBusMutex.WaitOne(millisecondsTimeout, false);
    1.47        } catch (AbandonedMutexException) { return false; } 
    1.48 @@ -225,6 +238,8 @@
    1.49      }
    1.50  
    1.51      public static void ReleaseIsaBusMutex() {
    1.52 +      if (isaBusMutex == null)
    1.53 +        return;
    1.54        isaBusMutex.ReleaseMutex();
    1.55      }
    1.56