try_enter_with_atomic_var() private method

private try_enter_with_atomic_var ( object obj, int millisecondsTimeout, bool &lockTaken ) : void
obj object
millisecondsTimeout int
lockTaken bool
return void
Ejemplo n.º 1
0
        public bool TryAcquire()
        {
            bool lockTaken = false;

            Monitor.try_enter_with_atomic_var(this, 0, false, ref lockTaken);
            return(lockTaken);
        }
Ejemplo n.º 2
0
        private void ReleaseCore(int count)
        {
            bool mutexLocked = false;

            try {
                Monitor.try_enter_with_atomic_var(mutex, Timeout.Infinite, false, ref mutexLocked);
                while (count > 0)
                {
                    if (head != null)
                    {
                        ref WaitEntry wait_entry = ref Unsafe.AsRef <WaitEntry> (head);
                        head = wait_entry.next;
                        if (head != null)
                        {
                            Unsafe.AsRef <WaitEntry> (head).previous = null;
                        }
                        wait_entry.previous = null;
                        wait_entry.next     = null;
                        lock (wait_entry.condition)
                        {
                            wait_entry.signaled = true;
                            Monitor.Pulse(wait_entry.condition);
                        }
                        --count;
                    }
                    else
                    {
                        pending_signals += (uint)count;
                        count            = 0;
                    }
                }
Ejemplo n.º 3
0
        public void Acquire()
        {
            bool lockTaken = false;

            Monitor.try_enter_with_atomic_var(this, Timeout.Infinite, false, ref lockTaken);
        }
Ejemplo n.º 4
0
        private bool WaitCore(int timeoutMs)
        {
            WaitEntry wait_entry      = new WaitEntry();
            bool      mutexLocked     = false;
            bool      waitEntryLocked = false;

            try {
                Monitor.try_enter_with_atomic_var(mutex, Timeout.Infinite, false, ref mutexLocked);

                if (pending_signals > 0)
                {
                    --pending_signals;
                    return(true);
                }

                wait_entry.condition = new object();
                wait_entry.previous  = null;
                wait_entry.next      = head;
                if (head != null)
                {
                    Unsafe.AsRef <WaitEntry> (head).previous = Unsafe.AsPointer <WaitEntry> (ref wait_entry);
                }
                head = Unsafe.AsPointer <WaitEntry> (ref wait_entry);
            }
            finally {
                if (mutexLocked)
                {
                    Monitor.Exit(mutex);
                }
            }

            try {
                Monitor.try_enter_with_atomic_var(wait_entry.condition, Timeout.Infinite, false, ref waitEntryLocked);
                if (!wait_entry.signaled)
                {
                    Monitor.Monitor_wait(wait_entry.condition, timeoutMs, false);
                }
            }
            finally {
                if (waitEntryLocked)
                {
                    Monitor.Exit(wait_entry.condition);
                }
            }

            mutexLocked = false;
            try {
                Monitor.try_enter_with_atomic_var(mutex, Timeout.Infinite, false, ref mutexLocked);

                if (!wait_entry.signaled)
                {
                    if (head == Unsafe.AsPointer <WaitEntry> (ref wait_entry))
                    {
                        head = wait_entry.next;
                    }
                    if (wait_entry.next != null)
                    {
                        Unsafe.AsRef <WaitEntry> (wait_entry.next).previous = wait_entry.previous;
                    }
                    if (wait_entry.previous != null)
                    {
                        Unsafe.AsRef <WaitEntry> (wait_entry.previous).next = wait_entry.next;
                    }
                }
            }
            finally {
                if (mutexLocked)
                {
                    Monitor.Exit(mutex);
                }
            }

            return(wait_entry.signaled);
        }