Exemple #1
0
        /// <summary>
        /// Removes the specified dependencies from this stage.
        /// </summary>
        /// <param name="dependee">The stage to remove dependencies for.</param>
        /// <param name="dependencies">The dependencies to remove.</param>
        public static void RemoveDependencies(this IPipelineStage dependee, params IPipelineStage[] dependencies)
        {
            lock (Dependencies)
            {
                foreach (var dependency in dependencies)
                {
                    if (dependency == null)
                    {
                        IncrementOperation();
                        MarkPipelineAsUpdated();
                        throw new ArgumentNullException("Entry in dependency list", "One or more entries in the given dependency list was null.");
                    }

                    var strong = new AmbivalentPipelineReference(dependency, true);
                    if (!Dependencies.TryGetValue(strong, out var deps))
                    {
                        continue;
                    }
                    TotalWeakKeys -= deps.RemoveAll(r => !r.TryGetTarget(out var reference) || reference == dependee);

                    GC.KeepAlive(dependency);
                }
                IncrementOperation();
                // TODO: remove this? Removed dependencies should never affect the propagation of the pipeline graph in any way.
                MarkPipelineAsUpdated();
            }
        }
Exemple #2
0
        /// <summary>
        /// Add dependencies for this pipeline stage, propagation on their invalidation.
        /// </summary>
        /// <param name="dependee">The stage to add dependencies for.</param>
        /// <param name="dependencies">The dependencies to add.</param>
        public static void AddDependencies(this IPipelineStage dependee, params IPipelineStage[] dependencies)
        {
            lock (Dependencies)
            {
                foreach (var dependency in dependencies)
                {
                    if (dependency == null)
                    {
                        IncrementOperation();
                        MarkPipelineAsUpdated();
                        throw new ArgumentNullException("Entry in dependency list", "One or more entries in the given dependency list was null.");
                    }

                    var weak = new AmbivalentPipelineReference(dependency, false);
                    if (!Dependencies.TryGetValue(weak, out var deps))
                    {
                        deps = new List <WeakReference <IPipelineStage> >();
                        Dependencies.Add(weak, deps);
                    }
                    deps.Add(new WeakReference <IPipelineStage>(dependee));
                    ++TotalWeakKeys;

                    GC.KeepAlive(dependency); //keep the reference alive at least until it can be added in the dictionary
                }
                IncrementOperation();
                MarkPipelineAsUpdated();
            }
        }
Exemple #3
0
        private static IEnumerable <WeakReference <IPipelineStage> > InternalGetDependencies(IPipelineStage stage)
        {
            IncrementOperation();
            var strong = new AmbivalentPipelineReference(stage, true);

            if (!Dependencies.TryGetValue(strong, out var dependencies))
            {
                return(Enumerable.Empty <WeakReference <IPipelineStage> >());
            }

            TotalWeakKeys -= RemoveNonExisting(dependencies);

            return(dependencies);
        }