/// <summary> /// Determines whether the current thread holds the lock on the specified object. /// </summary> public static bool IsEntered(object obj) { var runtime = CoyoteRuntime.Current; if (runtime.SchedulingPolicy is SchedulingPolicy.Interleaving) { var block = SynchronizedBlock.Find(obj) ?? throw new SystemThreading.SynchronizationLockException(); return(block.IsEntered()); } return(SystemThreading.Monitor.IsEntered(obj)); }
/// <summary> /// Releases the lock on an object and blocks the current thread until it reacquires the lock. /// If the specified time-out interval elapses, the thread enters the ready queue. /// </summary> public static bool Wait(object obj, int millisecondsTimeout) { var runtime = CoyoteRuntime.Current; if (runtime.SchedulingPolicy is SchedulingPolicy.Interleaving) { var block = SynchronizedBlock.Find(obj) ?? throw new SystemThreading.SynchronizationLockException(); return(block.Wait(millisecondsTimeout)); } return(SystemThreading.Monitor.Wait(obj, millisecondsTimeout)); }
/// <summary> /// Releases the lock on an object and blocks the current thread until it reacquires the lock. /// If the specified time-out interval elapses, the thread enters the ready queue. /// </summary> public static bool Wait(object obj, TimeSpan timeout) { var runtime = CoyoteRuntime.Current; if (runtime.SchedulingPolicy is SchedulingPolicy.Systematic) { var block = SynchronizedBlock.Find(obj) ?? throw new SystemThreading.SynchronizationLockException(); return(block.Wait(timeout)); } return(SystemThreading.Monitor.Wait(obj, timeout)); }
/// <summary> /// Releases an exclusive lock on the specified object. /// </summary> public static void Exit(object obj) { var runtime = CoyoteRuntime.Current; if (runtime.SchedulingPolicy is SchedulingPolicy.Interleaving) { var block = SynchronizedBlock.Find(obj) ?? throw new SystemThreading.SynchronizationLockException(); block.Exit(); } else { SystemThreading.Monitor.Exit(obj); } }
/// <summary> /// Releases the lock on an object and blocks the current thread until it reacquires the lock. /// If the specified time-out interval elapses, the thread enters the ready queue. Optionally /// exits the synchronization domain for the synchronized context before the wait and reacquires /// the domain afterward. /// </summary> public static bool Wait(object obj, TimeSpan timeout, bool exitContext) { var runtime = CoyoteRuntime.Current; if (runtime.SchedulingPolicy is SchedulingPolicy.Interleaving) { var block = SynchronizedBlock.Find(obj) ?? throw new SystemThreading.SynchronizationLockException(); // TODO: implement exitContext. return(block.Wait(timeout)); } return(SystemThreading.Monitor.Wait(obj, timeout, exitContext)); }