// Token: 0x06006E18 RID: 28184 RVA: 0x0017A5A8 File Offset: 0x001787A8
 public IAsyncLocalValueMap Set(IAsyncLocal key, object value, bool treatNullValueAsNonexistent)
 {
     if (value != null || !treatNullValueAsNonexistent)
     {
         if (key == this._key1)
         {
             return(new AsyncLocalValueMap.TwoElementAsyncLocalValueMap(key, value, this._key2, this._value2));
         }
         if (key != this._key2)
         {
             return(new AsyncLocalValueMap.ThreeElementAsyncLocalValueMap(this._key1, this._value1, this._key2, this._value2, key, value));
         }
         return(new AsyncLocalValueMap.TwoElementAsyncLocalValueMap(this._key1, this._value1, key, value));
     }
     else
     {
         if (key == this._key1)
         {
             return(new AsyncLocalValueMap.OneElementAsyncLocalValueMap(this._key2, this._value2));
         }
         if (key != this._key2)
         {
             return(this);
         }
         return(new AsyncLocalValueMap.OneElementAsyncLocalValueMap(this._key1, this._value1));
     }
 }
Exemple #2
0
            public IAsyncLocalValueMap Set(IAsyncLocal key, object? value, bool treatNullValueAsNonexistent)
            {
                if (value != null || !treatNullValueAsNonexistent)
                {
                    // If the key matches one already contained in this map, then create a new three-element map with the
                    // updated value.
                    if (ReferenceEquals(key, _key1)) return new ThreeElementAsyncLocalValueMap(key, value, _key2, _value2, _key3, _value3);
                    if (ReferenceEquals(key, _key2)) return new ThreeElementAsyncLocalValueMap(_key1, _value1, key, value, _key3, _value3);
                    if (ReferenceEquals(key, _key3)) return new ThreeElementAsyncLocalValueMap(_key1, _value1, _key2, _value2, key, value);

                    // The key doesn't exist in this map, so upgrade to a multi map that contains
                    // the additional key/value pair.
                    var multi = new MultiElementAsyncLocalValueMap(4);
                    multi.UnsafeStore(0, _key1, _value1);
                    multi.UnsafeStore(1, _key2, _value2);
                    multi.UnsafeStore(2, _key3, _value3);
                    multi.UnsafeStore(3, key, value);
                    return multi;
                }
                else
                {
                    // If the key exists in this map, remove it by downgrading to a two-element map without the key.  Otherwise,
                    // there's nothing to add or remove, so just return this map.
                    return
                        ReferenceEquals(key, _key1) ? new TwoElementAsyncLocalValueMap(_key2, _value2, _key3, _value3) :
                        ReferenceEquals(key, _key2) ? new TwoElementAsyncLocalValueMap(_key1, _value1, _key3, _value3) :
                        ReferenceEquals(key, _key3) ? new TwoElementAsyncLocalValueMap(_key1, _value1, _key2, _value2) :
                        (IAsyncLocalValueMap)this;
                }
            }
 // Token: 0x06006E17 RID: 28183 RVA: 0x0017A583 File Offset: 0x00178783
 public TwoElementAsyncLocalValueMap(IAsyncLocal key1, object value1, IAsyncLocal key2, object value2)
 {
     this._key1   = key1;
     this._value1 = value1;
     this._key2   = key2;
     this._value2 = value2;
 }
Exemple #4
0
        internal static void SetLocalValue(IAsyncLocal local, object newValue, bool needChangeNotifications)
        {
            ExecutionContext current = t_currentMaybeNull ?? ExecutionContext.Default;

            object previousValue;
            bool   hadPreviousValue = current.m_localValues.TryGetValue(local, out previousValue);

            if (previousValue == newValue)
            {
                return;
            }

            current = new ExecutionContext(current);
            current.m_localValues[local] = newValue;

            t_currentMaybeNull = current;

            if (needChangeNotifications)
            {
                if (hadPreviousValue)
                {
                    Debug.Assert(current.m_localChangeNotifications.Contains(local));
                }
                else
                {
                    current.m_localChangeNotifications.Add(local);
                }

                local.OnValueChanged(previousValue, newValue, false);
            }
        }
Exemple #5
0
 public IAsyncLocalValueMap Set(IAsyncLocal key, object?value, bool treatNullValueAsNonexistent)
 {
     // If the value isn't null or a null value may not be treated as nonexistent, then create a new one-element map
     // to store the key/value pair.  Otherwise, use the empty map.
     return(value != null || !treatNullValueAsNonexistent ?
            new OneElementAsyncLocalValueMap(key, value) :
            (IAsyncLocalValueMap)this);
 }
Exemple #6
0
 public IAsyncLocalValueMap Set(IAsyncLocal key, object value)
 {
     // If the value isn't null, then create a new one-element map to store
     // the key/value pair.  If it is null, then we're still empty.
     return(value != null ?
            new OneElementAsyncLocalValueMap(key, value) :
            (IAsyncLocalValueMap)this);
 }
 // Token: 0x06006E11 RID: 28177 RVA: 0x0017A4D8 File Offset: 0x001786D8
 public IAsyncLocalValueMap Set(IAsyncLocal key, object value, bool treatNullValueAsNonexistent)
 {
     if (value == null && treatNullValueAsNonexistent)
     {
         return(this);
     }
     return(new AsyncLocalValueMap.OneElementAsyncLocalValueMap(key, value));
 }
 // Token: 0x06003A69 RID: 14953 RVA: 0x000DDB08 File Offset: 0x000DBD08
 public static IAsyncLocalValueMap Create(IAsyncLocal key, object value, bool treatNullValueAsNonexistent)
 {
     if (value == null && treatNullValueAsNonexistent)
     {
         return(AsyncLocalValueMap.Empty);
     }
     return(new AsyncLocalValueMap.OneElementAsyncLocalValueMap(key, value));
 }
 private ExecutionContext(
     Dictionary<IAsyncLocal, object> localValues,
     IAsyncLocal[] localChangeNotifications,
     bool isFlowSuppressed)
 {
     m_localValues = localValues;
     m_localChangeNotifications = localChangeNotifications;
     m_isFlowSuppressed = isFlowSuppressed;
 }
 private ExecutionContext(
     IAsyncLocalValueMap localValues,
     IAsyncLocal[] localChangeNotifications,
     bool isFlowSuppressed)
 {
     m_localValues = localValues;
     m_localChangeNotifications = localChangeNotifications;
     m_isFlowSuppressed = isFlowSuppressed;
 }
 // Token: 0x06006E1A RID: 28186 RVA: 0x0017A684 File Offset: 0x00178884
 public ThreeElementAsyncLocalValueMap(IAsyncLocal key1, object value1, IAsyncLocal key2, object value2, IAsyncLocal key3, object value3)
 {
     this._key1   = key1;
     this._value1 = value1;
     this._key2   = key2;
     this._value2 = value2;
     this._key3   = key3;
     this._value3 = value3;
 }
 // Token: 0x06006E16 RID: 28182 RVA: 0x0017A56A File Offset: 0x0017876A
 public bool TryGetValue(IAsyncLocal key, out object value)
 {
     if (key == this._key1)
     {
         value = this._value1;
         return(true);
     }
     value = null;
     return(false);
 }
Exemple #13
0
        internal static object GetLocalValue(IAsyncLocal local)
        {
            ExecutionContext current = Thread.CurrentThread.ExecutionContext;

            if (current == null)
            {
                return(null);
            }

            current.m_localValues.TryGetValue(local, out object value);
            return(value);
        }
Exemple #14
0
 public bool TryGetValue(IAsyncLocal key, out object value)
 {
     if (ReferenceEquals(key, _key1))
     {
         value = _value1;
         return(true);
     }
     else
     {
         value = null;
         return(false);
     }
 }
Exemple #15
0
 public bool TryGetValue(IAsyncLocal key, out object value)
 {
     foreach (KeyValuePair <IAsyncLocal, object> pair in _keyValues)
     {
         if (ReferenceEquals(key, pair.Key))
         {
             value = pair.Value;
             return(true);
         }
     }
     value = null;
     return(false);
 }
 // Token: 0x06006E20 RID: 28192 RVA: 0x0017ABE0 File Offset: 0x00178DE0
 public bool TryGetValue(IAsyncLocal key, out object value)
 {
     foreach (KeyValuePair <IAsyncLocal, object> keyValuePair in this._keyValues)
     {
         if (key == keyValuePair.Key)
         {
             value = keyValuePair.Value;
             return(true);
         }
     }
     value = null;
     return(false);
 }
Exemple #17
0
        internal static object GetLocalValue(IAsyncLocal local)
        {
            ExecutionContext current = t_currentMaybeNull;

            if (current == null)
            {
                return(null);
            }

            object value;

            current.m_localValues.TryGetValue(local, out value);
            return(value);
        }
            public object GetLocalValue(IAsyncLocal local)
            {
                if (this.IsNull)
                {
                    return((object)null);
                }
                if (this.m_ec._localValues == null)
                {
                    return((object)null);
                }
                object obj;

                this.m_ec._localValues.TryGetValue(local, out obj);
                return(obj);
            }
Exemple #19
0
            public object GetLocalValue(IAsyncLocal local)
            {
                if (this.IsNull)
                {
                    return(null);
                }
                if (this.m_ec._localValues == null)
                {
                    return(null);
                }
                object result;

                this.m_ec._localValues.TryGetValue(local, out result);
                return(result);
            }
Exemple #20
0
 public bool TryGetValue(IAsyncLocal key, out object? value)
 {
     if (ReferenceEquals(key, _key1))
     {
         value = _value1;
         return true;
     }
     else if (ReferenceEquals(key, _key2))
     {
         value = _value2;
         return true;
     }
     else
     {
         value = null;
         return false;
     }
 }
Exemple #21
0
        internal static void SetLocalValue(IAsyncLocal local, object newValue, bool needChangeNotifications)
        {
            ExecutionContext mutableExecutionContext = Thread.CurrentThread.GetMutableExecutionContext();
            object           obj  = null;
            bool             flag = mutableExecutionContext._localValues != null && mutableExecutionContext._localValues.TryGetValue(local, out obj);

            if (obj == newValue)
            {
                return;
            }
            IAsyncLocalValueMap asyncLocalValueMap = mutableExecutionContext._localValues;

            if (asyncLocalValueMap == null)
            {
                asyncLocalValueMap = AsyncLocalValueMap.Create(local, newValue, !needChangeNotifications);
            }
            else
            {
                asyncLocalValueMap = asyncLocalValueMap.Set(local, newValue, !needChangeNotifications);
            }
            mutableExecutionContext._localValues = asyncLocalValueMap;
            if (needChangeNotifications)
            {
                if (!flag)
                {
                    IAsyncLocal[] array = mutableExecutionContext._localChangeNotifications;
                    if (array == null)
                    {
                        array = new IAsyncLocal[]
                        {
                            local
                        };
                    }
                    else
                    {
                        int num = array.Length;
                        Array.Resize <IAsyncLocal>(ref array, num + 1);
                        array[num] = local;
                    }
                    mutableExecutionContext._localChangeNotifications = array;
                }
                local.OnValueChanged(obj, newValue, false);
            }
        }
Exemple #22
0
 public IAsyncLocalValueMap Set(IAsyncLocal key, object?value, bool treatNullValueAsNonexistent)
 {
     if (value != null || !treatNullValueAsNonexistent)
     {
         // If the key matches one already contained in this map, then create a new one-element map with the updated
         // value, otherwise create a two-element map with the additional key/value.
         return(ReferenceEquals(key, _key1) ?
                new OneElementAsyncLocalValueMap(key, value) :
                (IAsyncLocalValueMap) new TwoElementAsyncLocalValueMap(_key1, _value1, key, value));
     }
     else
     {
         // If the key exists in this map, remove it by downgrading to an empty map.  Otherwise, there's nothing to
         // add or remove, so just return this map.
         return(ReferenceEquals(key, _key1) ?
                Empty :
                (IAsyncLocalValueMap)this);
     }
 }
        internal static void SetLocalValue(IAsyncLocal local, object newValue, bool needChangeNotifications)
        {
            ExecutionContext executionContext1 = Thread.CurrentThread.GetMutableExecutionContext();
            object           previousValue     = (object)null;
            bool             flag = executionContext1._localValues != null && executionContext1._localValues.TryGetValue(local, out previousValue);

            if (previousValue == newValue)
            {
                return;
            }
            if (executionContext1._localValues == null)
            {
                executionContext1._localValues = new Dictionary <IAsyncLocal, object>();
            }
            else
            {
                ExecutionContext executionContext2          = executionContext1;
                Dictionary <IAsyncLocal, object> dictionary = new Dictionary <IAsyncLocal, object>((IDictionary <IAsyncLocal, object>)executionContext2._localValues);
                executionContext2._localValues = dictionary;
            }
            executionContext1._localValues[local] = newValue;
            if (!needChangeNotifications)
            {
                return;
            }
            if (!flag)
            {
                if (executionContext1._localChangeNotifications == null)
                {
                    executionContext1._localChangeNotifications = new List <IAsyncLocal>();
                }
                else
                {
                    ExecutionContext   executionContext2 = executionContext1;
                    List <IAsyncLocal> asyncLocalList    = new List <IAsyncLocal>((IEnumerable <IAsyncLocal>)executionContext2._localChangeNotifications);
                    executionContext2._localChangeNotifications = asyncLocalList;
                }
                executionContext1._localChangeNotifications.Add(local);
            }
            local.OnValueChanged(previousValue, newValue, false);
        }
        internal static void SetLocalValue(IAsyncLocal local, object newValue, bool needChangeNotifications)
        {
            ExecutionContext current = Thread.CurrentThread.ExecutionContext ?? ExecutionContext.Default;

            object previousValue;
            bool   hadPreviousValue = current.m_localValues.TryGetValue(local, out previousValue);

            if (previousValue == newValue)
            {
                return;
            }

            IAsyncLocalValueMap newValues = current.m_localValues.Set(local, newValue);

            //
            // Either copy the change notification array, or create a new one, depending on whether we need to add a new item.
            //
            IAsyncLocal[] newChangeNotifications = current.m_localChangeNotifications;
            if (needChangeNotifications)
            {
                if (hadPreviousValue)
                {
                    Contract.Assert(Array.IndexOf(newChangeNotifications, local) >= 0);
                }
                else
                {
                    int newNotificationIndex = newChangeNotifications.Length;
                    Array.Resize(ref newChangeNotifications, newNotificationIndex + 1);
                    newChangeNotifications[newNotificationIndex] = local;
                }
            }

            Thread.CurrentThread.ExecutionContext =
                new ExecutionContext(newValues, newChangeNotifications, current.m_isFlowSuppressed);

            if (needChangeNotifications)
            {
                local.OnValueChanged(previousValue, newValue, false);
            }
        }
 // Token: 0x06006E1B RID: 28187 RVA: 0x0017A6BC File Offset: 0x001788BC
 public IAsyncLocalValueMap Set(IAsyncLocal key, object value, bool treatNullValueAsNonexistent)
 {
     if (value != null || !treatNullValueAsNonexistent)
     {
         if (key == this._key1)
         {
             return(new AsyncLocalValueMap.ThreeElementAsyncLocalValueMap(key, value, this._key2, this._value2, this._key3, this._value3));
         }
         if (key == this._key2)
         {
             return(new AsyncLocalValueMap.ThreeElementAsyncLocalValueMap(this._key1, this._value1, key, value, this._key3, this._value3));
         }
         if (key == this._key3)
         {
             return(new AsyncLocalValueMap.ThreeElementAsyncLocalValueMap(this._key1, this._value1, this._key2, this._value2, key, value));
         }
         AsyncLocalValueMap.MultiElementAsyncLocalValueMap multiElementAsyncLocalValueMap = new AsyncLocalValueMap.MultiElementAsyncLocalValueMap(4);
         multiElementAsyncLocalValueMap.UnsafeStore(0, this._key1, this._value1);
         multiElementAsyncLocalValueMap.UnsafeStore(1, this._key2, this._value2);
         multiElementAsyncLocalValueMap.UnsafeStore(2, this._key3, this._value3);
         multiElementAsyncLocalValueMap.UnsafeStore(3, key, value);
         return(multiElementAsyncLocalValueMap);
     }
     else
     {
         if (key == this._key1)
         {
             return(new AsyncLocalValueMap.TwoElementAsyncLocalValueMap(this._key2, this._value2, this._key3, this._value3));
         }
         if (key == this._key2)
         {
             return(new AsyncLocalValueMap.TwoElementAsyncLocalValueMap(this._key1, this._value1, this._key3, this._value3));
         }
         if (key != this._key3)
         {
             return(this);
         }
         return(new AsyncLocalValueMap.TwoElementAsyncLocalValueMap(this._key1, this._value1, this._key2, this._value2));
     }
 }
Exemple #26
0
 public IAsyncLocalValueMap Set(IAsyncLocal key, object value)
 {
     if (value != null)
     {
         // The value is non-null.  If the key matches one already contained in this map,
         // then create a new two-element map with the updated value, otherwise create
         // a three-element map with the additional key/value.
         return
             (ReferenceEquals(key, _key1) ? new TwoElementAsyncLocalValueMap(key, value, _key2, _value2) :
              ReferenceEquals(key, _key2) ? new TwoElementAsyncLocalValueMap(_key1, _value1, key, value) :
              (IAsyncLocalValueMap) new ThreeElementAsyncLocalValueMap(_key1, _value1, _key2, _value2, key, value));
     }
     else
     {
         // The value is null.  If the key exists in this map, remove it by downgrading to a one-element map
         // without the key.  Otherwise, there's nothing to add or remove, so just return this map.
         return
             (ReferenceEquals(key, _key1) ? new OneElementAsyncLocalValueMap(_key2, _value2) :
              ReferenceEquals(key, _key2) ? new OneElementAsyncLocalValueMap(_key1, _value1) :
              (IAsyncLocalValueMap)this);
     }
 }
Exemple #27
0
            public IAsyncLocalValueMap Set(IAsyncLocal key, object value)
            {
                // Find the key in this map.
                for (int i = 0; i < _keyValues.Length; i++)
                {
                    if (ReferenceEquals(key, _keyValues[i].Key))
                    {
                        // The key is in the map.  If the value isn't null, then create a new map of the same
                        // size that has all of the same pairs, with this new key/value pair overwriting the old.
                        if (value != null)
                        {
                            var multi = new MultiElementAsyncLocalValueMap(_keyValues.Length);
                            Array.Copy(_keyValues, 0, multi._keyValues, 0, _keyValues.Length);
                            multi._keyValues[i] = new KeyValuePair <IAsyncLocal, object>(key, value);
                            return(multi);
                        }
                        else if (_keyValues.Length == 4)
                        {
                            // The value is null, and we only have four elements, one of which we're removing,
                            // so downgrade to a three-element map, without the matching element.
                            return
                                (i == 0 ? new ThreeElementAsyncLocalValueMap(_keyValues[1].Key, _keyValues[1].Value, _keyValues[2].Key, _keyValues[2].Value, _keyValues[3].Key, _keyValues[3].Value) :
                                 i == 1 ? new ThreeElementAsyncLocalValueMap(_keyValues[0].Key, _keyValues[0].Value, _keyValues[2].Key, _keyValues[2].Value, _keyValues[3].Key, _keyValues[3].Value) :
                                 i == 2 ? new ThreeElementAsyncLocalValueMap(_keyValues[0].Key, _keyValues[0].Value, _keyValues[1].Key, _keyValues[1].Value, _keyValues[3].Key, _keyValues[3].Value) :
                                 (IAsyncLocalValueMap) new ThreeElementAsyncLocalValueMap(_keyValues[0].Key, _keyValues[0].Value, _keyValues[1].Key, _keyValues[1].Value, _keyValues[2].Key, _keyValues[2].Value));
                        }
                        else
                        {
                            // The value is null, and we have enough elements remaining to warrant a multi map.
                            // Create a new one and copy all of the elements from this one, except the one to be removed.
                            var multi = new MultiElementAsyncLocalValueMap(_keyValues.Length - 1);
                            if (i != 0)
                            {
                                Array.Copy(_keyValues, 0, multi._keyValues, 0, i);
                            }
                            if (i != _keyValues.Length - 1)
                            {
                                Array.Copy(_keyValues, i + 1, multi._keyValues, i, _keyValues.Length - i - 1);
                            }
                            return(multi);
                        }
                    }
                }

                // The key does not already exist in this map.

                // If the value is null, then we can simply return this same map, as there's nothing to add or remove.
                if (value == null)
                {
                    return(this);
                }

                // We need to create a new map that has the additional key/value pair.
                // If with the addition we can still fit in a multi map, create one.
                if (_keyValues.Length < MaxMultiElements)
                {
                    var multi = new MultiElementAsyncLocalValueMap(_keyValues.Length + 1);
                    Array.Copy(_keyValues, 0, multi._keyValues, 0, _keyValues.Length);
                    multi._keyValues[_keyValues.Length] = new KeyValuePair <IAsyncLocal, object>(key, value);
                    return(multi);
                }

                // Otherwise, upgrade to a many map.
                var many = new ManyElementAsyncLocalValueMap(MaxMultiElements + 1);

                foreach (KeyValuePair <IAsyncLocal, object> pair in _keyValues)
                {
                    many[pair.Key] = pair.Value;
                }
                many[key] = value;
                return(many);
            }
Exemple #28
0
 internal void UnsafeStore(int index, IAsyncLocal key, object value)
 {
     Debug.Assert(index < _keyValues.Length);
     _keyValues[index] = new KeyValuePair <IAsyncLocal, object>(key, value);
 }
 private ExecutionContext(Dictionary<IAsyncLocal, object> localValues, IAsyncLocal[] localChangeNotifications)
 {
     m_localValues = localValues;
     m_localChangeNotifications = localChangeNotifications;
 }
Exemple #30
0
 public ThreeElementAsyncLocalValueMap(IAsyncLocal key1, object?value1, IAsyncLocal key2, object?value2, IAsyncLocal key3, object?value3)
 {
     _key1 = key1; _value1 = value1;
     _key2 = key2; _value2 = value2;
     _key3 = key3; _value3 = value3;
 }
Exemple #31
0
 public bool TryGetValue(IAsyncLocal key, out object value)
 {
     value = null;
     return(false);
 }
        internal static void SetLocalValue(IAsyncLocal local, object newValue, bool needChangeNotifications)
        {
            ExecutionContext current = Thread.CurrentThread.ExecutionContext ?? ExecutionContext.Default;

            object previousValue;
            bool hadPreviousValue = current.m_localValues.TryGetValue(local, out previousValue);

            if (previousValue == newValue)
                return;

            //
            // Allocate a new Dictionary containing a copy of the old values, plus the new value.  We have to do this manually to 
            // minimize allocations of IEnumerators, etc.
            //
            Dictionary<IAsyncLocal, object> newValues = new Dictionary<IAsyncLocal, object>(current.m_localValues.Count + (hadPreviousValue ? 0 : 1));

            foreach (KeyValuePair<IAsyncLocal, object> pair in current.m_localValues)
                newValues.Add(pair.Key, pair.Value);

            newValues[local] = newValue;

            //
            // Either copy the change notification array, or create a new one, depending on whether we need to add a new item.
            //
            IAsyncLocal[] newChangeNotifications = current.m_localChangeNotifications;
            if (needChangeNotifications)
            {
                if (hadPreviousValue)
                {
                    Contract.Assert(Array.IndexOf(newChangeNotifications, local) >= 0);
                }
                else
                {
                    int newNotificationIndex = newChangeNotifications.Length;
                    Array.Resize(ref newChangeNotifications, newNotificationIndex + 1);
                    newChangeNotifications[newNotificationIndex] = local;
                }
            }

            Thread.CurrentThread.ExecutionContext =
                new ExecutionContext(newValues, newChangeNotifications, current.m_isFlowSuppressed);

            if (needChangeNotifications)
            {
                local.OnValueChanged(previousValue, newValue, false);
            }
        }
        internal static void SetLocalValue(IAsyncLocal local, object newValue, bool needChangeNotifications)
        {
            ExecutionContext current = Thread.CurrentThread.ExecutionContext ?? ExecutionContext.Default;

            object previousValue;
            bool hadPreviousValue = current.m_localValues.TryGetValue(local, out previousValue);

            if (previousValue == newValue)
                return;

            IAsyncLocalValueMap newValues = current.m_localValues.Set(local, newValue);

            //
            // Either copy the change notification array, or create a new one, depending on whether we need to add a new item.
            //
            IAsyncLocal[] newChangeNotifications = current.m_localChangeNotifications;
            if (needChangeNotifications)
            {
                if (hadPreviousValue)
                {
                    Contract.Assert(Array.IndexOf(newChangeNotifications, local) >= 0);
                }
                else
                {
                    int newNotificationIndex = newChangeNotifications.Length;
                    Array.Resize(ref newChangeNotifications, newNotificationIndex + 1);
                    newChangeNotifications[newNotificationIndex] = local;
                }
            }

            Thread.CurrentThread.ExecutionContext =
                new ExecutionContext(newValues, newChangeNotifications, current.m_isFlowSuppressed);

            if (needChangeNotifications)
            {
                local.OnValueChanged(previousValue, newValue, false);
            }
        }
        internal static object GetLocalValue(IAsyncLocal local)
        {
            ExecutionContext current = Thread.CurrentThread.ExecutionContext;
            if (current == null)
                return null;

            object value;
            current.m_localValues.TryGetValue(local, out value);
            return value;
        }
            public object GetLocalValue(IAsyncLocal local)
            {
                if (IsNull)
                    return null;

                if (m_ec._localValues == null)
                    return null;

                object value;
                m_ec._localValues.TryGetValue(local, out value);
                return value;
            }
        internal static void SetLocalValue(IAsyncLocal local, object newValue, bool needChangeNotifications)
        {
            ExecutionContext current = t_currentMaybeNull ?? ExecutionContext.Default;

            object previousValue;
            bool hadPreviousValue = current.m_localValues.TryGetValue(local, out previousValue);

            if (previousValue == newValue)
                return;

            current = new ExecutionContext(current);
            current.m_localValues[local] = newValue;

            t_currentMaybeNull = current;

            if (needChangeNotifications)
            {
                if (hadPreviousValue)
                    Contract.Assert(current.m_localChangeNotifications.Contains(local));
                else
                    current.m_localChangeNotifications.Add(local);

                local.OnValueChanged(previousValue, newValue, false);
            }
        }
Exemple #37
0
 public OneElementAsyncLocalValueMap(IAsyncLocal key, object value)
 {
     _key1 = key; _value1 = value;
 }
Exemple #38
0
 public TwoElementAsyncLocalValueMap(IAsyncLocal key1, object?value1, IAsyncLocal key2, object?value2)
 {
     _key1 = key1; _value1 = value1;
     _key2 = key2; _value2 = value2;
 }