コード例 #1
0
        public ScriptWorkerThreadPool(int minimumThreads, int maximumThreads, UUID sceneID)
        {
            MinimumThreads = minimumThreads;
            MaximumThreads = maximumThreads;
            m_SceneID      = sceneID;

            m_Log.InfoFormat("Starting {0} minimum threads for {1}", minimumThreads, m_SceneID.ToString());
            for (int threadCount = 0; threadCount < m_MinimumThreads; ++threadCount)
            {
                var tc = new ScriptThreadContext
                {
                    ScriptThread = ThreadManager.CreateThread(ThreadMain),
                    ThreadPool   = this
                };
                tc.ScriptThread.Name = "Script Worker: " + m_SceneID.ToString();
                tc.ScriptThread.Start(tc);
                m_Threads.Add(tc);
            }
            m_FrameTimer.Elapsed += FrameTimer;
            m_FrameTimer.Start();
        }
コード例 #2
0
        public void PostScript(ScriptInstance i)
        {
            /* Do not enqueue the already queued script */
            bool enqueued = false;

            if (i.ThreadPool == null)
            {
                enqueued = m_ScriptTriggerQueue.EnqueueNewOnly(i);
            }

            if (enqueued)
            {
                int threadsCount = m_Threads.Count;
                if (m_ScriptTriggerQueue.Count > threadsCount && threadsCount < m_MaximumThreads)
                {
                    lock (m_Threads)
                    {
                        try
                        {
                            var tc = new ScriptThreadContext
                            {
                                ScriptThread = ThreadManager.CreateThread(ThreadMain),
                                ThreadPool   = this
                            };
                            tc.ScriptThread.Name         = "Script Worker: " + m_SceneID.ToString();
                            tc.ScriptThread.IsBackground = true;
                            tc.ScriptThread.Start(tc);
                            m_Threads.Add(tc);
                        }
                        catch
                        {
                            /* do not fail when we could not add a thread */
                        }
                    }
                }
            }
        }