public bool AddTodo(ISliceId sliceId) { DateTime t = DateTime.Now; var sliceHash = this.ComputeSliceHash(sliceId, t); if (this.AlreadyComputed(sliceId, sliceHash)) { return(false); } if (this.WorkInProgress.ContainsKey(sliceHash)) { return(false); } var priority = this.ComputePriority(sliceId, t); // by default it is based on time, but we can put whatever we want var workToDo = new WorkToDo <TPriority>(sliceId, t, sliceHash, priority); lock (this.Lock) { // Notify that the queue is not empty anymore. // The main program ends when the queue is empty and all the workers are idle this.EmptyQueue.Reset(); // Remove all the things to do which have the same slice ID // This is not true, as our analysis is not monotonic this.ToDo.Remove(workToDo); // Add to to the queue this.ToDo.Add(workToDo); // Untested option if (this.optionB1) { foreach (var p in this.WorkInProgress.GetValueOrEmpty(sliceId).AssumeNotNull()) { this.CancelWork(p.Key, p.Value); } } // Untested option if (this.optionA1) { this.WorkInProgress.Remove(sliceId); } } return(true); }
public override int Compare(WorkToDo <TPriority> x, WorkToDo <TPriority> y) { return(x.Priority.CompareTo(y.Priority)); }
protected override bool CancelWork(WorkToDo <TPriority> work, IWorkerId workerId) { return(this.workerPool.CancelWork(workerId)); }
protected virtual bool CancelWork(WorkToDo <TPriority> work, IWorkerId workerId) { return(false); }