예제 #1
0
        public static void TryEnter(object obj, int millisecondsTimeout, ref bool tookLock)
        {
            global::System.Diagnostics.Debug.Assert(!tookLock);
            MSyncVarOp mop = (millisecondsTimeout == Timeout.Infinite) ? MSyncVarOp.LOCK_ACQUIRE : MSyncVarOp.LOCK_TRYACQUIRE;

            tookLock = TryEnterRaw(obj, millisecondsTimeout, mop, "Monitor.TryEnter");
        }
예제 #2
0
 // specialized WrapRelease for NativeEvents
 public static bool WrapRelease(System.IntPtr o, MSyncVarOp mop, ReleaseOp ro, String instrMethod)
 {
     return(Helper.SimpleWrap <bool>(
                delegate(ClrSyncManager manager)
     {
         manager.SetMethodInfo(instrMethod);
         manager.SyncVarAccess(manager.GetSyncVarFromNativeHandle((System.IntPtr)o), mop);
         bool ret;
         try
         {
             ret = ro(o);
         }
         catch (Exception e)
         {
             manager.CommitSyncVarAccess();
             throw e;
         };
         manager.CommitSyncVarAccess();
         return ret;
     },
                delegate()
     {
         return ro(o);
     }));
 }
예제 #3
0
 public void AggregateSyncVarAccess(SyncVar[] v, MSyncVarOp op)
 {
     if (!Conversions.AggregateSyncVarAccess(v, op))
     {
         ChessDetach();
     }
 }
예제 #4
0
 // for use by instrumentation layer (not by CHESS)
 public void SyncVarAccess(SyncVar sv, MSyncVarOp mop)
 {
     if (!Conversions.SyncVarAccess(sv, mop))
     {
         ChessDetach();
     }
 }
예제 #5
0
        public SyncVar SyncVarAccess(UIntPtr o, MSyncVarOp mop)
        {
            SyncVar sv = syncVarManager.GetSyncVarFromUIntPtr(o);

            if (!Conversions.SyncVarAccess(sv, mop))
            {
                ChessDetach();
            }
            return(sv);
        }
예제 #6
0
 public void SyncVarAccess(object o, MSyncVarOp mop)
 {
     if (o == null)
     {
         return;
     }
     if (!Conversions.SyncVarAccess(syncVarManager.GetSyncVarFromObject(o), mop))
     {
         ChessDetach();
     }
 }
예제 #7
0
 public void AggregateSyncVarAccess(object[] syncops, MSyncVarOp op)
 {
     SyncVar[] sarr = new SyncVar[syncops.Length];
     for (int i = 0; i < sarr.Length; i++)
     {
         sarr[i] = syncVarManager.GetSyncVarFromObject(syncops[i]);
     }
     if (!Conversions.AggregateSyncVarAccess(sarr, op))
     {
         ChessDetach();
     }
 }
예제 #8
0
 // Monitor.TryEnter (Object)  Attempts to acquire an exclusive lock on the specified object.
 public static bool TryEnterRaw(object @lock, int timeOut, MSyncVarOp operation, string name)
 {
     if (@lock == null)
     {
         throw new ArgumentNullException();
     }
     if (timeOut < 0 && timeOut != Timeout.Infinite)
     {
         throw new ArgumentOutOfRangeException();
     }
     return(Helper.SimpleWrap <bool>(
                delegate(ClrSyncManager manager)
     {
         bool flag;
         while (true)
         {
             try
             {
                 manager.SetMethodInfo(name);
                 manager.SyncVarAccess(@lock, operation);
                 flag = Original::Monitor.TryEnter(@lock);
                 if (!flag && timeOut == Timeout.Infinite)
                 {
                     manager.LocalBacktrack();
                     continue;
                 }
             }
             catch (Exception e)
             {
                 manager.CommitSyncVarAccess();
                 throw e;
             }
             if (flag)
             {
                 MonitorHelper.IncrementReentrancyCount(@lock);
             }
             if (!flag)
             {
                 manager.MarkTimeout();
             }
             manager.CommitSyncVarAccess();
             break;
         }
         return flag;
     },
                delegate()
     {
         return Original::Monitor.TryEnter(@lock, timeOut);
     }));
 }
예제 #9
0
 public static bool WrapRelease(object o, MSyncVarOp mop, ReleaseOp ro, String instrMethod)
 {
     return(Helper.SimpleWrap <bool>(
                delegate(ClrSyncManager manager)
     {
         manager.SetMethodInfo(instrMethod);
         manager.SyncVarAccess(o, mop);
         bool ret;
         try {
             ret = ro(o);
         } catch (Exception e) {
             manager.CommitSyncVarAccess();
             throw e;
         };
         manager.CommitSyncVarAccess();
         return ret;
     },
                delegate()
     {
         return ro(o);
     }));
 }
예제 #10
0
 public static T WrapProperty <T>(Original::ReaderWriterLockSlim @lock, PropertyDel <T> property, MSyncVarOp mop, string instrMethod)
 {
     return(Helper.SimpleWrap <T>(
                delegate(ClrSyncManager manager)
     {
         manager.SetMethodInfo(instrMethod);
         manager.SyncVarAccess(@lock, mop);
         T ret;
         try {
             ret = property();
         } catch (Exception e) {
             manager.CommitSyncVarAccess();
             throw e;
         };
         manager.CommitSyncVarAccess();
         return ret;
     },
                delegate()
     {
         return property();
     }));
 }
예제 #11
0
 public static T WrapReceive <T>(BlockingReceive <T> b, QueueEmpty qe, object o, MSyncVarOp mop, String instrMethod)
 {
     return(SimpleWrap <T>(
                delegate(ClrSyncManager manager)
     {
         T ret;
         while (true)
         {
             manager.SetMethodInfo(instrMethod);
             manager.SyncVarAccess(o, mop);
             try
             {
                 if (qe())
                 {
                     manager.LocalBacktrack();
                     continue;
                 }
                 ret = b();
             }
             catch (Exception e)
             {
                 manager.CommitSyncVarAccess();
                 throw e;
             }
             manager.CommitSyncVarAccess();
             break;
         }
         ;
         return ret;
     },
                delegate()
     {
         return b();
     }));
 }
예제 #12
0
 public static bool WrapAcquire(BlockingAcquire b, NonBlockingAcquire nb, object o, MSyncVarOp mop, String instrMethod)
 {
     return(SimpleWrap <bool>(
                delegate(ClrSyncManager manager)
     {
         while (true)
         {
             manager.SetMethodInfo(instrMethod);
             manager.SyncVarAccess(o, mop);
             try
             {
                 if (!nb())
                 {
                     manager.LocalBacktrack();
                     continue;
                 }
             }
             catch (Exception e)
             {
                 manager.CommitSyncVarAccess();
                 throw e;
             }
             manager.CommitSyncVarAccess();
             break;
         }
         ;
         return true;
     },
                delegate()
     {
         return b();
     }));
 }
예제 #13
0
        // Monitor.TryEnter (Object, TimeSpan)  Attempts, for the specified amount of time, to acquire
        //   an exclusive lock on the specified object.
        public static bool TryEnter(object @lock, TimeSpan timeOut)
        {
            MSyncVarOp mop = (timeOut.TotalMilliseconds == Timeout.Infinite) ? MSyncVarOp.LOCK_ACQUIRE : MSyncVarOp.LOCK_TRYACQUIRE;

            return(TryEnterRaw(@lock, (int)timeOut.TotalMilliseconds, mop, "Monitor.TryEnter"));
        }
예제 #14
0
        // Monitor.TryEnter (Object, Int32)  Attempts, for the specified number of milliseconds, to
        //   acquire an exclusive lock on the specified object.
        public static bool TryEnter(object @lock, int timeOut)
        {
            MSyncVarOp mop = (timeOut == Timeout.Infinite) ? MSyncVarOp.LOCK_ACQUIRE : MSyncVarOp.LOCK_TRYACQUIRE;

            return(TryEnterRaw(@lock, timeOut, mop, "Monitor.TryEnter"));
        }