internal void ExitCPUContext(ICPUContext CPUContext) { System.Diagnostics.Debug.Assert(CPUContext.IsCurrent()); ((CPUContext)CPUContext).Release(); // UnlockCPUでは、deleteしたCPUContextに対してEndDelaySuspendを // 呼んでしまうので、その手前の処理のみ実行。 int TlsLockCount = (int)m_TlsIndex.Value; TlsLockCount--; // ロック解除 if (TlsLockCount == 0) { m_SysSem.Release(); Interlocked.Decrement(ref m_Locked); } m_TlsIndex.Value = TlsLockCount; m_IntEvent.Set(); CPUContext.Exit(); }
public ER Wait(LinkedList <Task> WaitQueue, TSKWAIT tskwait, ID wid, TMO tmout) { ER Result; System.Diagnostics.Debug.Assert(m_CPUContext.IsCurrent()); if (m_rtsk.tskstat == TSKSTAT.TTS_SUS) { m_rtsk.tskstat = TSKSTAT.TTS_WAS; } else if (m_rtsk.tskstat == TSKSTAT.TTS_RUN) { System.Diagnostics.Debug.Assert(m_Nucleus.m_CurrentTask == this); m_rtsk.tskstat = TSKSTAT.TTS_WAI; m_Nucleus.m_CurrentTask = null; } else { m_rtsk.tskstat = TSKSTAT.TTS_WAI; } m_rtsk.tskwait = tskwait; m_rtsk.wid = wid; m_Nucleus.m_ReadyQueue[m_rtsk.tskpri].Remove(this); // 待ちタスクキューへ追加 WaitQueue.AddLast(this); // タイマー設定 SetState(false, tmout, WaitQueue, OnTimeOut); // タスクスケジューリング if (m_CPUContext.Dispatch()) { if (State) { Result = ER.E_TMOUT; } else { Result = ER.E_OK; } } else { m_rtsk.tskstat = TSKSTAT.TTS_RUN; m_ReleaseWait = true; Result = ER.E_RLWAI; } return(Result); }
public void Terminate() { if (m_Terminate && m_Thread == null) { DoTerminate(); } else { m_Terminate = true; m_IntEvent.Set(); } if ((m_Current != null) && m_Current.IsCurrent()) { ExitCPUContext(m_Current); } }