/* _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ Funtion :_bk_sus_tsk Input :struct task *task < task to suspend > Output :void Return :ER < result > Description :suspend a task for btron _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ */ EXPORT ER _bk_sus_tsk(struct task *task) { TSTAT state; ER ercd = E_OK; state = (TSTAT)task->state; if ( !task_alive(state) ) { ercd = ( state == TS_NONEXIST )? E_NOEXS: E_OBJ; goto error_exit; } if ( task == ctxtsk && dispatch_disabled >= DDS_DISABLE ) { ercd = E_CTX; goto error_exit; } if ( task->suscnt == INT_MAX ) { ercd = E_QOVR; goto error_exit; } /* Update suspend request count */ ++task->suscnt; /* Move to forced wait state */ if ( state == TS_READY ) { make_non_ready(task); task->state = TS_SUSPEND; } else if ( state == TS_WAIT ) { task->state = TS_WAITSUS; } error_exit: return ercd; }
/* * Task finalization * Call from critical section */ LOCAL void _ter_tsk( TCB *tcb ) { TSTAT state; if ( tcb->svclocked != NULL ) { /* Unlock all extended SVC locks */ AllUnlockSVC(tcb); } state = (TSTAT)tcb->state; if ( state == TS_READY ) { make_non_ready(tcb); } else if ( (state & TS_WAIT) != 0 ) { wait_cancel(tcb); if ( tcb->wspec->rel_wai_hook != NULL ) { (*tcb->wspec->rel_wai_hook)(tcb); } } #ifdef NUM_MTXID /* signal mutex */ signal_all_mutex(tcb); #endif cleanup_context(tcb); }
/* * Suspend task */ SYSCALL ER _tk_sus_tsk( ID tskid ) { TCB *tcb; TSTAT state; ER ercd = E_OK; CHECK_TSKID(tskid); CHECK_NONSELF(tskid); tcb = get_tcb(tskid); BEGIN_CRITICAL_SECTION; state = (TSTAT)tcb->state; if ( !task_alive(state) ) { ercd = ( state == TS_NONEXIST )? E_NOEXS: E_OBJ; goto error_exit; } if ( tcb == ctxtsk && dispatch_disabled >= DDS_DISABLE ) { ercd = E_CTX; goto error_exit; } if ( tcb->suscnt == INT_MAX ) { ercd = E_QOVR; goto error_exit; } /* Update suspend request count */ ++tcb->suscnt; /* Move to forced wait state */ if ( state == TS_READY ) { make_non_ready(tcb); tcb->state = TS_SUSPEND; } else if ( state == TS_WAIT ) { tcb->state = TS_WAITSUS; } error_exit: END_CRITICAL_SECTION; return ercd; }