Пример #1
0
        //public static long TotalHandleTime = 0;

        public static unsafe void HandleMessage(Message msg, int index)
        {
            //Stopwatch testsw = new Stopwatch();
            //testsw.Start();


            //Check if configmsg's payload is initialized. If not, it's a normal message.
            if ((IntPtr)msg.ConfigMsg.Payload != IntPtr.Zero) //It's a config message
            {
                Console.WriteLine("[HandleMessage] config message");
                //Cut pending batch so we can make and send the block then a config block
                Batch newbatch = GPUWrapper.Cut();
                if (newbatch.MsgCount > 0)
                {
                    Task.Factory.StartNew(() => MakeBlock(newbatch, false));
                }
                //Now make a config block
                Batch newconfigbatch = new Batch();
                newconfigbatch.Messages[0] = msg.ConfigMsg;
                Task.Factory.StartNew(() => MakeBlock(newconfigbatch, true));
            }
            else //It's a normal message
            {
                Console.WriteLine("[HandleMessage] normal message");
                Batch Batch1 = new Batch();
                Batch Batch2 = new Batch();
                //Stopwatch sw1 = new Stopwatch();
                //sw1.Start();
                bool IsPendingBatch = GPUWrapper.Ordered(msg.NormalMsg, ref Batch1, ref Batch2, index);
                //sw1.Stop();
                //if(Batch2.MsgCount > 0)
                //{
                //    OrderTimeCut += sw1.ElapsedMilliseconds;
                //}
                //else
                //{
                //    OrderTime += sw1.ElapsedMilliseconds;
                //}
                //string output = "Time taken: " + sw1.ElapsedMilliseconds + " ms" + Environment.NewLine;
                //Console.WriteLine(output);

                //Ordered returns 0, 1, or 2 batches, process each one returned into a block
                if (Batch1.MsgCount > 0)
                {
                    Task.Factory.StartNew(() => MakeBlock(Batch1, false));
                }
                if (Batch2.MsgCount > 0)
                {
                    Task.Factory.StartNew(() => MakeBlock(Batch2, false));
                }

                //Handle setting of timer
                bool timernull = Timer == new DateTime(); //Timer is default value
                if (!timernull && !IsPendingBatch)        //There is a timer but no pending batches, unnecessary
                {
                    Timer = new DateTime();               //Set timer to default value
                }
                else if (timernull && IsPendingBatch)
                {
                    Timer = DateTime.Now; //Start timer
                }
            }

            //testsw.Stop();
            //TotalHandleTime += testsw.ElapsedMilliseconds;
            //Console.WriteLine("Time taken: " + testsw.ElapsedMilliseconds);
        }