Esempio n. 1
0
        public bool TryGet(long key, out Match val)
        {
            try
            {
                RWL.AcquireReaderLock(500);

                return(Matches.TryGetValue(key, out val));
            }
            finally
            {
                RWL.ReleaseReaderLock();
            }
        }
Esempio n. 2
0
        public void Pop(long key)
        {
            try
            {
                RWL.AcquireReaderLock(1000); // this is already too long but who cares ?

                Matches.Remove(key);
            }
            finally
            {
                RWL.ReleaseReaderLock();
            }
        }
Esempio n. 3
0
        public void Push(Match val)
        {
            try
            {
                RWL.AcquireReaderLock(1000); // this is already too long but who cares ?

                val.MatchId = Matches.Count;
                Matches.Add(val.MatchId, val);
            }
            finally
            {
                RWL.ReleaseReaderLock();
            }
        }
Esempio n. 4
0
            protected override void Run()
            {
                while (true)
                {
                    using (RWL.AcquireReaderLock()) {
                        Console.WriteLine("<| " + base.ToString() + " is reading");
                        Thread.Sleep(3000);

                        Console.WriteLine(" |>" + base.ToString() + " has finished reading!");
                    }

                    // Thread.Sleep (1000);
                }
            }
Esempio n. 5
0
        public bool TryGet(string userName, out Presence pr)
        {
            try
            {
                RWL.AcquireReaderLock(500);

                pr = Values.FirstOrDefault(_pr => _pr.Value.User.UserName == userName).Value;
                return(pr != null);
            }
            finally
            {
                RWL.ReleaseReaderLock();
            }
        }
Esempio n. 6
0
        public void Push(IPacket packet, Presence skip = null)
        {
            try
            {
                RWL.AcquireReaderLock(1000); // this is already too long but who cares ?

                foreach (var pr in Values.Where(pr => pr.Value != skip))
                {
                    pr.Value.Push(packet);
                }
            }
            finally
            {
                RWL.ReleaseReaderLock();
            }
        }