ER chg_pri(ID tskid, PRI tskpri) { TCB *p_tcb; uint_t newbpri; ER ercd; LOG_CHG_PRI_ENTER(tskid, tskpri); CHECK_TSKCTX_UNL(); /*[NGKI1184][NGKI1185]*/ if (tskid == TSK_SELF) { p_tcb = p_runtsk; /*[NGKI1198]*/ } else { CHECK_ID(VALID_TSKID(tskid)); /*[NGKI1187]*/ p_tcb = get_tcb(tskid); } if (tskpri == TPRI_INI) { newbpri = p_tcb->p_tinib->ipriority; /*[NGKI1199]*/ } else { CHECK_PAR(VALID_TPRI(tskpri)); /*[NGKI1188]*/ newbpri = INT_PRIORITY(tskpri); } lock_cpu(); if (p_tcb->p_tinib->tskatr == TA_NOEXS) { ercd = E_NOEXS; /*[NGKI1189]*/ } else if (TSTAT_DORMANT(p_tcb->tstat)) { ercd = E_OBJ; /*[NGKI1191]*/ } else if ((p_tcb->p_lastmtx != NULL || TSTAT_WAIT_MTX(p_tcb->tstat)) && !((*mtxhook_check_ceilpri)(p_tcb, newbpri))) { ercd = E_ILUSE; /*[NGKI1201]*/ } else { p_tcb->bpriority = newbpri; /*[NGKI1192]*/ if (p_tcb->p_lastmtx == NULL || !((*mtxhook_scan_ceilmtx)(p_tcb))) { change_priority(p_tcb, newbpri, false); /*[NGKI1193]*/ if (p_runtsk != p_schedtsk) { dispatch(); } /*[NGKI1197]*/ } ercd = E_OK; } unlock_cpu(); error_exit: LOG_CHG_PRI_LEAVE(ercd); return(ercd); }
ER_UINT acre_mtx(const T_CMTX *pk_cmtx) { MTXCB *p_mtxcb; MTXINIB *p_mtxinib; ATR mtxatr; PRI ceilpri; ID domid; const DOMINIB *p_dominib; ACPTN acptn; ER ercd; LOG_ACRE_MTX_ENTER(pk_cmtx); CHECK_TSKCTX_UNL(); CHECK_MACV_READ(pk_cmtx, T_CMTX); mtxatr = pk_cmtx->mtxatr; ceilpri = pk_cmtx->ceilpri; if ((mtxatr & MTXPROTO_MASK) == TA_CEILING) { CHECK_VALIDATR(mtxatr, TA_CEILING|TA_DOMMASK); CHECK_PAR(VALID_TPRI(ceilpri)); } else { CHECK_VALIDATR(pk_cmtx->mtxatr, TA_TPRI|TA_DOMMASK); } domid = get_atrdomid(mtxatr); if (domid == TDOM_SELF) { if (rundom == TACP_KERNEL) { domid = TDOM_KERNEL; } else { domid = p_runtsk->p_tinib->domid; } mtxatr = set_atrdomid(mtxatr, domid); } switch (domid) { case TDOM_KERNEL: p_dominib = &dominib_kernel; break; case TDOM_NONE: p_dominib = &dominib_none; break; default: CHECK_RSATR(VALID_DOMID(domid)); p_dominib = get_dominib(domid); break; } CHECK_ACPTN(p_dominib->acvct.acptn1); lock_cpu(); if (tnum_mtx == 0 || queue_empty(&(p_dominib->p_domcb->free_mtxcb))) { ercd = E_NOID; } else { p_mtxcb = (MTXCB *) queue_delete_next(&(p_dominib->p_domcb->free_mtxcb)); p_mtxinib = (MTXINIB *)(p_mtxcb->p_mtxinib); p_mtxinib->mtxatr = mtxatr; p_mtxinib->ceilpri = INT_PRIORITY(ceilpri); acptn = default_acptn(domid); p_mtxinib->acvct.acptn1 = acptn; p_mtxinib->acvct.acptn2 = acptn; p_mtxinib->acvct.acptn3 = p_dominib->acvct.acptn1; p_mtxinib->acvct.acptn4 = acptn; queue_initialize(&(p_mtxcb->wait_queue)); p_mtxcb->p_loctsk = NULL; ercd = MTXID(p_mtxcb); } unlock_cpu(); error_exit: LOG_ACRE_MTX_LEAVE(ercd); return(ercd); }
ER_UINT acre_tsk(const T_CTSK *pk_ctsk) { TCB *p_tcb; TINIB *p_tinib; ATR tskatr; TASK task; PRI itskpri; size_t stksz; STK_T *stk; ER ercd; LOG_ACRE_TSK_ENTER(pk_ctsk); CHECK_TSKCTX_UNL(); tskatr = pk_ctsk->tskatr; task = pk_ctsk->task; itskpri = pk_ctsk->itskpri; stksz = pk_ctsk->stksz; stk = pk_ctsk->stk; CHECK_RSATR(tskatr, TA_ACT|TA_NOACTQUE|TARGET_TSKATR); CHECK_PAR(FUNC_ALIGN(task)); CHECK_PAR(FUNC_NONNULL(task)); CHECK_PAR(VALID_TPRI(itskpri)); CHECK_PAR(stksz >= TARGET_MIN_STKSZ); if (stk != NULL) { CHECK_PAR(STKSZ_ALIGN(stksz)); CHECK_PAR(STACK_ALIGN(stk)); } lock_cpu(); if (queue_empty(&free_tcb)) { ercd = E_NOID; } else { if (stk == NULL) { stk = kernel_malloc(ROUND_STK_T(stksz)); tskatr |= TA_MEMALLOC; } if (stk == NULL) { ercd = E_NOMEM; } else { p_tcb = ((TCB *) queue_delete_next(&free_tcb)); p_tinib = (TINIB *)(p_tcb->p_tinib); p_tinib->tskatr = tskatr; p_tinib->exinf = pk_ctsk->exinf; p_tinib->task = task; p_tinib->ipriority = INT_PRIORITY(itskpri); #ifdef USE_TSKINICTXB init_tskinictxb(&(p_tinib->tskinictxb), stksz, stk); #else /* USE_TSKINICTXB */ p_tinib->stksz = stksz; p_tinib->stk = stk; #endif /* USE_TSKINICTXB */ p_tcb->actque = false; make_dormant(p_tcb); if ((p_tcb->p_tinib->tskatr & TA_ACT) != 0U) { make_active(p_tcb); } ercd = TSKID(p_tcb); } } unlock_cpu(); error_exit: LOG_ACRE_TSK_LEAVE(ercd); return(ercd); }