Exemple #1
0
    /**
     * Required to be called in order to create thread pool, uses const definition for number of threads to be generated
     */
    public void Awake()
    {
        KillThread = false;
        if (this.enabled)
        {
            Debug.Log("Clearing chunk manager lists in Enable");
            generatedChunk.Clear();
            chunkMap.Clear();
            updateMap.Clear();
            updateGenerationMap.Clear();
            lockMap.Clear();
            chunkList.Clear();
            deletionPool.Clear();
            chunkUpdateQueue.Clear();
            ThreadPool.Clear();
            generationRequests.Clear();
            finishedGeneration.Clear();
            finishedUpdate.Clear();
            Debug.Log("Finished clearing chunk manager lists in Enable");

            //Debug.Log("Destroying chunk parent in chunk manager Enable");
            //Destroy(chunkParent);
            //Debug.Log("Finished destroying chunk parent in chunk manager Enable");
            chunkParent = new GameObject("Chunk Parent");
            Chunk.noise = new FastNoise(UnityEngine.Random.Range(0, int.MaxValue));

            for (int n = 0; n < CurrentWidth / 2; n++)
            {
                for (int i = 1024 - n; i < n + 1024; i++)
                {
                    for (int j = 1024 - n; j < n + 1024; j++)
                    {
                        if (!chunkRequested.ContainsKey(Hash(i, j)))
                        {
                            RequestChunk(i, j, new MarchingChunkMesher(), Vector2.zero);
                        }
                    }
                }
            }

            StartCoroutine(CheckDeletionQueue());
            StartCoroutine(CheckGenerationQueue());
            StartCoroutine(CheckUpdateQueue());
            StartCoroutine(AddChunks());
            Thread thread = new Thread(CheckUpdateMap);
            thread.Start();

            for (int i = 0; i < ThreadPoolSize; i++)
            {
                thread = new Thread(GenerateChunk);
                thread.Start();
                ThreadPool.Add(thread);
            }
            chunkParent.transform.position = new Vector3(-1024 * Constants.ChunkWidth, 0, -1024 * Constants.ChunkWidth);
        }
    }
Exemple #2
0
        /// <summary>
        /// Disposer. Release resources and cleanup.
        /// </summary>
        /// <param name="disposing">true to dispose managed resources</param>
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!_disposed)
            {
                Log.Debug();

                if (disposing)
                {
                    _exitThread = true;
                    calibrationQueue.Clear();
                    calibrationQueue.Enqueue("Stop");
                    Log.Debug("Calling thread.join");

                    _thread.Join(2000);
                    Log.Debug("Exited thread");

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

                // Release unmanaged resources.
            }

            _disposed = true;
        }
Exemple #3
0
        internal IOrganizationService[] ClearServicesQueue()
        {
            var services = servicesQueue.ToArray();

            servicesQueue.Clear();
            return(services);
        }
        public Task StopAsync()
        {
            StopPublishing();
            StopMaintainingConnection();

            _messageQueue.Clear();

            return(Task.FromResult(0));
        }
        public void Stop()
        {
            m_running = false;

            Thread.Sleep(1000); // let the world move

            foreach (Thread t in m_workerThreads)
            {
                Watchdog.AbortThread(t.ManagedThreadId);
            }

            // any entry in m_bycontext should have a active request on the other queues
            // so just delete contents to easy GC
            foreach (Queue <PollServiceHttpRequest> qu in m_bycontext.Values)
            {
                qu.Clear();
            }
            m_bycontext.Clear();

            try
            {
                foreach (PollServiceHttpRequest req in m_retryRequests)
                {
                    req.DoHTTPstop(m_server);
                }
            }
            catch
            {
            }

            PollServiceHttpRequest wreq;

            m_retryRequests.Clear();

            lock (m_slowRequests)
            {
                while (m_slowRequests.Count > 0)
                {
                    m_requests.Enqueue(m_slowRequests.Dequeue());
                }
            }

            while (m_requests.Count() > 0)
            {
                try
                {
                    wreq = m_requests.Dequeue(0);
                    wreq.DoHTTPstop(m_server);
                }
                catch
                {
                }
            }

            m_requests.Clear();
        }
Exemple #6
0
        public void StartInternal()
        {
            lock (this)
            {
                _logger.DebugFormat("Execute :{0} StartInternal, queueCount {1}", Name, _queue.Count);
                _isStart = true;

                _queue.Clear();
            }
        }
Exemple #7
0
 public void Connect(string ip, int port, float timeOut)
 {
     if (clientSocket != null)
     {
         clientSocket.Close();
     }
     msgQueue.Clear();
     state        = SocketState.Connecting;
     clientSocket = new ClientSocket(++socketId, msgQueue);
     clientSocket.Connect(ip, port, timeOut);
 }
Exemple #8
0
        public void Stop()
        {
            m_running = false;

            Thread.Sleep(100); // let the world move

            foreach (Thread t in m_workerThreads)
            {
                Watchdog.AbortThread(t.ManagedThreadId);
            }

            m_threadPool.Shutdown();

            // any entry in m_bycontext should have a active request on the other queues
            // so just delete contents to easy GC
            foreach (Queue <PollServiceHttpRequest> qu in m_bycontext.Values)
            {
                qu.Clear();
            }
            m_bycontext.Clear();

/*
 *          try
 *          {
 *              foreach (PollServiceHttpRequest req in m_retryRequests)
 *              {
 *                  req.DoHTTPstop(m_server);
 *              }
 *          }
 *          catch
 *          {
 *          }
 *
 *          PollServiceHttpRequest wreq;
 */
            m_retryRequests.Clear();

/*
 *          while (m_requests.Count() > 0)
 *          {
 *              try
 *              {
 *                  wreq = m_requests.Dequeue(0);
 *                  wreq.DoHTTPstop(m_server);
 *
 *              }
 *              catch
 *              {
 *              }
 *          }
 */
            m_requests.Clear();
        }
        public void Release()
        {
            lock (this)
            {
                _cancelTasks?.Cancel();
                _cancelTasks?.Dispose();

                _dbConnectors.ForEach(v => v.Close());
                _dbConnectors.Clear();
                _poolDBC.Clear();
            }
        }
Exemple #10
0
        public void Clear_Items()
        {
            var queue = new BlockingQueue <string>();

            queue.Enqueue("a");
            queue.Enqueue("b");
            queue.Enqueue("c");

            Assert.AreEqual(3, queue.Count);

            queue.Clear();

            Assert.AreEqual(0, queue.Count);
        }
Exemple #11
0
        public void Queue()
        {
            using (var queue = new BlockingQueue <string>())
            {
                using (var worker = new BackgroundWorker())
                {
                    worker.DoWork                    += new DoWorkEventHandler(DoWork);
                    worker.ProgressChanged           += new ProgressChangedEventHandler(DoProgressChanged);
                    worker.WorkerReportsProgress      = true;
                    worker.WorkerSupportsCancellation = true;
                    worker.RunWorkerAsync(queue);

                    int count = 0;
                    while (count < QueueSize)
                    {
                        string s = queue.Dequeue();
                        Console.WriteLine("dequeued " + count + "(" + s + ")");
                        count++;
                    }

                    worker.CancelAsync();
                }

                queue.Clear();

                // priority

                queue.Enqueue("one");
                queue.Enqueue("two");
                queue.Enqueue("thr");

                queue.Enqueue("one1", 1);
                queue.Enqueue("one0", 0);
                queue.Enqueue("two1", 1);
                queue.Enqueue("two0");
                queue.Enqueue("thr1", 1);
                queue.Enqueue("thr0");


                Assert.AreEqual("one", queue.Dequeue());
                Assert.AreEqual("two", queue.Dequeue());
                Assert.AreEqual("thr", queue.Dequeue());
                Assert.AreEqual("one0", queue.Dequeue());
                Assert.AreEqual("two0", queue.Dequeue());
                Assert.AreEqual("thr0", queue.Dequeue());
                Assert.AreEqual("one1", queue.Dequeue());
                Assert.AreEqual("two1", queue.Dequeue());
                Assert.AreEqual("thr1", queue.Dequeue());
            }
        }
Exemple #12
0
 /// <summary>
 /// Send a quit message to all child processes.
 /// </summary>
 private void QuitChildProcesses()
 {
     foreach (var url in childBuilderURLs)
     {
         CommMessage quitMessage = new CommMessage(CommMessage.MessageType.CloseReceiver)
         {
             To = url
         };
         quitMessage.Arguments.Add(CommCommands.AUTODISCONNECT, "");
         commObject.PostMessage(quitMessage);
     }
     childBuilderURLs.Clear();
     readyQueue.Clear();
     Console.WriteLine("Attempting to stop childs process.");
 }
        public void Stop()
        {
            if (m_log.IsDebugEnabled)
            {
                m_log.DebugFormat("{0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
            }

            m_running = false;
//            m_timeout = -10000; // cause all to expire
            Thread.Sleep(1000); // let the world move

            foreach (Thread t in m_workerThreads)
            {
                Watchdog.AbortThread(t.ManagedThreadId);
            }

            PollServiceHttpRequest wreq;

            lock (m_longPollRequests)
            {
                if (m_longPollRequests.Count > 0 && m_running)
                {
                    m_longPollRequests.ForEach(req => m_requests.Enqueue(req));
                }
            }

            while (m_requests.Count() > 0)
            {
                try
                {
                    wreq = m_requests.Dequeue(0);
                    wreq.DoHTTPGruntWork(
                        m_server, wreq.PollServiceArgs.NoEvents(wreq.RequestID, wreq.PollServiceArgs.Id));
                }
                catch
                {
                }
            }

            m_longPollRequests.Clear();
            m_requests.Clear();
        }
        public void Start(Int32 threadCount)
        {
            if (threadCount < 1)
            {
                return;
            }


            lock (this)
            {
                _works.Clear();

                _running = true;
                _threads = new Thread[threadCount];
                for (Int32 i = 0; i < threadCount; ++i)
                {
                    _threads[i]      = new Thread(Run);
                    _threads[i].Name = String.Format("{0} {1}", Name, i);
                    _threads[i].Start();
                }
            }
        }
Exemple #15
0
        public void Stop()
        {
            lock (this)
            {
                if (_running == false || _threads == null)
                {
                    return;
                }


                _running = false;
                _works.Cancel();

                foreach (Thread th in _threads)
                {
                    th.Join();
                }

                _works.Clear();
                _threads = null;
            }
        }
Exemple #16
0
        public void Queue()
        {
            BlockingQueue<string> queue = new BlockingQueue<string>();

            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += new DoWorkEventHandler(DoWork);
            worker.ProgressChanged += new ProgressChangedEventHandler(DoProgressChanged);
            worker.WorkerReportsProgress = true;
            worker.RunWorkerAsync(queue);

            int count = 0;
            while (count < 5)
            {
                string s = queue.Dequeue();
                Console.WriteLine("dequeued " + count + "(" + s + ")");
                count++;
            }

            queue.Clear();
            queue.Dispose();
            queue = null;
        }
Exemple #17
0
        public void Stop()
        {
            IsRunning = false;
            //            m_timeout = -10000; // cause all to expire
            Thread.Sleep(1000); // let the world move

            foreach (Thread t in m_workerThreads)
            {
                Watchdog.AbortThread(t.ManagedThreadId);
            }

            PollServiceHttpRequest wreq;

            lock (m_longPollRequests)
            {
                if (m_longPollRequests.Count > 0 && IsRunning)
                {
                    m_longPollRequests.ForEach(req => m_requests.Enqueue(req));
                }
            }

            while (m_requests.Count() > 0)
            {
                try
                {
                    wreq = m_requests.Dequeue(0);
                    ResponsesProcessed++;
                    wreq.DoHTTPGruntWork(
                        m_server, wreq.PollServiceArgs.NoEvents(wreq.RequestID, wreq.PollServiceArgs.Id));
                }
                catch
                {
                }
            }

            m_longPollRequests.Clear();
            m_requests.Clear();
        }
Exemple #18
0
 public void Clear()
 {
     _stringQueue.Clear();
 }
 internal void StartExecution() 
 { 
     _toggleActivityQueue.Clear(); 
     _toggleActivityQueue.Open(); 
     ThreadUtils.StartBackgroundThread(InterruptExecutionThread); 
 } 
Exemple #20
0
        private void ParsCommand(XfsCommandBase <object> commandBase)
        {
            switch (commandBase.CommandType)
            {
            case CommandType.Execute:
            {
                blockingQueue.Clear();
                var cmnd = JsonConvert.DeserializeObject <ExecuteCommand>(JsonConvert.SerializeObject(commandBase.XfsCommand));
                if (commandBase.IsExecuteSuccessfully)
                {
                    if (cmnd.CommandCode == BCRDefinition.WFS_CMD_BCR_READ)
                    {
                        blockingQueue.Clear();
                        try
                        {
                            var data = XFSUtil.Cast <BarcodeData[]>(cmnd.ResultModel)[0].Value;
                            ReadDataCompleted?.Invoke(data);
                        }
                        catch (Exception ex)
                        {
                            L4Logger.Error(ex);
                            //MediaError.Invoke();
                        }
                    }
                }
                else
                {
                    if (commandBase.ErrorCode == XFSDefinition.WFS_ERR_CANCELED)
                    {
                        return;
                    }
                    if (cmnd.CommandCode == BCRDefinition.WFS_CMD_BCR_READ)
                    {
                        ReadDataError?.Invoke("BCR", commandBase.ErrorCode, commandBase.ErrorCode.ToString());
                        //if (workingMode == WorkingMode.None || workingMode == WorkingMode.EjectCard)
                        //    return;
                        //else
                        //    ReadRawDataError?.Invoke("IDC", commandBase.ErrorCode, commandBase.ErrorCode.ToString());

                        //workingMode = WorkingMode.None;
                    }
                }
                break;
            }

            case CommandType.Open:
            {
                var cmnd = JsonConvert.DeserializeObject <OpenCommand>(JsonConvert.SerializeObject(commandBase.XfsCommand));
                if (commandBase.IsExecuteSuccessfully)
                {
                    if (commandBase.Detail.Equals("XFSDevice_OpenComplete"))
                    {
                        IsOpenned = true;
                        OpenCompleted?.Invoke();
                    }
                    if (commandBase.Detail.Equals("XFSDevice_RegisterComplete"))
                    {
                        RegisterCompleted?.Invoke();
                    }
                }
                else
                {
                    if (commandBase.Detail.Equals("XFSDevice_OpenError"))
                    {
                        IsOpenned = false;
                        OpenError?.Invoke(commandBase.ErrorCode);
                    }
                    if (commandBase.Detail.Equals("XFSDevice_RegisterError"))
                    {
                        RegisterError?.Invoke(commandBase.ErrorCode);
                    }
                }
                break;
            }

            case CommandType.Getinfo:
            {
                var cmnd = JsonConvert.DeserializeObject <GetInfoCommand>(JsonConvert.SerializeObject(commandBase.XfsCommand));
                GetInfoResponse?.Invoke(XFSUtil.Cast <WFSBCRSTATUS>(cmnd.Status), null);
                break;
            }
            }
        }
Exemple #21
0
 /// <summary>
 /// Dispose
 /// </summary>
 public void Dispose()
 {
     _concurrentQueue.Clear();
     _bufferManager.Dispose();
 }
Exemple #22
0
        private void PacketHandler()
        {
            Action <LLAgent> clientPacketHandler = ClientOutgoingPacketHandler;

            while (base.IsRunning)
            {
                try
                {
                    // Time keeping
                    int now     = Util.TickCount();
                    int elapsed = now - m_tickLastOutgoingPacketHandler;
                    m_tickLastOutgoingPacketHandler = now;

                    // Maximum time to wait dequeuing an incoming packet. Used
                    // to put this thread to sleep when there is little or no
                    // activity
                    int dequeueTimeout = 0;

                    #region Outgoing Packets

                    m_packetSent = false;

                    #region Update Timers

                    m_resendUnacked = false;
                    m_sendAcks      = false;
                    m_sendPing      = false;

                    m_resendTimer.Elapsed += elapsed;
                    m_ackTimer.Elapsed    += elapsed;
                    m_pingTimer.Elapsed   += elapsed;

                    if (m_resendTimer.Elapsed >= m_resendTimer.Interval)
                    {
                        m_resendUnacked       = true;
                        m_resendTimer.Elapsed = 0;
                    }
                    if (m_ackTimer.Elapsed >= m_ackTimer.Interval)
                    {
                        m_sendAcks         = true;
                        m_ackTimer.Elapsed = 0;
                    }
                    if (m_pingTimer.Elapsed >= m_pingTimer.Interval)
                    {
                        m_sendPing          = true;
                        m_pingTimer.Elapsed = 0;
                    }

                    #endregion Update Timers

                    // Handle outgoing packets, resends, acknowledgements, and pings for each
                    // client. m_packetSent will be set to true if a packet is sent
                    m_clients.ForEach(clientPacketHandler);

                    // If nothing was sent, wait up to the minimum amount of time before a
                    // token bucket could get more tokens, if we have clients connected.
                    // Otherwise, do a long wait
                    if (!m_packetSent)
                    {
                        if (m_clients.Count > 0)
                        {
                            dequeueTimeout = (int)Scene.Simian.TickCountResolution;
                        }
                        else
                        {
                            dequeueTimeout = Simian.LONG_SLEEP_INTERVAL;
                        }
                    }

                    #endregion Outgoing Packets

                    #region Incoming Packets

                    IncomingPacket incomingPacket = null;

                    if (m_packetInbox.Dequeue(dequeueTimeout, ref incomingPacket))
                    {
                        Packet  packet = incomingPacket.Packet;
                        LLAgent agent  = incomingPacket.Agent;

                        // Record the time we started processing this packet
                        incomingPacket.StartedHandling = Util.TickCount();

                        // Sanity check
                        if (packet == null || agent == null)
                        {
                            m_log.WarnFormat("Processing a packet with incomplete state. Packet=\"{0}\", LLAgent=\"{1}\"",
                                             packet, agent);
                        }

                        PacketEvents.BeginRaiseEvent(incomingPacket);
                    }

                    #endregion Incoming Packets
                }
                catch (Exception ex)
                {
                    m_log.Error("Error in the packet handler loop: " + ex.Message, ex);
                }

                Scheduler.ThreadKeepAlive();
            }

            if (m_packetInbox.Count > 0)
            {
                m_log.Warn("IncomingPacketHandler is shutting down, dropping " + m_packetInbox.Count + " packets");
            }
            m_packetInbox.Clear();

            Scheduler.RemoveThread();
        }