private Activity DequeueActivity(bool firstRun) { // Load the available activities into the queue if the queue is empty // or on first run (repeat session situation) if (!ExecutionQueue.Any() || firstRun) { // Add activities based on the execution count which describes // the overall distribution or weight of different activities // being executed. List <Activity> activities = new List <Activity>(); foreach (var item in MasterList.OrderBy(n => n.ExecutionOrder)) { activities.Add(item); } if (Randomize) { // If randomize was set for this collection of activities, then shuffle them activities.Shuffle(); TraceFactory.Logger.Debug("Activities were shuffled"); } foreach (Activity activity in activities) { // Then enqueue each activity onto the execution queue. ExecutionQueue.Enqueue(activity); } } _currentActivityExecutionCount = 1; return(ExecutionQueue.Dequeue()); }
/// <summary> /// Initializes a new instance of the <see cref="LoopbackRingMaster"/> class. /// </summary> /// <param name="backend">Backend core</param> /// <param name="readOnlyInterfaceRequiresLocks">Whether readonly interface requires locks</param> /// <param name="allowWrites">Whether write operation is allowed</param> public LoopbackRingMaster(RingMasterBackendCore backend, bool readOnlyInterfaceRequiresLocks, bool allowWrites) : base("loopback:0", 0, null) { this.backend = backend ?? throw new ArgumentNullException("backend"); this.session = backend.GetLoopbackSession(string.Empty, false, allowWrites, readOnlyInterfaceRequiresLocks); this.executionQueue = new ExecutionQueue(this.maxThreads); this.session.ROInterfaceRequiresLocks = readOnlyInterfaceRequiresLocks; }
public static void Spawn(MulticastDelegate f) { var sw = Stopwatch.StartNew(); var e = new WaitExecution(CurrentScript, (LuaThread)LuaThread.running().Values[0], 0, () => f.FastDynamicInvoke(sw.Elapsed.TotalSeconds, Game.Workspace.DistributedGameTime)); ExecutionQueue.Enqueue(e); }
public static double Wait(double seconds) { seconds = Math.Max(seconds, LuaSettings.DefaultWaitTime); var sw = Stopwatch.StartNew(); var e = new WaitExecution(CurrentScript, (LuaThread)LuaThread.running().Values[0], seconds); ExecutionQueue.Enqueue(e); YieldThread(); return(sw.Elapsed.TotalSeconds); }
public void Populate(ExecutionQueue executionQueue, ServiceRunner serviceRunner, HiraComponentContainer target, IBlackboardComponent blackboard) { if (Collection4.Length == 0) { executionQueue.Append(AutoSucceedExecutable.INSTANCE); } foreach (var provider in Collection4) { executionQueue.Append(provider.GetExecutable(target, blackboard)); } foreach (var serviceProvider in Collection5) { serviceRunner.Append(serviceProvider.GetService(target, blackboard)); } }
public void InitializeEmptyExecutionQueue() { ITaskExecutor taskQueue = new ExecutionQueue("EQ"); taskQueue.Start(); if (!taskQueue.IsStarted) { throw new InvalidOperationException(); } taskQueue.Stop(true); if (taskQueue.IsStarted) { throw new InvalidOperationException(); } }
private Activity DequeueActivity(bool firstRun) { //during a repeat session the previous session would have queued the execution queue, which makes it run out of order by 1 activity //by clearning the queue for the repeat session, we maintain the same order. if (firstRun) { ExecutionQueue.Clear(); } //if there is any queued item return the topmost if (ExecutionQueue.Any()) { return(ExecutionQueue.Dequeue()); } // Load the available activities into the queue if the queue is empty // or on first run (repeat session situation) // Add activities based on the execution count which describes // the overall distribution or weight of different activities // being executed. List <Activity> activities = new List <Activity>(); foreach (var activity in MasterList.OrderBy(n => n.ExecutionOrder)) { for (int i = 0; i < activity.ExecutionValue; i++) { activities.Add(activity); } } if (Randomize) { activities.Shuffle(); TraceFactory.Logger.Debug("Activities were shuffled"); } foreach (Activity activity in activities) { ExecutionQueue.Enqueue(activity); } return(ExecutionQueue.Dequeue()); }
public Thread processExecutionQueue() { return(O2Thread.mtaThread( () => { if (ExecutionQueue.Count == 0) { return; } while (ExecutingRequest.WaitOne(1000).isFalse()) // after one second check if the next command is Ctrl+C { if (ExecutionQueue.Peek() == "Ctrl+C") { //ExecutionQueue.Dequeue(); "breaking loop".error(); //cmdApi.hostCmd_Ctrl_C(); break; } } //ExecutingRequest.Reset(); //if (ExecutionQueue.Count == 0) // return; LastCommandResult = new StringBuilder(); var cmdToExecute = ExecutionQueue.Dequeue(); "executing Queued command:{0}".format(cmdToExecute).debug(); //"from queue, executing cmd:{0}".format(cmdToExecute).debug(); //cmd(cmdToExecute); sosApi.setShowHideReceivedDataForCommand(cmdToExecute); if (cmdToExecute == "Ctrl+C") { cmdApi.hostCmd_Ctrl_C(); } else { cmdApi.hostCmd(cmdToExecute); cmdApi.hostCmd(extraExecutionCommand); // so we can detect when the execution is completed } })); }
internal static void Init() { LoggerInternal = LogManager.GetLogger(nameof(ScriptService)); EnumTypes = typeof(Engine).Assembly.GetTypes().Where(x => x.IsEnum); CacheTypes(); Lua = new Lua(LuaIntegerType.Int32, LuaFloatType.Double); GlobalEnvironment = new ScriptGlobal(Lua); ExecutionQueue = new ConcurrentWorkQueue <Execution>(execution => { if (!execution.TryFulfill()) { ExecutionQueue.Enqueue(execution); // send to back of queue } else { execution.Set(); } }); }
// TODO: Execution logic could use a major refacoring, as it has been quite spaghettified at the moment. public void ExecuteAll(ExecutionMetadata metadata = null) { if (metadata == null) // If null, then create a fresh one. { metadata = new ExecutionMetadata(); } if (IsExecuting) { return; } IsExecuting = true; while (ExecutionQueue.Count != 0) { IExecutable executable = ExecutionQueue.Dequeue(); executable.Execute(metadata); } IsExecuting = false; }
public void InitializeExecuteActions() { ITaskExecutor taskQueue = new ExecutionQueue(); int counter = 0; taskQueue.Start(); taskQueue.Add((e) => { counter++; }); taskQueue.Add((e) => { if (counter == 1) { counter++; } }); taskQueue.Add((e) => { if (counter == 2) { counter++; } }); // complete all tasks: taskQueue.Stop(true); Assert.AreEqual(3, counter, "3 Tasks should perform their job!"); }
internal void Post(SendOrPostCallback d, object state, bool mainThreadAffinitized) { using (this.Factory.Context.NoMessagePumpSynchronizationContext.Apply()) { SingleExecuteProtector wrapper = null; List <AsyncManualResetEvent> eventsNeedNotify = null; // initialized if we should pulse it at the end of the method bool postToFactory = false; bool isCompleteRequested; bool synchronouslyBlockingMainThread; lock (this.owner.Context.SyncContextLock) { isCompleteRequested = this.IsCompleteRequested; synchronouslyBlockingMainThread = this.SynchronouslyBlockingMainThread; } if (isCompleteRequested) { // This job has already been marked for completion. // We need to forward the work to the fallback mechanisms. postToFactory = true; } else { bool mainThreadQueueUpdated = false; bool backgroundThreadQueueUpdated = false; wrapper = SingleExecuteProtector.Create(this, d, state); if (ThreadingEventSource.Instance.IsEnabled()) { ThreadingEventSource.Instance.PostExecutionStart(wrapper.GetHashCode(), mainThreadAffinitized); } if (mainThreadAffinitized && !synchronouslyBlockingMainThread) { wrapper.RaiseTransitioningEvents(); } lock (this.owner.Context.SyncContextLock) { if (mainThreadAffinitized) { if (this.mainThreadQueue == null) { this.mainThreadQueue = new ExecutionQueue(this); } // Try to post the message here, but we'll also post to the underlying sync context // so if this fails (because the operation has completed) we'll still get the work // done eventually. this.mainThreadQueue.TryEnqueue(wrapper); mainThreadQueueUpdated = true; } else { if (this.SynchronouslyBlockingThreadPool) { if (this.threadPoolQueue == null) { this.threadPoolQueue = new ExecutionQueue(this); } backgroundThreadQueueUpdated = this.threadPoolQueue.TryEnqueue(wrapper); if (!backgroundThreadQueueUpdated) { ThreadPool.QueueUserWorkItem(SingleExecuteProtector.ExecuteOnceWaitCallback, wrapper); } } else { ThreadPool.QueueUserWorkItem(SingleExecuteProtector.ExecuteOnceWaitCallback, wrapper); } } if (mainThreadQueueUpdated || backgroundThreadQueueUpdated) { var tasksNeedNotify = this.GetDependingSynchronousTasks(mainThreadQueueUpdated); if (tasksNeedNotify.Count > 0) { eventsNeedNotify = new List <AsyncManualResetEvent>(tasksNeedNotify.Count); foreach (var taskToNotify in tasksNeedNotify) { if (taskToNotify.pendingEventSource == null || taskToNotify == this) { taskToNotify.pendingEventSource = this.WeakSelf; } taskToNotify.pendingEventCount++; if (taskToNotify.queueNeedProcessEvent != null) { eventsNeedNotify.Add(taskToNotify.queueNeedProcessEvent); } } } } } } // Notify tasks which can process the event queue. if (eventsNeedNotify != null) { foreach (var queueEvent in eventsNeedNotify) { queueEvent.PulseAll(); } } // We deferred this till after we release our lock earlier in this method since we're calling outside code. if (postToFactory) { Assumes.Null(wrapper); // we avoid using a wrapper in this case because this job transferring ownership to the factory. this.Factory.Post(d, state, mainThreadAffinitized); } else if (mainThreadAffinitized) { Assumes.NotNull(wrapper); // this should have been initialized in the above logic. this.owner.PostToUnderlyingSynchronizationContextOrThreadPool(wrapper); foreach (var nestingFactory in this.nestingFactories) { if (nestingFactory != this.owner) { nestingFactory.PostToUnderlyingSynchronizationContextOrThreadPool(wrapper); } } } } }
public void addToExecutionQueue(string cmdToExecute) // for use by the SonOfStrikeApi callback and implements the multithread queue { "Queueing command:{0}".format(cmdToExecute).debug(); ExecutionQueue.Enqueue(cmdToExecute); processExecutionQueue(); }
private async Task <T> Run <T>(Task <T> task) { ExecutionQueue.Enqueue(task); Process(); return(await task); }
private async Task Run(Task task) { ExecutionQueue.Enqueue(task); Process(); await task; }
public void EnqueueExecutable(IExecutable executable) { ExecutionQueue.Enqueue(executable); }
/// <summary> /// Starts the wire backup /// </summary> public void Start() { this.toUpload = new ExecutionQueue(1); this.FindFilesToArchived(); }
/// <summary> /// Stops the wire backup /// </summary> public void Stop() { this.OnTimer(null); this.toUpload.Drain(ExecutionQueue.DrainMode.DisallowAllFurtherEnqueuesAndRemoveAllElements); this.toUpload = null; }