Exemplo n.º 1
0
        public Deque(IEnumerable <TValue> collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection), "Collection cannot be null.");
            }
#if DEBUG
            this.m_lock = new SpinLockWrapper(true);
#else
            this.m_lock = new SpinLockWrapper(false);
#endif

            var source = CollectionExtensions.ToReadOnlyCollection(collection);
            var count  = source.Count;

            if (count > 0)
            {
                this.SetCapacity(count);
                this.DoAddRange(source);
            }
            else
            {
                this.m_data   = new TValue[DefaultCapacity];
                this.m_count  = 0;
                this.m_offset = 0;
            }

            this.m_isDisposed = 0;
        }
Exemplo n.º 2
0
        public void LockUnicityTest()
        {
            ParallelTestHelper.Repeat(delegate
            {
                var currentCount = 0;
                var fail         = false;
                var wrapper      = new SpinLockWrapper();

                ParallelTestHelper.ParallelStressTest(wrapper, delegate
                {
                    var taken = false;
                    wrapper.Lock.Enter(ref taken);
                    var current = currentCount++;
                    if (current != 0)
                    {
                        fail = true;
                    }

                    var sw = new SpinWait();
                    for (var i = 0; i < 200; i++)
                    {
                        sw.SpinOnce();
                    }

                    currentCount--;

                    wrapper.Lock.Exit();
                }, 4);

                Assert.IsFalse(fail);
            }, 200);
        }
Exemplo n.º 3
0
        public void LockUnicityTest()
        {
            ParallelTestHelper.Repeat(delegate {
                int currentCount        = 0;
                bool fail               = false;
                SpinLockWrapper wrapper = new SpinLockWrapper();

                ParallelTestHelper.ParallelStressTest(wrapper, delegate {
                    bool taken = false;
                    wrapper.Lock.Enter(ref taken);
                    int current = currentCount++;
                    if (current != 0)
                    {
                        fail = true;
                    }

                    SpinWait sw = new SpinWait();
                    for (int i = 0; i < 200; i++)
                    {
                        sw.SpinOnce();
                    }
                    currentCount -= 1;

                    wrapper.Lock.Exit();
                }, 4);

                Assert.IsFalse(fail);
            }, 5);
        }
        public RemoteTriggerQueue(IOptions <QueueSettings> options, IInternalMqttClient client)
        {
            this.m_gaugeTriggerSerivce = Metrics.CreateGauge("router_trigger_messages_queued", "Number of messages in the trigger queue.");

            this.m_triggerMeasurements = new MeasurementData();
            this.m_triggerMessages     = new TextMessageData();
            this.m_measurementLock     = new SpinLockWrapper();
            this.m_messageLock         = new SpinLockWrapper();

            this.m_client = client;
            this.m_messageTriggerTopic     = options.Value.TriggerQueueTemplate.Replace("$type", "messages");
            this.m_measurementTriggerTopic = options.Value.TriggerQueueTemplate.Replace("$type", "measurements");
        }
Exemplo n.º 5
0
        public Deque(int capacity)
        {
#if DEBUG
            this.m_lock = new SpinLockWrapper(true);
#else
            this.m_lock = new SpinLockWrapper(false);
#endif

            this.m_isDisposed = 0;
            this.m_count      = 0;
            this.m_offset     = 0;
            this.m_data       = null;
            this.SetCapacity(capacity);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create a new memory cache.
        /// </summary>
        /// <param name="capacity">Cache capacity.</param>
        /// <param name="timeout">Default entry timeout.</param>
        /// <param name="clock">Cache clock to compute entry times and timeouts.</param>
        public MemoryCache(long capacity, TimeSpan timeout, ISystemClock clock)
        {
            this.m_defaultTimeout = timeout;
            this.m_clock          = clock;
            this.m_capacity       = capacity;

            this.m_activeScanning = true;
            this.m_disposed       = false;
            this.m_data           = new Dictionary <TKey, CacheEntry <TValue> >();
            this.m_dataLock       = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
            this.m_lastScan       = DateTimeOffset.MinValue;
            this.m_deletionQueue  = new List <TKey>();
            this.m_deletionLock   = new SpinLockWrapper();
            this.m_size           = 0L;
            this.m_cts            = new CancellationTokenSource();
        }
        public RemoteLiveDataQueue(IOptions <QueueSettings> options, IInternalMqttClient client)
        {
            this.m_liveDataLock         = new SpinLockWrapper();
            this.m_liveDataHandlers     = new HashSet <string>();
            this.m_textMessageQueues    = new Dictionary <string, TextMessageData>();
            this.m_measurementQueues    = new Dictionary <string, MeasurementData>();
            this.m_controlMessageQueues = new Dictionary <string, ControlMessageData>();

            this.m_controlMessageLiveDataTopic = options.Value.LiveDataQueueTemplate.Replace("$type", "control");
            this.m_messageLiveDataTopic        = options.Value.LiveDataQueueTemplate.Replace("$type", "messages");
            this.m_measurementLiveDataTopic    = options.Value.LiveDataQueueTemplate.Replace("$type", "measurements");

            this.m_controlLock          = new SpinLockWrapper();
            this.m_measurementLock      = new SpinLockWrapper();
            this.m_messageLock          = new SpinLockWrapper();
            this.m_client               = client;
            this.m_gaugeLiveDataService = Metrics.CreateGauge("router_livedata_messages_queued", "Number of messages in the live data queue.");
        }
Exemplo n.º 8
0
    public static void Main(string[] args)
    {
        int iterations = 200;

        if (args.Length > 0)
        {
            iterations = Int32.Parse(args [0]);
        }

        ParallelTestHelper.Repeat(delegate {
            int currentCount        = 0;
            bool fail               = false;
            SpinLockWrapper wrapper = new SpinLockWrapper();

            ParallelTestHelper.ParallelStressTest(wrapper, delegate {
                bool taken = false;
                wrapper.Lock.Enter(ref taken);
                //wrapper.Lock.TryEnter (200,ref taken);
                int current = currentCount++;
                if (current != 0)
                {
                    fail = true;
                }

                SpinWait sw = new SpinWait();
                for (int i = 0; i < 200; i++)
                {
                    sw.SpinOnce();
                }
                currentCount -= 1;

                wrapper.Lock.Exit();
            }, 4);

            if (fail)
            {
                Environment.Exit(1);
            }
        }, iterations);
        Environment.Exit(0);
    }
Exemplo n.º 9
0
 public MqttClientStub()
 {
     this.m_lock          = new SpinLockWrapper();
     this.m_publishCounts = new Dictionary <string, int>();
 }
Exemplo n.º 10
0
 protected AbstractAuthorizationHandler()
 {
     this.m_lock     = new SpinLockWrapper();
     this.m_messages = new List <TData>();
 }