示例#1
0
 public Module(Module other, int workerId)
 {
     Name     = other.Name;
     Provides = other.Provides;
     Requires = other.Requires;
     Script   = other.Script;
     WorkerId = workerId;
 }
示例#2
0
 // Thread-safe
 public Module Next()
 {
     return _module = _runner.GetNextModule(_workerId, _module);
 }
示例#3
0
        // Thread-safe
        private Module GetNextModule(int workerId, Module priorModule)
        {
            lock (_lock)
            {
                if (priorModule != null)
                    CompleteModule(priorModule);

                return DequeueModule(workerId);
            }
        }
示例#4
0
        private void CompleteModule(Module module)
        {
            var notify = false; // Notify waiting workers to get the next module.

            foreach (var name in module.Provides)
            {
                var subject = _subjects[name];

                // Mark this module as done
                subject.ProvidedBy.Remove(module);

                // Check if all subject's modules are done
                if (subject.ProvidedBy.Any())
                    continue;

                // Mark subject as done
                _subjects.Remove(name);
                if (!_subjects.Any())
                    // No more modules; wake sleeping workers so they can exit
                    notify = true;

                // Update dependents
                foreach (var dependent in subject.RequiredBy)
                {
                    // Mark requirement as met
                    dependent.Requires.Remove(name);

                    // Check if all of dependent's requrements are met
                    if (dependent.Requires.Any())
                        continue;

                    // All requirements met; queue the dependent
                    _queue.Enqueue(dependent);
                    notify = true;
                }
            }

            // Wake up sleeping workers
            if (notify)
                Monitor.PulseAll(_lock);
        }
示例#5
0
        private void AddModule(Module module)
        {
            foreach (var name in module.Provides)
                GetOrAddSubject(name).ProvidedBy.Add(module);

            foreach (var name in module.Requires)
                GetOrAddSubject(name).RequiredBy.Add(module);

            if (!module.Requires.Any())
                _queue.Enqueue(module);
        }
示例#6
0
        private void AcceptModule()
        {
            var module = RequireModule();

            if (module.WorkerId == Worker.All)
                for (var id = 1; id <= _parallelism; id++)
                    AddModule(new Module(module, id));
            else
                AddModule(module);

            _module = null;
        }
示例#7
0
 public void StartModule(string name)
 {
     AcceptModule();
     _module = new Module(name);
 }
示例#8
0
        public ModuleRunner(string script, Hashtable parameters, int parallelism, PSHost host)
        {
            if (script == null)
                throw new ArgumentNullException("script");
            if (parameters == null)
                throw new ArgumentNullException("parameters");
            if (parallelism < 0)
                parallelism = Environment.ProcessorCount;
            if (host == null)
                throw new ArgumentNullException("host");

            _script      = script;
            _parameters  = parameters;
            _parallelism = parallelism;
            _host        = host;
            _module      = new Module(Module.InitModuleName);
        }