Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/28/10 01:44:33 (14 years ago)
Author:
swagner
Message:

Revoked changes of r5177 (#1333)

Location:
branches/ParallelEngine/HeuristicLab.Parameters/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ParallelEngine/HeuristicLab.Parameters/3.3/LookupParameter.cs

    r4722 r5178  
    5252    }
    5353    public new T ActualValue {
    54       get {
    55         if (cachedActualValue == null) cachedActualValue = GetActualValue();
    56         return (T)cachedActualValue;
    57       }
    58       set {
    59         cachedActualValue = value;
    60         SetActualValue(value);
    61       }
     54      get { return (T)base.ActualValue; }
     55      set { base.ActualValue = value; }
    6256    }
    6357
  • branches/ParallelEngine/HeuristicLab.Parameters/3.3/Parameter.cs

    r4722 r5178  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using System.Collections.Generic;
     28using System.Threading;
    2729
    2830namespace HeuristicLab.Parameters {
     
    5355      get { return dataType; }
    5456    }
    55     protected IItem cachedActualValue;
     57    protected Dictionary<int, IItem> cachedActualValues;
    5658    public IItem ActualValue {
    5759      get {
    58         if (cachedActualValue == null) cachedActualValue = GetActualValue();
    59         return cachedActualValue;
     60        int id = Thread.CurrentThread.ManagedThreadId;
     61        IItem value = null;
     62        lock (cachedActualValues) {
     63          cachedActualValues.TryGetValue(id, out value);
     64        }
     65        if (value == null) {
     66          value = GetActualValue();
     67          lock (cachedActualValues) {
     68            if (cachedActualValues.ContainsKey(id)) cachedActualValues[id] = value;
     69            else cachedActualValues.Add(id, value);
     70          }
     71        }
     72        return value;
    6073      }
    6174      set {
    62         cachedActualValue = value;
     75        int id = Thread.CurrentThread.ManagedThreadId;
     76        lock (cachedActualValues) {
     77          if (cachedActualValues.ContainsKey(id)) cachedActualValues[id] = value;
     78          else cachedActualValues.Add(id, value);
     79        }
    6380        SetActualValue(value);
    6481      }
    6582    }
    66     [Storable]
    67     private IExecutionContext executionContext;
     83    private Dictionary<int, IExecutionContext> executionContexts;
    6884    public IExecutionContext ExecutionContext {
    69       get { return executionContext; }
     85      get {
     86        int id = Thread.CurrentThread.ManagedThreadId;
     87        IExecutionContext context = null;
     88        lock (executionContexts) {
     89          executionContexts.TryGetValue(id, out context);
     90        }
     91        return context;
     92      }
    7093      set {
    71         if (value != executionContext) {
    72           executionContext = value;
    73           cachedActualValue = null;
    74           OnExecutionContextChanged();
     94        IExecutionContext context = null;
     95        int id = Thread.CurrentThread.ManagedThreadId;
     96        lock (executionContexts) {
     97          executionContexts.TryGetValue(id, out context);
     98          if (value != context) {
     99            if (context == null) executionContexts.Add(id, value);
     100            else if (value == null) {
     101              executionContexts.Remove(id);
     102              lock (cachedActualValues) cachedActualValues.Remove(id);
     103            } else {
     104              executionContexts[id] = value;
     105              lock (cachedActualValues) cachedActualValues.Remove(id);
     106            }
     107          }
    75108        }
    76109      }
     
    78111
    79112    [StorableConstructor]
    80     protected Parameter(bool deserializing) : base(deserializing) { }
     113    protected Parameter(bool deserializing) : base(deserializing) {
     114      cachedActualValues = new Dictionary<int, IItem>();
     115      executionContexts = new Dictionary<int, IExecutionContext>();
     116    }
    81117    protected Parameter(Parameter original, Cloner cloner)
    82118      : base(original, cloner) {
    83119      dataType = original.dataType;
    84       executionContext = cloner.Clone(original.executionContext);
     120      cachedActualValues = new Dictionary<int, IItem>();
     121      executionContexts = new Dictionary<int, IExecutionContext>();
     122      foreach (var item in original.executionContexts) {
     123        executionContexts.Add(item.Key, cloner.Clone(item.Value));
     124      }
    85125    }
    86126    protected Parameter()
    87127      : base("Anonymous") {
    88128      dataType = typeof(IItem);
     129      cachedActualValues = new Dictionary<int, IItem>();
     130      executionContexts = new Dictionary<int, IExecutionContext>();
    89131    }
    90132    protected Parameter(string name, Type dataType)
     
    92134      if (dataType == null) throw new ArgumentNullException();
    93135      this.dataType = dataType;
     136      cachedActualValues = new Dictionary<int, IItem>();
     137      executionContexts = new Dictionary<int, IExecutionContext>();
    94138    }
    95139    protected Parameter(string name, string description, Type dataType)
     
    97141      if (dataType == null) throw new ArgumentNullException();
    98142      this.dataType = dataType;
     143      cachedActualValues = new Dictionary<int, IItem>();
     144      executionContexts = new Dictionary<int, IExecutionContext>();
    99145    }
    100146
     
    105151    protected abstract IItem GetActualValue();
    106152    protected abstract void SetActualValue(IItem value);
    107 
    108     protected virtual void OnExecutionContextChanged() { }
    109153  }
    110154}
Note: See TracChangeset for help on using the changeset viewer.