Ejemplo n.º 1
0
        public void Schedule(Action action, Func <float> priority)
        {
            Contract.Assert(priority != null);

            BloxelTask task = new BloxelTask(action, priority);

            lock (_taskSync)
            {
                _tasks.Add(task);
                Monitor.Pulse(_taskSync); // signal next worker thread that we have a task ready
            }
        }
Ejemplo n.º 2
0
        private BloxelTask NextTask()
        {
            BloxelTask ret       = null; // highest priority = task with lowest priority value
            int        taskIndex = -1;

            _tasks.RemoveAll(t => t.Priority < 0.0f);

            // assuming the calling thread has a lock...
            for (int i = 0; i < _tasks.Count; i++)
            {
                if (ret == null || _tasks[i].Priority < ret.Priority)
                {
                    ret       = _tasks[i];
                    taskIndex = i;
                }
            }

            if (taskIndex >= 0)
            {
                _tasks.RemoveAt(taskIndex); // work like a queue; dequeue it from the list
            }
            return(ret);
        }