Exemplo n.º 1
0
        static void AddRealmPacket(IDictionary <RealmServerOpCode, LockfreeQueue <RealmReceiveInfo> > packets,
                                   PacketSender sender, PacketIn packet, TestFakeClient client)
        {
            var opCode = (RealmServerOpCode)packet.PacketId.RawId;

            LockfreeQueue <RealmReceiveInfo> queue;

            if (!packets.TryGetValue(opCode, out queue))
            {
                packets.Add(opCode, queue = new LockfreeQueue <RealmReceiveInfo>());
            }

            var def = PacketAnalyzer.GetDefinition(packet.PacketId, sender);

            if (def != null)
            {
                if (packet is RealmPacketIn)
                {
                    packet = ((DisposableRealmPacketIn)packet).Copy();
                }
                var parser = new PacketParser(packet, sender);
                parser.Parse();
                queue.Enqueue(new RealmReceiveInfo {
                    Parser = parser, Client = client
                });

                //packet.IncrementUsage();
            }
        }
Exemplo n.º 2
0
		static AuthQueue()
		{
			s_queuedClients = new LockfreeQueue<IRealmClient>();
			s_checkTimer = new Timer(ProcessQueuedClients);

			s_checkTimer.Change(TimeSpan.FromSeconds(15.0), TimeSpan.FromSeconds(15.0));
		}
Exemplo n.º 3
0
        static AuthQueue()
        {
            s_queuedClients = new LockfreeQueue <IRealmClient>();
            s_checkTimer    = new Timer(ProcessQueuedClients);

            s_checkTimer.Change(TimeSpan.FromSeconds(15.0), TimeSpan.FromSeconds(15.0));
        }
Exemplo n.º 4
0
		/// <summary>
		/// Creates a new task pool with the specified update frequency.
		/// </summary>
		/// <param name="updateFrequency">the update frequency of the task pool</param>
		public AsyncTaskPool(long updateFrequency)
		{
			m_taskQueue = new LockfreeQueue<IMessage>();
			m_taskTimer = Stopwatch.StartNew();
			m_updateFrequency = updateFrequency;

		    Task.Factory.StartNewDelayed((int)m_updateFrequency, TaskUpdateCallback, this);
		}
Exemplo n.º 5
0
 /// <summary>
 /// Constructs a new <see cref="Default"></see> object
 /// </summary>
 /// <param name="segmentCount">The number of chunks tocreate per segment</param>
 /// <param name="segmentSize">The size of a chunk in bytes</param>
 public BufferManager(int segmentCount, int segmentSize)
 {
     _segmentCount = segmentCount;
     _segmentSize = segmentSize;
     _buffers = new List<ArrayBuffer>();
     _availableSegments = new LockfreeQueue<BufferSegment>();
     Managers.Add(this);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a new task pool with the specified update frequency.
 /// </summary>
 /// <param name="updateFrequency">the update frequency of the task pool</param>
 public AsyncTaskPool(long updateFrequency)
 {
     this.TaskQueue       = new LockfreeQueue <IMessage>();
     this.TaskTimer       = Stopwatch.StartNew();
     this.UpdateFrequency = updateFrequency;
     Task.Factory.StartNewDelayed((int)this.UpdateFrequency, new Action <object>(this.TaskUpdateCallback),
                                  (object)this);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a new task pool with the specified update frequency.
 /// </summary>
 /// <param name="updateFrequency">the update frequency of the task pool</param>
 public AsyncTaskPool(long updateFrequency)
 {
     TaskQueue       = new LockfreeQueue <IMessage>();
     TaskTimer       = Stopwatch.StartNew();
     UpdateFrequency = updateFrequency;
     Task.Factory.StartNewDelayed((int)UpdateFrequency, TaskUpdateCallback,
                                  this);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Constructs a new <see cref="Default"></see> object
 /// </summary>
 /// <param name="segmentCount">The number of chunks tocreate per segment</param>
 /// <param name="segmentSize">The size of a chunk in bytes</param>
 public BufferManager(int segmentCount, int segmentSize)
 {
     _segmentCount      = segmentCount;
     _segmentSize       = segmentSize;
     _buffers           = new List <ArrayBuffer>();
     _availableSegments = new LockfreeQueue <BufferSegment>();
     Managers.Add(this);
 }
Exemplo n.º 9
0
		/// <summary>
		/// Creates a new task pool with the specified update frequency.
		/// </summary>
		/// <param name="updateFrequency">the update frequency of the task pool</param>
		public AsyncTaskPool(long updateFrequency)
		{
			m_waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
			m_taskQueue = new LockfreeQueue<IMessage>();
			m_taskTimer = Stopwatch.StartNew();
			m_updateFrequency = updateFrequency;

			ThreadPool.RegisterWaitForSingleObject(m_waitHandle, TaskUpdateCallback, null, m_updateFrequency, true);
		}
Exemplo n.º 10
0
 public SelfRunningTaskQueue(int updateInterval, string name, bool running = true)
 {
     Name             = name;
     m_timers         = new List <SimpleTimerEntry>();
     m_updatables     = new List <IUpdatable>();
     m_messageQueue   = new LockfreeQueue <IMessage>();
     m_queueTimer     = Stopwatch.StartNew();
     m_updateInterval = updateInterval;
     m_lastUpdate     = 0;
     IsRunning        = running;
 }
Exemplo n.º 11
0
		public SelfRunningTaskQueue(int updateInterval, string name, bool running = true)
		{
			Name = name;
			m_timers = new List<SimpleTimerEntry>();
			m_updatables = new List<IUpdatable>();
			m_messageQueue = new LockfreeQueue<IMessage>();
			m_queueTimer = Stopwatch.StartNew();
			m_updateInterval = updateInterval;
			m_lastUpdate = 0;

			IsRunning = running;
		}
Exemplo n.º 12
0
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        //[TestMethod]
        public void TestAll()
        {
            var num = 5000;

            bool done = false;
            var  q    = new LockfreeQueue <int>();

            for (int i = 0; i < num; i++)
            {
                q.Enqueue(i);
            }

            Assert.AreEqual(num, q.Count);

            var values = new int[num];

            for (int i = 0; i < num; i++)
            {
                ThreadPool.QueueUserWorkItem((indexObj) => {
                    var index = (int)indexObj;
                    var x     = q.TryDequeue();

                    lock (values)
                    {
                        if (index == num - 1)
                        {
                            done = true;
                            Monitor.PulseAll(values);
                        }
                    }
                }, i);
            }

            lock (values)
            {
                if (!done)
                {
                    Monitor.Wait(values);
                }
            }

            var uniqueStrings = new HashSet <int>();

            for (int i = 0; i < values.Length; i++)
            {
                var s = values[i];

                Assert.IsNotNull(s);
                uniqueStrings.Add(s);
            }
            Assert.AreEqual(values.Length, uniqueStrings.Count);
        }
Exemplo n.º 13
0
		//
		// You can use the following additional attributes as you write your tests:
		//
		// Use ClassInitialize to run code before running the first test in the class
		// [ClassInitialize()]
		// public static void MyClassInitialize(TestContext testContext) { }
		//
		// Use ClassCleanup to run code after all tests in a class have run
		// [ClassCleanup()]
		// public static void MyClassCleanup() { }
		//
		// Use TestInitialize to run code before running each test 
		// [TestInitialize()]
		// public void MyTestInitialize() { }
		//
		// Use TestCleanup to run code after each test has run
		// [TestCleanup()]
		// public void MyTestCleanup() { }
		//
		#endregion

		//[TestMethod]
		public void TestAll()
		{
			var num = 5000;

			bool done = false;
			var q = new LockfreeQueue<int>();
		    for (int i = 0; i < num; i++)
			{
				q.Enqueue(i);
			}

			Assert.AreEqual(num, q.Count);

			var values = new int[num];
			for (int i = 0; i < num; i++)
			{
				ThreadPool.QueueUserWorkItem((indexObj) => {
					var index = (int)indexObj;
					var x = q.TryDequeue();

					lock (values)
					{
						if (index == num - 1)
						{
							done = true;
							Monitor.PulseAll(values);
						}
					}
				}, i);
			}

			lock (values)
			{
				if (!done)
				{
					Monitor.Wait(values);
				}
			}

			var uniqueStrings = new HashSet<int>();
			for (int i = 0; i < values.Length; i++)
			{
				var s = values[i];

				Assert.IsNotNull(s);
				uniqueStrings.Add(s);
			}
			Assert.AreEqual(values.Length, uniqueStrings.Count);
		}
Exemplo n.º 14
0
        public void TestEnqueueAndDequeue()
        {
            LockfreeQueue<int> q = new LockfreeQueue<int>();

            q.Enqueue(1);
            q.Enqueue(2);
            q.Enqueue(3);

            // queue count
            Assert.AreEqual(3, q.Count);

            int value;

            Assert.AreEqual(1, q.Dequeue());
            Assert.AreEqual(2, q.Dequeue());
            Assert.AreEqual(3, q.Dequeue());
            Assert.IsFalse(q.TryDequeue(out value));
        }
Exemplo n.º 15
0
        public void TestEnqueueAndDequeue()
        {
            LockfreeQueue <int> q = new LockfreeQueue <int>();

            q.Enqueue(1);
            q.Enqueue(2);
            q.Enqueue(3);

            // queue count
            Assert.AreEqual(3, q.Count);

            int value;

            Assert.AreEqual(1, q.Dequeue());
            Assert.AreEqual(2, q.Dequeue());
            Assert.AreEqual(3, q.Dequeue());
            Assert.IsFalse(q.TryDequeue(out value));
        }
Exemplo n.º 16
0
		static void AddRealmPacket(IDictionary<RealmServerOpCode, LockfreeQueue<RealmReceiveInfo>> packets,
			PacketSender sender, PacketIn packet, TestFakeClient client)
		{
			var opCode = (RealmServerOpCode)packet.PacketId.RawId;

			LockfreeQueue<RealmReceiveInfo> queue;
			if (!packets.TryGetValue(opCode, out queue))
			{
				packets.Add(opCode, queue = new LockfreeQueue<RealmReceiveInfo>());
			}

			var def = PacketAnalyzer.GetDefinition(packet.PacketId, sender);
			if (def != null)
			{
				if (packet is RealmPacketIn)
				{
					packet = ((DisposableRealmPacketIn) packet).Copy();
				}
				var parser = new PacketParser(packet, sender);
				parser.Parse();
				queue.Enqueue(new RealmReceiveInfo { Parser = parser, Client = client });

				//packet.IncrementUsage();
			}
		}
Exemplo n.º 17
0
 public IdQueue()
 {
     m_freeIds = new LockfreeQueue<uint>();
 }
Exemplo n.º 18
0
		internal GuildEventLog(Guild guild)
		{
			m_guild = guild;
			m_entries = new LockfreeQueue<GuildEventLogEntry>();
		}