Ejemplo n.º 1
0
        public void TestInterruptOnDispose()
        {
            using (var testInst = new MonitorObject())
            {
                int exitCount = 0;
                var task      = Task.Run(() =>
                {
                    try
                    {
                        using (var waiter = testInst.Enter())
                        {
                            waiter.Wait(_ => false, (object)null);
                        }
                    }
                    catch (OperationInterruptedException) { }
                    Interlocked.Increment(ref exitCount);
                });


                TimingAssert.AreEqual(10000, 1, () => testInst.WaiterCount);

                testInst.Dispose();
                TimingAssert.AreEqual(10000, 1, () => Volatile.Read(ref exitCount));

                task.Wait();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Clean-up all resources
        /// </summary>
        /// <param name="isUserCall">Was called by user</param>
        protected override void Dispose(bool isUserCall)
        {
            if (!_isDisposed)
            {
                _isDisposed = true;

                if (_backgroundCompactionThread != null)
                {
                    _backgroundCompactionThread.Stop(true);
                }

                _addMonitor.Dispose();
                _takeMonitor.Dispose();
                _peekMonitor.Dispose();

                lock (_segmentOperationsLock)
                {
                    foreach (var segment in _segments)
                    {
                        segment.Dispose();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Clean-up all resources
        /// </summary>
        /// <param name="isUserCall">Was called by user</param>
        protected override void Dispose(bool isUserCall)
        {
            if (!_isDisposed)
            {
                _isDisposed = true;

                if (_backgroundTransferer != null)
                {
                    _backgroundTransferer.Stop(waitForStop: true);
                }

                _addMonitor.Dispose();
                _takeMonitor.Dispose();
                _peekMonitor.Dispose();

                _lowLevelQueue.Dispose();
                _highLevelQueue.Dispose();

                if (_backgoundTransfererExclusive != null)
                {
                    _backgoundTransfererExclusive.Dispose();
                }
            }
        }