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"); }
// 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); })); }
public void AggregateSyncVarAccess(SyncVar[] v, MSyncVarOp op) { if (!Conversions.AggregateSyncVarAccess(v, op)) { ChessDetach(); } }
// for use by instrumentation layer (not by CHESS) public void SyncVarAccess(SyncVar sv, MSyncVarOp mop) { if (!Conversions.SyncVarAccess(sv, mop)) { ChessDetach(); } }
public SyncVar SyncVarAccess(UIntPtr o, MSyncVarOp mop) { SyncVar sv = syncVarManager.GetSyncVarFromUIntPtr(o); if (!Conversions.SyncVarAccess(sv, mop)) { ChessDetach(); } return(sv); }
public void SyncVarAccess(object o, MSyncVarOp mop) { if (o == null) { return; } if (!Conversions.SyncVarAccess(syncVarManager.GetSyncVarFromObject(o), mop)) { ChessDetach(); } }
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(); } }
// 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); })); }
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); })); }
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(); })); }
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(); })); }
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(); })); }
// 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")); }
// 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")); }