?? ss_task.c
字號:
#if (ERRCLASS & ERRCLS_INT_PAR)
/* check entity and instance ranges */
if (ent >= SS_MAX_ENT || inst >= SS_MAX_INST)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS502, ERRZERO, "Invalid entity/instance");
RETVALUE(RFAILED);
}
#endif
/* Lock the system task table. We do this to prevent
* the system task from being destroyed and confusing
* matters before we detach.
*/
ret = SLock(&osCp.sTskTblLock);
if (ret != ROK)
{
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS503, (ErrVal) ret,
"Could not lock system task table");
#endif
RETVALUE(RFAILED);
}
/* lock the TAPA task table */
SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
if (ret != ROK)
{
SUnlock(&osCp.sTskTblLock);
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS504, ERRZERO,
"Could not lock TAPA task table");
#endif
RETVALUE(RFAILED);
}
#if (ERRCLASS & ERRCLS_INT_PAR)
/* Check this TAPA task. We do this with the TAPA task table
* locked, coz we don't want the task to be found, but then
* be deregistered before we lock
*/
if (osCp.tTskIds[ent][inst] == SS_TSKNC)
{
SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
SUnlock(&osCp.sTskTblLock);
SSLOGERROR(ERRCLS_INT_PAR, ESS505, ERRZERO, "Unknown task");
RETVALUE(RFAILED);
}
#endif
idx = osCp.tTskIds[ent][inst];
tTsk = &osCp.tTskTbl[idx];
/* check if this TAPA task is attached to anyone */
if (tTsk->sTsk == NULLP)
{
SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
SUnlock(&osCp.sTskTblLock);
RETVALUE(ROK);
}
/* we get the system task entry out */
sTsk = tTsk->sTsk;
/* We unlock the TAPA task table here, and then re-lock it later
* because of lock sequencing--we have to lock the system task
* entry first, and then the TAPA task table. Note, the system
* task table is locked, so nobody can sneak in and destroy the
* system task while we're doing this.
*/
SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
/* lock the system task entry */
if (!SS_CHECK_CUR_STSK(sTsk))
{
ret = SLock(&sTsk->lock);
if (ret != ROK)
{
SUnlock(&osCp.sTskTblLock);
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS506, (ErrVal) ret,
"Could not lock system task entry");
#endif
RETVALUE(RFAILED);
}
}
/* now we lock the TAPA task table */
SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
if (ret != ROK)
{
SUnlock(&sTsk->lock);
SUnlock(&osCp.sTskTblLock);
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS507, ERRZERO,
"Could not lock TAPA task table");
#endif
RETVALUE(RFAILED);
}
/* Now, we can safely update both the system task entry
* and the TAPA task entry. First, we update the TAPA
* task entry--nobody is running it now.
*/
tTsk->sTsk = NULLP;
/* Remove this TAPA task from the system task's list of
* TAPA tasks to run.
*/
for (i = 0; i < SS_MAX_TTSKS; i++)
{
if (sTsk->tTsks[i] == idx)
{
sTsk->tTsks[i] = SS_INVALID_IDX;
sTsk->numTTsks--;
break;
}
}
/* call the implementation to do anything it needs to */
ret = ssdDetachTTsk(tTsk);
/* unlock the TAPA task table */
SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
/* unlock the system task entry */
if (!SS_CHECK_CUR_STSK(sTsk))
{
SUnlock(&sTsk->lock);
}
/* unlock the system task table */
SUnlock(&osCp.sTskTblLock);
/* If the implementation couldn't detach the task, we just
* return an error, nothing else we can do.
*/
if (ret != ROK)
{
RETVALUE(RFAILED);
}
RETVALUE(ROK);
} /* SDetachTTsk */
/*
*
* Fun: Post a message to a task
*
* Desc: This function is used to post a message to a TAPA
* task. The message is delivered to the demand queue
* of the system task that is running the specified
* destination task.
*
* Ret: ROK - ok
* RFAILED - failed, general (optional)
*
* Notes:
*
* File: ss_task.c
*
*/
#ifdef ANSI
PUBLIC S16 SPstTsk
(
Pst *pst, /* post information */
Buffer *mBuf /* message to post */
)
#else
PUBLIC S16 SPstTsk(pst, mBuf)
Pst *pst; /* post information */
Buffer *mBuf; /* message to post */
#endif
{
S16 r;
S16 i;
S16 j;
SsIdx dstIdx;
SsIdx srcIdx;
Prior prior;
SsTTskEntry *tTsk;
SsMsgInfo *msgInfo;
#if (defined(SS_DRVR_SUPPORT) || defined(SS_RTR_SUPPORT))
Pst nPst;
Bool nPstUsed = FALSE;
#endif
#if (defined(SS_RTR_SUPPORT))
Route rte;
#endif
TRC1(SPstTsk);
UNUSED(j);
#if (ERRCLASS & ERRCLS_INT_PAR)
/* check the message buffer */
if (mBuf == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS508, ERRZERO, "Invalid message buffer");
RETVALUE(RFAILED);
}
/* check the pst structure */
if (pst == NULLP)
{
SPutMsg(mBuf);
SSLOGERROR(ERRCLS_INT_PAR, ESS509, ERRZERO, "Null pointer");
RETVALUE(RFAILED);
}
#endif
/* lock the TAPA task table */
SS_ACQUIRE_SEMA(&osCp.tTskTblSem, r);
if (r != ROK)
{
SPutMsg(mBuf);
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS510, ERRZERO,
"Could not lock TAPA task table");
#endif
RETVALUE(RFAILED);
}
#if (ERRCLASS & ERRCLS_INT_PAR)
if (pst->srcEnt >= SS_MAX_ENT || pst->srcInst >= SS_MAX_INST
|| pst->dstEnt >= SS_MAX_ENT || pst->dstInst >= SS_MAX_INST)
{
SS_RELEASE_SEMA(&osCp.tTskTblSem);
SPutMsg(mBuf);
SSLOGERROR(ERRCLS_INT_PAR, ESS511, ERRZERO,
"Invalid source/destination entity/instance");
RETVALUE(RFAILED);
}
#endif
/* get the src and destination task */
srcIdx = osCp.tTskIds[pst->srcEnt][pst->srcInst];
dstIdx = osCp.tTskIds[pst->dstEnt][pst->dstInst];
/* If the source/destination processor ID is local, the
* source/destination TAPA task must be local.
*/
if ((pst->srcProcId == osCp.procId && srcIdx == SS_TSKNC)
|| (pst->dstProcId == osCp.procId && dstIdx == SS_TSKNC))
{
SS_RELEASE_SEMA(&osCp.tTskTblSem);
SPutMsg(mBuf);
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS512, ERRZERO, "Unknown task");
printf("srcEnt=%d, srcProcId=%d, dstEnt=%d, dstProcId=%d, \n \
Event=%d, Selector=%d\n",
pst->srcEnt, pst->srcProcId, pst->dstEnt, pst->dstProcId,pst->event,
pst->selector
);
#endif
RETVALUE(RFAILED);
}
#ifdef SS_RTR_SUPPORT
/* check if we have a router task registered for this route */
if (pst->route < RTENC && osCp.rtrTskTbl[pst->route] != NULLP)
{
/* copy the Pst structure into a local duplicate */
for (i = 0; i < sizeof(Pst); i++)
{
*(((U8 *)(&nPst)) + i) = *(((U8 *) pst) + i);
}
pst = &nPst;
nPstUsed = TRUE;
/* lock the router task entry */
rte = pst->route;
r = SLock(&osCp.rtrTskLocks[rte]);
if (r != ROK)
{
SS_RELEASE_SEMA(&osCp.tTskTblSem);
SPutMsg(mBuf);
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS513, ERRZERO,
"Could not lock router task entry");
#endif
RETVALUE(RFAILED);
}
/* call the router activation function */
r = (*osCp.rtrTskTbl[rte])(pst, mBuf);
/* unlock the router task entry */
SUnlock(&osCp.rtrTskLocks[rte]);
if (r == RFAILED || r == ROKIGNORE)
{
SS_RELEASE_SEMA(&osCp.tTskTblSem);
RETVALUE((r == RFAILED) ? RFAILED : ROK);
}
}
#endif /* SS_RTR_SUPPORT */
#ifdef SS_DRVR_SUPPORT
/* Check for the destination procId. If it is non-local,
* we need to find the driver task that will handle this
* message.
*/
if (pst->dstProcId != osCp.procId)
{
/* Need to optimize this search.
*/
for (i = 0; i < SS_MAX_DRVRTSKS; i++)
{
if (osCp.drvrTskTbl[i].used
&& pst->dstProcId >= osCp.drvrTskTbl[i].low
&& pst->dstProcId <= osCp.drvrTskTbl[i].high)
{
/* Copy the Pst structure into a local duplicate if not
* already done.
*/
if (!nPstUsed)
{
for (j = 0; j < sizeof(Pst); j++)
{
*(((U8 *)(&nPst)) + j) = *(((U8 *) pst) + j);
}
pst = &nPst;
nPstUsed = TRUE;
}
/* lock the driver task entry */
r = SLock(&osCp.drvrTskTbl[i].lock);
if (r != ROK)
{
SS_RELEASE_SEMA(&osCp.tTskTblSem);
SPutMsg(mBuf);
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS514, ERRZERO,
"Could not lock driver task entry");
#endif
RETVALUE(RFAILED);
}
CMCHKPKLOG(cmPkInst, osCp.drvrTskTbl[i].channel, mBuf, ESS515, pst);
(osCp.drvrTskTbl[i].actvTsk)(pst, mBuf);
/* unlock */
SUnlock(&osCp.drvrTskTbl[i].lock);
SS_RELEASE_SEMA(&osCp.tTskTblSem);
RETVALUE(ROK);
}
}
SS_RELEASE_SEMA(&osCp.tTskTblSem);
SPutMsg(mBuf);
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS516, ERRZERO,
"Could not find a driver task to handle this proc ID");
#endif
RETVALUE(RFAILED);
}
#endif /* SS_DRVR_SUPPORT */
/* plug the Pst structure into the message information portion */
msgInfo = (SsMsgInfo *) (mBuf->b_rptr);
for (i = 0; i < (S16 )sizeof(Pst); i++)
*(((U8 *)(&msgInfo->pst)) + i) = *(((U8 *) pst) + i);
/* Write the message to the demand queue of the system
* task which is running the destination task
*/
tTsk = &osCp.tTskTbl[dstIdx];
prior = tTsk->tskPrior;
if (tTsk->sTsk == NULLP)
{
SS_RELEASE_SEMA(&osCp.tTskTblSem);
SPutMsg(mBuf);
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS517, (ErrVal) 0,
"Destination TAPA task is not attached");
#endif
RETVALUE(RFAILED);
}
r = ssDmndQPutLast(&tTsk->sTsk->dQ, mBuf,
((prior * SS_MAX_MSG_PRI) + pst->prior));
if (r != ROK)
{
SS_RELEASE_SEMA(&osCp.tTskTblSem);
SPutMsg(mBuf);
#if (ERRCLASS & ERRCLS_ADD_RES)
SSLOGERROR(ERRCLS_ADD_RES, ESS518, (ErrVal) r,
"Could not write to demand queue");
#endif
RETVALUE(RFAILED);
}
/* unlock, we're done */
SS_RELEASE_SEMA(&osCp.tTskTblSem);
/* If the implementation has anything to do... note that
* we call it unlocked at this time.
*/
ssdPstTsk(pst, mBuf, tTsk);
RETVALUE(ROK);
} /* SPstTsk */
/********************************************************************30**
End of file: ss_task.c 1.3 - 10/14/98 14:22:22
*********************************************************************31*/
/********************************************************************40**
Notes:
*********************************************************************41*/
/********************************************************************50**
*********************************************************************51*/
/********************************************************************60**
Revision history:
*********************************************************************61*/
/********************************************************************90**
ver pat init description
------------ -------- ---- ----------------------------------------------
1.1 --- kp 1. initial release
1.2 --- ag 1. Added ssdPstTsk() function in SPstTsk
--- ag 2. Fixed a bug in function SPstTsk
--- bsr 3. moved code from ssdDeregInitTskTmr to
SDeregInitTskTmr.
--- bsr 4. Added timer deregistration to SDeregTTsk
--- bsr 5. Added a check in SPstTsk to see if the
destination tapa task is attached to a
system task.
--- bsr 6. packed channel id into mBuf instead
of passing it via route field in post
strucure before calling DrvrActvTsk
--- kp 7. Fixed bug in SDeregInitTskTmr
--- kp 8. Fixed bug in SDeregTTsk
--- kp 9. Changed parameters for ssdPstTsk
--- kp 9. Cosmetic changes
1.3 --- kp 1. Added in Message Router support
*********************************************************************91*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -