Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        /// <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));
        }
Ejemplo n.º 3
0
        /// <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));
        }
Ejemplo n.º 4
0
        /// <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);
            }
        }
Ejemplo n.º 5
0
        /// <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));
        }