Changeset 5178 for branches/ParallelEngine/HeuristicLab.Parameters
- Timestamp:
- 12/28/10 01:44:33 (14 years ago)
- Location:
- branches/ParallelEngine/HeuristicLab.Parameters/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ParallelEngine/HeuristicLab.Parameters/3.3/LookupParameter.cs
r4722 r5178 52 52 } 53 53 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; } 62 56 } 63 57 -
branches/ParallelEngine/HeuristicLab.Parameters/3.3/Parameter.cs
r4722 r5178 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using System.Collections.Generic; 28 using System.Threading; 27 29 28 30 namespace HeuristicLab.Parameters { … … 53 55 get { return dataType; } 54 56 } 55 protected IItem cachedActualValue;57 protected Dictionary<int, IItem> cachedActualValues; 56 58 public IItem ActualValue { 57 59 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; 60 73 } 61 74 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 } 63 80 SetActualValue(value); 64 81 } 65 82 } 66 [Storable] 67 private IExecutionContext executionContext; 83 private Dictionary<int, IExecutionContext> executionContexts; 68 84 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 } 70 93 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 } 75 108 } 76 109 } … … 78 111 79 112 [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 } 81 117 protected Parameter(Parameter original, Cloner cloner) 82 118 : base(original, cloner) { 83 119 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 } 85 125 } 86 126 protected Parameter() 87 127 : base("Anonymous") { 88 128 dataType = typeof(IItem); 129 cachedActualValues = new Dictionary<int, IItem>(); 130 executionContexts = new Dictionary<int, IExecutionContext>(); 89 131 } 90 132 protected Parameter(string name, Type dataType) … … 92 134 if (dataType == null) throw new ArgumentNullException(); 93 135 this.dataType = dataType; 136 cachedActualValues = new Dictionary<int, IItem>(); 137 executionContexts = new Dictionary<int, IExecutionContext>(); 94 138 } 95 139 protected Parameter(string name, string description, Type dataType) … … 97 141 if (dataType == null) throw new ArgumentNullException(); 98 142 this.dataType = dataType; 143 cachedActualValues = new Dictionary<int, IItem>(); 144 executionContexts = new Dictionary<int, IExecutionContext>(); 99 145 } 100 146 … … 105 151 protected abstract IItem GetActualValue(); 106 152 protected abstract void SetActualValue(IItem value); 107 108 protected virtual void OnExecutionContextChanged() { }109 153 } 110 154 }
Note: See TracChangeset
for help on using the changeset viewer.