ER sac_sem(ID semid, const ACVCT *p_acvct) { SEMCB *p_semcb; SEMINIB *p_seminib; ER ercd; LOG_SAC_SEM_ENTER(semid, p_acvct); CHECK_TSKCTX_UNL(); CHECK_SEMID(semid); CHECK_MACV_READ(p_acvct, ACVCT); p_semcb = get_semcb(semid); t_lock_cpu(); if (p_semcb->p_seminib->sematr == TA_NOEXS) { ercd = E_NOEXS; } else if (VIOLATE_ACPTN(p_semcb->p_seminib->acvct.acptn3)) { ercd = E_OACV; } else if (SEMID(p_semcb) > tmax_ssemid) { p_seminib = (SEMINIB *)(p_semcb->p_seminib); p_seminib->acvct = *p_acvct; ercd = E_OK; } else { ercd = E_OBJ; } t_unlock_cpu(); error_exit: LOG_SAC_SEM_LEAVE(ercd); return(ercd); }
ER_UINT acre_sem(const T_CSEM *pk_csem) { SEMCB *p_semcb; SEMINIB *p_seminib; ER ercd; LOG_ACRE_SEM_ENTER(pk_csem); CHECK_TSKCTX_UNL(); CHECK_RSATR(pk_csem->sematr, TA_TPRI); CHECK_PAR(0 <= pk_csem->isemcnt && pk_csem->isemcnt <= pk_csem->maxsem); CHECK_PAR(1 <= pk_csem->maxsem && pk_csem->maxsem <= TMAX_MAXSEM); t_lock_cpu(); if (tnum_sem == 0 || queue_empty(&free_semcb)) { ercd = E_NOID; } else { p_semcb = ((SEMCB *) queue_delete_next(&free_semcb)); p_seminib = (SEMINIB *)(p_semcb->p_seminib); p_seminib->sematr = pk_csem->sematr; p_seminib->isemcnt = pk_csem->isemcnt; p_seminib->maxsem = pk_csem->maxsem; queue_initialize(&(p_semcb->wait_queue)); p_semcb->semcnt = p_semcb->p_seminib->isemcnt; ercd = SEMID(p_semcb); } t_unlock_cpu(); error_exit: LOG_ACRE_SEM_LEAVE(ercd); return(ercd); }
ER_UINT acre_sem(const T_CSEM *pk_csem) { ID domid; SEMCB *p_semcb; SEMINIB *p_seminib; ACPTN acptn; ER ercd; LOG_ACRE_SEM_ENTER(pk_csem); CHECK_TSKCTX_UNL(); CHECK_MACV_READ(pk_csem, T_CSEM); CHECK_RSATR(pk_csem->sematr, TA_TPRI|TA_DOMMASK); domid = get_atrdomid(pk_csem->sematr); CHECK_ATRDOMID_INACTIVE(domid); CHECK_PAR(0 <= pk_csem->isemcnt && pk_csem->isemcnt <= pk_csem->maxsem); CHECK_PAR(1 <= pk_csem->maxsem && pk_csem->maxsem <= TMAX_MAXSEM); CHECK_ACPTN(sysstat_acvct.acptn3); t_lock_cpu(); if (tnum_sem == 0 || queue_empty(&free_semcb)) { ercd = E_NOID; } else { p_semcb = ((SEMCB *) queue_delete_next(&free_semcb)); p_seminib = (SEMINIB *)(p_semcb->p_seminib); p_seminib->sematr = pk_csem->sematr; p_seminib->isemcnt = pk_csem->isemcnt; p_seminib->maxsem = pk_csem->maxsem; acptn = default_acptn(domid); p_seminib->acvct.acptn1 = acptn; p_seminib->acvct.acptn2 = acptn; p_seminib->acvct.acptn3 = acptn | rundom; p_seminib->acvct.acptn4 = acptn; queue_initialize(&(p_semcb->wait_queue)); p_semcb->semcnt = p_semcb->p_seminib->isemcnt; ercd = SEMID(p_semcb); } t_unlock_cpu(); error_exit: LOG_ACRE_SEM_LEAVE(ercd); return(ercd); }
ER del_sem(ID semid) { SEMCB *p_semcb; SEMINIB *p_seminib; const DOMINIB *p_dominib; ER ercd; LOG_DEL_SEM_ENTER(semid); CHECK_TSKCTX_UNL(); CHECK_ID(VALID_SEMID(semid)); p_semcb = get_semcb(semid); lock_cpu(); if (p_semcb->p_seminib->sematr == TA_NOEXS) { ercd = E_NOEXS; } else if (VIOLATE_ACPTN(p_semcb->p_seminib->acvct.acptn3)) { ercd = E_OACV; } else if (SEMID(p_semcb) <= tmax_ssemid) { ercd = E_OBJ; } else { init_wait_queue(&(p_semcb->wait_queue)); p_seminib = (SEMINIB *)(p_semcb->p_seminib); p_dominib = get_atrdominib(p_seminib->sematr); p_seminib->sematr = TA_NOEXS; queue_insert_prev(&(p_dominib->p_domcb->free_semcb), &(p_semcb->wait_queue)); if (p_runtsk != p_schedtsk) { dispatch(); } ercd = E_OK; } unlock_cpu(); error_exit: LOG_DEL_SEM_LEAVE(ercd); return(ercd); }
ER del_sem(ID semid) { SEMCB *p_semcb; SEMINIB *p_seminib; bool_t dspreq; ER ercd; LOG_DEL_SEM_ENTER(semid); CHECK_TSKCTX_UNL(); CHECK_SEMID(semid); p_semcb = get_semcb(semid); t_lock_cpu(); if (p_semcb->p_seminib->sematr == TA_NOEXS) { ercd = E_NOEXS; } else if (VIOLATE_ACPTN(p_semcb->p_seminib->acvct.acptn3)) { ercd = E_OACV; } else if (SEMID(p_semcb) > tmax_ssemid) { dspreq = init_wait_queue(&(p_semcb->wait_queue)); p_seminib = (SEMINIB *)(p_semcb->p_seminib); p_seminib->sematr = TA_NOEXS; queue_insert_prev(&free_semcb, &(p_semcb->wait_queue)); if (dspreq) { dispatch(); } ercd = E_OK; } else { ercd = E_OBJ; } t_unlock_cpu(); error_exit: LOG_DEL_SEM_LEAVE(ercd); return(ercd); }
ER ref_tsk(ID tskid, T_RTSK *pk_rtsk) { TCB *p_tcb; uint_t tstat; ER ercd; LOG_REF_TSK_ENTER(tskid, pk_rtsk); CHECK_TSKCTX_UNL(); CHECK_TSKID_SELF(tskid); p_tcb = get_tcb_self(tskid); t_lock_cpu(); tstat = p_tcb->tstat; if (TSTAT_DORMANT(tstat)) { /* * 対象タスクが休止状態の場合 */ pk_rtsk->tskstat = TTS_DMT; } else { /* * タスク状態の取出し */ if (TSTAT_SUSPENDED(tstat)) { if (TSTAT_WAITING(tstat)) { pk_rtsk->tskstat = TTS_WAS; } else { pk_rtsk->tskstat = TTS_SUS; } } else if (TSTAT_WAITING(tstat)) { pk_rtsk->tskstat = TTS_WAI; } else if (p_tcb == p_runtsk) { pk_rtsk->tskstat = TTS_RUN; } else { pk_rtsk->tskstat = TTS_RDY; } /* * 現在優先度とベース優先度の取出し */ pk_rtsk->tskpri = EXT_TSKPRI(p_tcb->priority); pk_rtsk->tskbpri = EXT_TSKPRI(p_tcb->bpriority); if (TSTAT_WAITING(tstat)) { /* * 待ち要因と待ち対象のオブジェクトのIDの取出し */ switch (tstat & TS_WAIT_MASK) { case TS_WAIT_SLP: pk_rtsk->tskwait = TTW_SLP; break; case TS_WAIT_DLY: pk_rtsk->tskwait = TTW_DLY; break; case TS_WAIT_SEM: pk_rtsk->tskwait = TTW_SEM; pk_rtsk->wobjid = SEMID(((WINFO_SEM *)(p_tcb->p_winfo)) ->p_semcb); break; case TS_WAIT_FLG: pk_rtsk->tskwait = TTW_FLG; pk_rtsk->wobjid = FLGID(((WINFO_FLG *)(p_tcb->p_winfo)) ->p_flgcb); break; case TS_WAIT_SDTQ: pk_rtsk->tskwait = TTW_SDTQ; pk_rtsk->wobjid = DTQID(((WINFO_DTQ *)(p_tcb->p_winfo)) ->p_dtqcb); break; case TS_WAIT_RDTQ: pk_rtsk->tskwait = TTW_RDTQ; pk_rtsk->wobjid = DTQID(((WINFO_DTQ *)(p_tcb->p_winfo)) ->p_dtqcb); break; case TS_WAIT_SPDQ: pk_rtsk->tskwait = TTW_SPDQ; pk_rtsk->wobjid = PDQID(((WINFO_PDQ *)(p_tcb->p_winfo)) ->p_pdqcb); break; case TS_WAIT_RPDQ: pk_rtsk->tskwait = TTW_RPDQ; pk_rtsk->wobjid = PDQID(((WINFO_PDQ *)(p_tcb->p_winfo)) ->p_pdqcb); break; case TS_WAIT_MBX: pk_rtsk->tskwait = TTW_MBX; pk_rtsk->wobjid = MBXID(((WINFO_MBX *)(p_tcb->p_winfo)) ->p_mbxcb); break; case TS_WAIT_MPF: pk_rtsk->tskwait = TTW_MPF; pk_rtsk->wobjid = MPFID(((WINFO_MPF *)(p_tcb->p_winfo)) ->p_mpfcb); break; } /* * タイムアウトするまでの時間の取出し */ if (p_tcb->p_winfo->p_tmevtb != NULL) { pk_rtsk->lefttmo = (TMO) tmevt_lefttim(p_tcb->p_winfo->p_tmevtb); } else { pk_rtsk->lefttmo = TMO_FEVR; } } /* * 起床要求キューイング数の取出し */ pk_rtsk->wupcnt = p_tcb->wupque ? 1U : 0U; } /* * 起動要求キューイング数の取出し */ pk_rtsk->actcnt = p_tcb->actque ? 1U : 0U; ercd = E_OK; t_unlock_cpu(); error_exit: LOG_REF_TSK_LEAVE(ercd, pk_rtsk); return(ercd); }
ER ref_tsk(ID tskid, T_RTSK *pk_rtsk) { TCB *p_tcb; uint_t tstat; ER ercd; LOG_REF_TSK_ENTER(tskid, pk_rtsk); CHECK_TSKCTX_UNL(); CHECK_TSKID_SELF(tskid); p_tcb = get_tcb_self(tskid); t_lock_cpu(); tstat = p_tcb->tstat; if (TSTAT_DORMANT(tstat)) { /* * when task is in dormant status */ pk_rtsk->tskstat = TTS_DMT; } else { /* * get task status */ if (TSTAT_SUSPENDED(tstat)) { if (TSTAT_WAITING(tstat)) { pk_rtsk->tskstat = TTS_WAS; } else { pk_rtsk->tskstat = TTS_SUS; } } else if (TSTAT_WAITING(tstat)) { pk_rtsk->tskstat = TTS_WAI; } else if (p_tcb == p_runtsk) { pk_rtsk->tskstat = TTS_RUN; } else { pk_rtsk->tskstat = TTS_RDY; } /* * get current priority and base priority */ pk_rtsk->tskpri = EXT_TSKPRI(p_tcb->priority); pk_rtsk->tskbpri = EXT_TSKPRI(p_tcb->priority); if (TSTAT_WAITING(tstat)) { /* * if the task is in waiting * get the waiting reason and wait objects id */ switch (tstat & TS_WAIT_MASK) { case TS_WAIT_SLP: pk_rtsk->tskwait = TTW_SLP; break; case TS_WAIT_DLY: pk_rtsk->tskwait = TTW_DLY; break; case TS_WAIT_SEM: pk_rtsk->tskwait = TTW_SEM; pk_rtsk->wobjid = SEMID(((WINFO_SEM *)(p_tcb->p_winfo)) ->p_semcb); break; case TS_WAIT_FLG: pk_rtsk->tskwait = TTW_FLG; pk_rtsk->wobjid = FLGID(((WINFO_FLG *)(p_tcb->p_winfo)) ->p_flgcb); break; case TS_WAIT_SDTQ: pk_rtsk->tskwait = TTW_SDTQ; pk_rtsk->wobjid = DTQID(((WINFO_DTQ *)(p_tcb->p_winfo)) ->p_dtqcb); break; case TS_WAIT_RDTQ: pk_rtsk->tskwait = TTW_RDTQ; pk_rtsk->wobjid = DTQID(((WINFO_DTQ *)(p_tcb->p_winfo)) ->p_dtqcb); break; case TS_WAIT_SPDQ: pk_rtsk->tskwait = TTW_SPDQ; pk_rtsk->wobjid = PDQID(((WINFO_PDQ *)(p_tcb->p_winfo)) ->p_pdqcb); break; case TS_WAIT_RPDQ: pk_rtsk->tskwait = TTW_RPDQ; pk_rtsk->wobjid = PDQID(((WINFO_PDQ *)(p_tcb->p_winfo)) ->p_pdqcb); break; case TS_WAIT_MBX: pk_rtsk->tskwait = TTW_MBX; pk_rtsk->wobjid = MBXID(((WINFO_MBX *)(p_tcb->p_winfo)) ->p_mbxcb); break; case TS_WAIT_MPF: pk_rtsk->tskwait = TTW_MPF; pk_rtsk->wobjid = MPFID(((WINFO_MPF *)(p_tcb->p_winfo)) ->p_mpfcb); break; } /* * get left time before timeout */ if (p_tcb->p_winfo->p_tmevtb != NULL) { pk_rtsk->lefttmo = (TMO) tmevt_lefttim(p_tcb->p_winfo->p_tmevtb); } else { pk_rtsk->lefttmo = TMO_FEVR; } } /* * get wakeup request */ pk_rtsk->wupcnt = p_tcb->wupque ? 1U : 0U; } /* * get activation request */ pk_rtsk->actcnt = p_tcb->actque ? 1U : 0U; ercd = E_OK; t_unlock_cpu(); error_exit: LOG_REF_TSK_LEAVE(ercd, pk_rtsk); return(ercd); }
ER_UINT acre_sem(const T_CSEM *pk_csem) { SEMCB *p_semcb; SEMINIB *p_seminib; ATR sematr; uint_t isemcnt, maxsem; ID domid; const DOMINIB *p_dominib; ACPTN acptn; ER ercd; LOG_ACRE_SEM_ENTER(pk_csem); CHECK_TSKCTX_UNL(); CHECK_MACV_READ(pk_csem, T_CSEM); sematr = pk_csem->sematr; isemcnt = pk_csem->isemcnt; maxsem = pk_csem->maxsem; CHECK_VALIDATR(sematr, TA_TPRI|TA_DOMMASK); CHECK_PAR(0 <= isemcnt && isemcnt <= maxsem); CHECK_PAR(1 <= maxsem && maxsem <= TMAX_MAXSEM); domid = get_atrdomid(sematr); if (domid == TDOM_SELF) { if (rundom == TACP_KERNEL) { domid = TDOM_KERNEL; } else { domid = p_runtsk->p_tinib->domid; } sematr = set_atrdomid(sematr, 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_sem == 0 || queue_empty(&(p_dominib->p_domcb->free_semcb))) { ercd = E_NOID; } else { p_semcb = (SEMCB *) queue_delete_next(&(p_dominib->p_domcb->free_semcb)); p_seminib = (SEMINIB *)(p_semcb->p_seminib); p_seminib->sematr = sematr; p_seminib->isemcnt = isemcnt; p_seminib->maxsem = maxsem; acptn = default_acptn(domid); p_seminib->acvct.acptn1 = acptn; p_seminib->acvct.acptn2 = acptn; p_seminib->acvct.acptn3 = p_dominib->acvct.acptn1; p_seminib->acvct.acptn4 = acptn; queue_initialize(&(p_semcb->wait_queue)); p_semcb->semcnt = isemcnt; ercd = SEMID(p_semcb); } unlock_cpu(); error_exit: LOG_ACRE_SEM_LEAVE(ercd); return(ercd); }