Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/04/19 17:31:54 (5 years ago)
Author:
mkommend
Message:

#2521: Added cancellation token to evaluate function of problems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/EvaluationCache.cs

    r17226 r17320  
    3131using System.Threading;
    3232using Google.ProtocolBuffers;
     33using HEAL.Attic;
    3334using HeuristicLab.Common;
    3435using HeuristicLab.Common.Resources;
     
    3637using HeuristicLab.Data;
    3738using HeuristicLab.Parameters;
    38 using HEAL.Attic;
    3939
    4040namespace HeuristicLab.Problems.ExternalEvaluation {
     
    5050      private byte[] rawMessage;
    5151
    52       private object lockObject = new object();
     52      private readonly object lockObject = new object();
    5353
    5454      public byte[] RawMessage {
     
    116116    }
    117117
    118     public delegate QualityMessage Evaluator(SolutionMessage message);
     118    public delegate QualityMessage Evaluator(SolutionMessage message, CancellationToken cancellationToken);
    119119    #endregion
    120120
     
    124124
    125125    private HashSet<string> activeEvaluations = new HashSet<string>();
    126     private object cacheLock = new object();
     126    private readonly object cacheLock = new object();
    127127    #endregion
    128128
     
    221221    }
    222222
    223     void CapacityChanged(object sender, EventArgs e) {
     223    private void CapacityChanged(object sender, EventArgs e) {
    224224      if (Capacity < 0)
    225225        throw new ArgumentOutOfRangeException("Cache capacity cannot be less than zero");
     
    240240    }
    241241
    242     public QualityMessage GetValue(SolutionMessage message, Evaluator evaluate, ExtensionRegistry extensions) {
     242    public QualityMessage GetValue(SolutionMessage message, Evaluator evaluate, ExtensionRegistry extensions, CancellationToken cancellationToken) {
    243243      var entry = new CacheEntry(message.ToString());
    244244      bool lockTaken = false;
     
    267267              OnChanged();
    268268              try {
    269                 entry.SetMessage(evaluate(message));
     269                entry.SetMessage(evaluate(message, cancellationToken));
    270270                Monitor.Enter(cacheLock, ref lockTaken);
    271271                index[entry] = list.AddLast(entry);
Note: See TracChangeset for help on using the changeset viewer.