Exemple #1
0
        public bool ReleaseMutex()
        {
            _lock.Enter();

            bool released;

            if (_ownerThreadId == Thread.CurrentThread.ManagedThreadId)
            {
                _enterCounter--;

                if (_enterCounter == 0)
                {
                    _ownerThreadId = -1;

                    _releaseSignal.Set();
                }

                released = true;
            }
            else
            {
                released = false;
            }

            _lock.Exit();
            return(released);
        }
Exemple #2
0
        public void Set()
        {
            _lock.Enter();

            _isSet = true;
            _signal.Exit();

            _lock.Exit();
        }
Exemple #3
0
        public bool Wait()
        {
            _lock.Enter();
            try
            {
                if (_ownerThreadId == Thread.CurrentThread.ManagedThreadId)
                {
                    do
                    {
                        this.ReleaseImpl();
                        _lock.Exit();

                        _pulseSignal.WaitOne();

                        _lock.Enter();
                    }while (_isMultiPulse || (_isPulseHandled && !_isMultiPulse));

                    _isPulseHandled = true;
                    this.CaptureImpl();
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            finally
            {
                _lock.Exit();
            }
            return(true);
        }
        public void WaitOne()
        {
            _spinlock.Enter();

            if (_counter < _max)
            {
                _counter++;

                _spinlock.Exit();
            }
            else
            {
                _spinlock.Exit();
                _guard.WaitOne();
                while (_counter == _max)
                {
                }
                _counter++;
            }
        }
Exemple #5
0
 public void Set()
 {
     _signal.Exit();
 }