Ejemplo n.º 1
0
 private void CommitTerminateThread(NsScriptThread thread)
 {
     thread.CallFrameStack.Clear();
     thread.EvalStack.Clear();
     _threads.Remove(thread);
     _terminatedThreads.Add(thread.Id);
 }
Ejemplo n.º 2
0
        internal void ProcessPendingThreadActions()
        {
            if (!IsRunning)
            {
                return;
            }
            while (PendingThreadActions.TryDequeue(out ThreadAction action))
            {
                NsScriptThread thread = action.Thread;
                switch (action.Kind)
                {
                case ThreadAction.ActionKind.Create:
                    _threads.Add(thread);
                    _newThreads.Add(thread.Id);
                    break;

                case ThreadAction.ActionKind.Terminate:
                    CommitTerminateThread(thread);
                    break;

                case ThreadAction.ActionKind.Suspend:
                    CommitSuspendThread(thread, action.Timeout);
                    break;

                case ThreadAction.ActionKind.Join:
                    Debug.Assert(action.JoinedThread is not null);
                    CommitJoin(thread, action.JoinedThread);
                    break;

                case ThreadAction.ActionKind.Resume:
                    CommitResumeThread(thread);
                    break;
                }
            }
        }
Ejemplo n.º 3
0
 public WaitOperation(
     NsScriptThread thread,
     WaitCondition condition,
     EntityQuery?entityQuery)
 {
     Thread      = thread;
     Condition   = condition;
     EntityQuery = entityQuery;
 }
Ejemplo n.º 4
0
 private void CommitResumeThread(NsScriptThread thread)
 {
     if (!IsRunning)
     {
         return;
     }
     thread.SleepTimeout   = null;
     thread.SuspensionTime = null;
 }
Ejemplo n.º 5
0
 private void CommitJoin(NsScriptThread thread, NsScriptThread target)
 {
     if (!IsRunning)
     {
         return;
     }
     thread.SuspensionTime = Ticks;
     target.WaitingThread  = thread;
 }
Ejemplo n.º 6
0
 internal void CommitSuspendThread(NsScriptThread thread, TimeSpan?timeoutOpt)
 {
     if (!IsRunning)
     {
         return;
     }
     thread.SuspensionTime = Ticks;
     if (timeoutOpt is TimeSpan timeout)
     {
         thread.SleepTimeout = (long)Math.Round(timeout.TotalSeconds * Stopwatch.Frequency);
     }
 }
Ejemplo n.º 7
0
 public NsScriptProcess(NsScriptVM vm, uint id, NsScriptThread mainThread)
 {
     VM                   = vm;
     Id                   = id;
     MainThread           = mainThread;
     _threads             = new ArrayBuilder <NsScriptThread>(16);
     PendingThreadActions = new Queue <ThreadAction>();
     _newThreads          = new ArrayBuilder <uint>(8);
     _terminatedThreads   = new ArrayBuilder <uint>(8);
     _clockBase           = 0;
     _clock               = Stopwatch.StartNew();
     AttachThread(mainThread);
 }
Ejemplo n.º 8
0
 internal void AttachThread(NsScriptThread thread)
 {
     thread.Process = this;
     PendingThreadActions.Enqueue(ThreadAction.Create(thread));
 }