Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/29/13 14:39:02 (11 years ago)
Author:
mkommend
Message:

#1427: Moved actual value caching and execution contexts from Paramater to LookupParameter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs

    r7259 r9195  
    2222using System;
    2323using System.Drawing;
    24 using System.Threading;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
     
    3332  [Item("Parameter", "A base class for parameters.")]
    3433  [StorableClass]
    35   public abstract class Parameter : NamedItem, IParameter, IStatefulItem {
     34  public abstract class Parameter : NamedItem, IParameter {
    3635    public override Image ItemImage {
    3736      get {
     
    6766    }
    6867
    69     private Lazy<ThreadLocal<IItem>> cachedActualValues;
    7068    public IItem ActualValue {
    71       get {
    72         if (cachedActualValues.Value.Value == null) cachedActualValues.Value.Value = GetActualValue();
    73         return cachedActualValues.Value.Value;
    74       }
    75       set {
    76         cachedActualValues.Value.Value = value;
    77         SetActualValue(value);
    78       }
    79     }
    80     private Lazy<ThreadLocal<IExecutionContext>> executionContexts;
    81     public IExecutionContext ExecutionContext {
    82       get { return executionContexts.Value.Value; }
    83       set {
    84         if (value != executionContexts.Value.Value) {
    85           executionContexts.Value.Value = value;
    86           cachedActualValues.Value.Value = null;
    87         }
    88       }
     69      get { return GetActualValue(); }
     70      set { SetActualValue(value); }
    8971    }
    9072
     
    9274    protected Parameter(bool deserializing)
    9375      : base(deserializing) {
    94       cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    95       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    9676    }
    9777    protected Parameter(Parameter original, Cloner cloner)
     
    9979      dataType = original.dataType;
    10080      hidden = original.hidden;
    101       cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    102       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    10381    }
    10482    protected Parameter()
     
    10684      dataType = typeof(IItem);
    10785      hidden = false;
    108       cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    109       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    11086    }
    11187    protected Parameter(string name, Type dataType)
     
    11490      this.dataType = dataType;
    11591      hidden = false;
    116       cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    117       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    11892    }
    11993    protected Parameter(string name, string description, Type dataType)
     
    12296      this.dataType = dataType;
    12397      hidden = false;
    124       cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    125       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    126     }
    127 
    128     public virtual void InitializeState() { }
    129     public virtual void ClearState() {
    130       cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    131       executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
    13298    }
    13399
Note: See TracChangeset for help on using the changeset viewer.