Пример #1
0
        /// <summary>
        /// Sets the current thread's copy of this thread-local variable
        /// to the specified value.  Most subclasses will have no need to
        /// override this method, relying solely on the <seealso cref="#initialValue"/>
        /// method to set the values of thread-locals.
        /// </summary>
        /// <param name="value"> the value to be stored in the current thread's copy of
        ///        this thread-local. </param>
        public virtual void Set(T value)
        {
            Thread         t   = Thread.CurrentThread;
            ThreadLocalMap map = GetMap(t);

            if (map != null)
            {
                map.Set(this, value);
            }
            else
            {
                CreateMap(t, value);
            }
        }
Пример #2
0
        /// <summary>
        /// Variant of set() to establish initialValue. Used instead
        /// of set() in case user has overridden the set() method.
        /// </summary>
        /// <returns> the initial value </returns>
        private T SetInitialValue()
        {
            T              value = InitialValue();
            Thread         t     = Thread.CurrentThread;
            ThreadLocalMap map   = GetMap(t);

            if (map != null)
            {
                map.Set(this, value);
            }
            else
            {
                CreateMap(t, value);
            }
            return(value);
        }