/// <summary> /// Submit the given task to the task queue. /// </summary> /// <remarks> /// <para> /// If this task already has a task in the queue, the currently enqueued /// task will be replaced with the given one. /// </para> /// <para> /// Since tasks are most likely run from a separate thread than that in /// which they are created, it is recommended that the provided task be /// immutable, which will guarantee its thread-safety. Using a mutable /// task object will most likely be a race condition between the tasks /// queue and the task itself. /// </para> /// </remarks> /// <param name="task">The task to submit</param> public void Submit(IGlTask task) { impl.Submit(task); }
public Impl(GlTaskQueue taskQueue) { this.taskQueue = taskQueue; this.wrappedTask = null; }
public void Submit(IGlTask task) { // Use an atomic operation to ensure that the task is submitted exactly once. // Set the task to a value, and if no task was there already, we have the // go-ahead to submit the task. bool shouldSubmit = Interlocked.Exchange(ref wrappedTask, task) == null; if (shouldSubmit) { taskQueue.SubmitTask(this); } }
/// <summary> /// Submits a task for execution /// </summary> /// <remarks> /// <para> /// Submitting a task does not guarantee that it will be executed right away, or /// even in the near future - only that it will be executed eventually. /// </para> /// <para> /// Though this class is called a queue, submitted tasks are not guaranteed to /// execute in the order that they are submitted. If one task has a dependency /// on another, the depending task should not be submitted until the dependent /// task has completed. It is safe to submit a task from another task, so this /// is a simple option for handling that use-case. /// </para> /// </remarks> /// <param name="task">The task to execute</param> public void SubmitTask(IGlTask task) { Debug.Assert(task != null, "Cannot submit a null task"); tasks.Enqueue(task); }