Esempio n. 1
0
        static bool TryRemoveThreadedTask(List <KSPTSTaskGroup> taskGroupList, Func <object, object> threadedTask)
        {
            for (int i = 0; i < taskGroupList.Count; i++)
            {
                KSPTSTaskGroup tmpTaskGroup = taskGroupList[i];
                if (threadedTask.Equals(tmpTaskGroup.threadedTask))
                {
                    taskGroupList.Remove(tmpTaskGroup);
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Queues up all registered tasks and sends them to the thread pool to be processed
        /// </summary>
        /// <param name="group">Threading group to queue tasks for</param>
        void QueueThreadingGroupTasks(KSPTSThreadingGroup group)
        {
            List <KSPTSTaskGroup> tmpTaskGroupList = registeredTasks._groupTasks[group];

            for (int i = 0; i < tmpTaskGroupList.Count; i++)
            {
                KSPTSTaskGroup tmpTaskGroup = tmpTaskGroupList[i];
                object         tmpObject    = null;
                if (tmpTaskGroup.preFunction != null)
                {
                    tmpObject = tmpTaskGroup.preFunction();
                }

                _threadPool.EnqueueNewTask(tmpTaskGroup.threadedTask, tmpObject, tmpTaskGroup.postFunction, group);
            }
            _postFunctionsRemaining[group] = tmpTaskGroupList.Count;
        }
Esempio n. 3
0
        /// <summary>
        /// Internal task registration method
        /// </summary>
        /// <param name="threadingGroup">Determines which loop to synchronize with and when</param>
        /// <param name="newTaskGroup">Class holding all pre-function, threadedTask, and post-function data</param>
        internal static void RegisterNewThreadTask(KSPTSThreadingGroup threadingGroup, KSPTSTaskGroup newTaskGroup)
        {
            KSPTSRegisteredTasks registeredTasks = KSPTSThreadController.instance.registeredTasks;

            registeredTasks._groupTasks[threadingGroup].Add(newTaskGroup);
        }
Esempio n. 4
0
 /// <summary>
 /// Register a task with a pre-function to run in the main Unity thread before starting the threadedTask and a post-function to run in the main Unity thread after finishing the threadedTask
 /// </summary>
 /// <param name="threadingGroup">Determines which loop to synchronize with and when</param>
 /// <param name="preFunction">Method that returns an object passed to the threadedTask as a parameter; run in the main Unity thread before threadedTask is started</param>
 /// <param name="threadedTask">Task that takes an object as a parameter and returns an object</param>
 /// <param name="postFunction">Void Method that takes an object as a parameter and is run in the main Unity thread after threadedTask completes</param>
 public static void RegisterNewThreadTask(KSPTSThreadingGroup threadingGroup, Func<object> preFunction, Func<object, object> threadedTask, Action<object> postFunction)
 {
     KSPTSTaskGroup newTaskGroup = new KSPTSTaskGroup(preFunction, threadedTask, postFunction);
     RegisterNewThreadTask(threadingGroup, newTaskGroup);
 }
Esempio n. 5
0
        /// <summary>
        /// Internal task registration method
        /// </summary>
        /// <param name="threadingGroup">Determines which loop to synchronize with and when</param>
        /// <param name="newTaskGroup">Class holding all pre-function, threadedTask, and post-function data</param>
        internal static void RegisterNewThreadTask(KSPTSThreadingGroup threadingGroup, KSPTSTaskGroup newTaskGroup)
        {
            KSPTSRegisteredTasks registeredTasks = KSPTSThreadController.instance.registeredTasks;

            registeredTasks._groupTasks[threadingGroup].Add(newTaskGroup);
        }
Esempio n. 6
0
        /// <summary>
        /// Register a task with a pre-function to run in the main Unity thread before starting the threadedTask and a post-function to run in the main Unity thread after finishing the threadedTask
        /// </summary>
        /// <param name="threadingGroup">Determines which loop to synchronize with and when</param>
        /// <param name="preFunction">Method that returns an object passed to the threadedTask as a parameter; run in the main Unity thread before threadedTask is started</param>
        /// <param name="threadedTask">Task that takes an object as a parameter and returns an object</param>
        /// <param name="postFunction">Void Method that takes an object as a parameter and is run in the main Unity thread after threadedTask completes</param>
        public static void RegisterNewThreadTask(KSPTSThreadingGroup threadingGroup, Func <object> preFunction, Func <object, object> threadedTask, Action <object> postFunction)
        {
            KSPTSTaskGroup newTaskGroup = new KSPTSTaskGroup(preFunction, threadedTask, postFunction);

            RegisterNewThreadTask(threadingGroup, newTaskGroup);
        }