示例#1
0
 // TODO: Put strings into the resources.
 //
 protected override void QueueTask(Task task)
 {
     task.EnsureNotNull(nameof(task));
     //
     if (_tasksQueue.UpdateValue(o => o.Contains(task) ? o : o.Add(task)))
     {
         for (; ;)
         {
             var processQueueRunningCount = VolatileUtilities.Read(ref _processQueueRunningCount);
             if (processQueueRunningCount < _maxDop)
             {
                 if (processQueueRunningCount == Interlocked.CompareExchange(ref _processQueueRunningCount, processQueueRunningCount + 1, processQueueRunningCount))
                 {
                     P_ProcessQueue();
                     break;
                 }
             }
             else
             {
                 break;
             }
         }
     }
     else
     {
         throw new InvalidOperationException($"Указанная задача уже ранее была поставлена в очередь шедулера '{this}'.");
     }
 }
示例#2
0
 /// <summary>
 /// Метод, вызываемый перед явной или неявной выгрузкой.
 /// <para>Не предназначен для прямого вызова из кода.</para>
 /// <para>Метод не вызывается после того, как один из вызывов был выполнен успешно.</para>
 /// <para>На момент вызова метода <seealso cref="Disposable.IsDisposeRequested"/> == true.</para>
 /// <para>Перед вызовом базовой реализации <seealso cref="Disposable.FireBeforeDispose(bool)"/> вызывает обработчик события <seealso cref="BeforeDispose"/>.</para>
 /// </summary>
 /// <param name="explicitDispose">Указывает на явную/не явную выгрузку.</param>
 protected override void FireBeforeDispose(bool explicitDispose)
 {
     if (explicitDispose)
     {
         VolatileUtilities.Read(ref _eventHandler_BeforeDispose)?.Invoke(this, new DisposeEventArgs(explicitDispose));
     }
     //
     base.FireBeforeDispose(explicitDispose);
 }
示例#3
0
        static bool P_ValT_ValueUpdater <T>(MuttableVh <T> valueStore, Transform <T> transform)
            where T : struct
        {
            transform.EnsureNotNull(nameof(transform));
            //
            var currentVersion = valueStore.ReadDA(ref valueStore._value);
            var newValue       = transform(currentVersion);

            if (EqualityComparer <T> .Default.Equals(x: currentVersion, y: newValue))
            {
                return(false);
            }
            else
            {
                VolatileUtilities.Write(ref valueStore._value, newValue);
                valueStore.EnsureNotDisposeState();
                return(true);
            }
        }
示例#4
0
        protected override void FireAfterDisposed(bool explicitDispose)
        {
            base.FireAfterDisposed(explicitDispose);
            //
            var notExceptionThrown = true;

            try {
                if (explicitDispose)
                {
                    VolatileUtilities.Read(ref _eventHandler_AfterDisposed)?.Invoke(this, new DisposeEventArgs(explicitDispose));
                }
            } catch {
                notExceptionThrown = false;
                throw;
            } finally {
                if (notExceptionThrown)
                {
                    VolatileUtilities.Write(ref _eventHandler_AfterDisposed, null);
                }
            }
        }
示例#5
0
        static MuttableVh()
        {
            __DefaultValue = default;
            //
            var typeOfValue = typeof(TValue);
            var valueStoreInstanceParameter = Expression.Parameter(typeof(MuttableVh <TValue>));
            var transformParameter          = Expression.Parameter(typeof(Transform <TValue>));

            if (typeOfValue.IsValueType())
            {
                __Setter = (locValueStore, locValue) => VolatileUtilities.Write(ref locValueStore._value, locValue);
                //
                __Updater =
                    Expression
                    .Lambda <Func <MuttableVh <TValue>, Transform <TValue>, bool> >(
                        body:
                        Expression
                        .Call(
                            method:
                            typeof(MuttableVh <TValue>)
                            .GetMethod(nameof(P_ValT_ValueUpdater), BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.NonPublic)
                            .MakeGenericMethod(typeOfValue),
                            arg0: valueStoreInstanceParameter,
                            arg1: transformParameter),
                        parameters: new[] { valueStoreInstanceParameter, transformParameter })
                    .Compile();
                //
                if (typeof(IDisposable).IsAssignableFrom(typeOfValue))
                {
                    var valueParameter = Expression.Parameter(typeOfValue);
                    __ExplicitDispose =
                        Expression
                        .Lambda <Action <TValue> >(
                            body:
                            Expression
                            .Call(
                                instance: valueParameter,
                                method: typeOfValue.GetMethod(nameof(IDisposable.Dispose), throwIfNotFound: true)),
                            parameters: new[] { valueParameter })
                        .Compile();
                }
                else
                {
                    __ExplicitDispose = locValue => { }
                };
                //
                if (typeof(IEonCloneable).IsAssignableFrom(typeOfValue))
                {
                    var valueParameter        = Expression.Parameter(typeOfValue);
                    var cloneContextParameter = Expression.Parameter(typeof(ICloneContext));
                    __CloneValue = Expression.Lambda <Func <TValue, ICloneContext, TValue> >(
                        Expression.Call(
                            valueParameter,
                            typeOfValue.GetMethod(
                                nameof(IEonCloneable.Clone),
                                parameterTypes: new[] { cloneContextParameter.Type },
                                throwIfNotFound: true),
                            cloneContextParameter),
                        valueParameter,
                        cloneContextParameter).Compile();
                }
                else
                {
                    __CloneValue = (v, c) => v;
                }
            }
            else
            {
                var valueParameter = Expression.Parameter(typeOfValue);
                //
                __Setter =
                    Expression
                    .Lambda <Action <MuttableVh <TValue>, TValue> >(
                        body:
                        Expression
                        .Call(
                            method:
                            typeof(MuttableVh <TValue>)
                            .GetMethod(nameof(P_RefT_ValueSetter), BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.NonPublic)
                            .MakeGenericMethod(typeOfValue),
                            arg0: valueStoreInstanceParameter,
                            arg1: valueParameter),
                        parameters: new[] { valueStoreInstanceParameter, valueParameter })
                    .Compile();
                //
                __Updater =
                    Expression
                    .Lambda <Func <MuttableVh <TValue>, Transform <TValue>, bool> >(
                        body:
                        Expression
                        .Call(
                            method:
                            typeof(MuttableVh <TValue>)
                            .GetMethod(nameof(P_RefT_ValueUpdater), BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.NonPublic)
                            .MakeGenericMethod(typeOfValue),
                            arg0: valueStoreInstanceParameter,
                            arg1: transformParameter),
                        parameters: new[] { valueStoreInstanceParameter, transformParameter })
                    .Compile();
                //
                if (typeof(IDisposable).IsAssignableFrom(typeOfValue))
                {
                    __ExplicitDispose = Expression.Lambda <Action <TValue> >(Expression.Call(typeof(MuttableVh <TValue>).GetMethod(nameof(P_RefT_ExplicitDispose), BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.NonPublic).MakeGenericMethod(typeOfValue), valueParameter), valueParameter).Compile();
                }
                else
                {
                    __ExplicitDispose = v => { }
                };
                //
                if (typeof(IEonCloneable).IsAssignableFrom(typeOfValue))
                {
                    var cloneContextParameter = Expression.Parameter(typeof(ICloneContext));
                    __CloneValue = Expression.Lambda <Func <TValue, ICloneContext, TValue> >(
                        Expression.Condition(
                            Expression.ReferenceEqual(valueParameter, Expression.Constant(null, valueParameter.Type)),
                            valueParameter,
                            Expression.Convert(
                                Expression.Call(
                                    Expression.Convert(valueParameter, typeof(IEonCloneable)),
                                    typeof(IEonCloneable).GetMethod(
                                        nameof(IEonCloneable.Clone),
                                        parameterTypes: new[] { cloneContextParameter.Type },
                                        throwIfNotFound: true),
                                    cloneContextParameter),
                                valueParameter.Type)),
                        valueParameter,
                        cloneContextParameter).Compile();
                }
                else
                {
                    __CloneValue = (v, c) => v;
                }
            }
        }