?? ss_timer.c
字號:
/********************************************************************20**
Name: System Services -- Timing
Type: C source file
Desc: Source code for System Services related to timing.
File: ss_timer.c
Sid: ss_timer.c 1.3 - 10/14/98 14:22:57
Prg: kp
*********************************************************************21*/
/* header include files (.h) */
#include "envopt.h" /* environment options */
#include "envdep.h" /* environment dependent */
#include "envind.h" /* environment independent */
#include "gen.h" /* general layer */
#include "ssi.h" /* system services */
#include "ss_err.h" /* errors */
#include "ss_dep.h" /* implementation-specific */
#include "ss_queue.h" /* queues */
#include "ss_msg.h" /* messaging */
#include "ss_mem.h" /* memory management interface */
#include "ss_gen.h" /* general */
/* header/extern include files (.x) */
#include "gen.x" /* general layer */
#include "ssi.x" /* system services */
#include "ss_dep.x" /* implementation-specific */
#include "ss_queue.x" /* queues */
#include "ss_task.x" /* tasking */
#include "ss_timer.x" /* timers */
#include "ss_strm.x" /* STREAMS */
#include "ss_msg.x" /* messaging */
#include "ss_mem.x" /* memory management interface */
#include "ss_drvr.x" /* driver tasks */
#include "ss_gen.x" /* general */
/*
*
* Fun: Register Timer Task - timer
*
* Desc: This function is used to register a timer function for the
* layer. The system services will periodically invoke the
* function passed to it. The timer function will be used by the
* layer to manage the layers internal protocol timers.
*
* Ret: ROK - ok
* RFAILED - failed, general (optional)
* ROUTRES - failed, out of resources (optional)
*
* Notes:
*
* File: ss_timer.c
*
*/
#ifdef ANSI
PUBLIC S16 SRegTmr
(
Ent ent, /* entity */
Inst inst, /* instance */
S16 period, /* period */
PFS16 tmrFnct /* timer function, typically SActvTmr */
)
#else
PUBLIC S16 SRegTmr(ent, inst, period, tmrFnct)
Ent ent; /* entity */
Inst inst; /* instance */
S16 period; /* period */
PFS16 tmrFnct; /* timer function, typically SActvTmr */
#endif
{
S16 ret;
SsTmrEntry *tmr;
TRC1(SRegTmr);
#if (ERRCLASS & ERRCLS_INT_PAR)
if (ent >= SS_MAX_ENT || inst >= SS_MAX_INST)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS519, ERRZERO, "Invalid entity/instance");
RETVALUE(RFAILED);
}
/* check period */
if (period <= 0)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS520, ERRZERO, "Invalid period");
RETVALUE(RFAILED);
}
/* check timer function */
if (tmrFnct == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS521, ERRZERO, "Null pointer");
RETVALUE(RFAILED);
}
/* check task ID */
/* lock TAPA task table */
SS_ACQUIRE_SEMA(&osCp.tTskTblSem, ret);
if (ret != ROK)
{
SSLOGERROR(ERRCLS_DEBUG, ESS522, ERRZERO,
"Could not lock TAPA task table");
RETVALUE(RFAILED);
}
if (osCp.tTskIds[ent][inst] == SS_TSKNC)
{
SS_RELEASE_SEMA(&osCp.tTskTblSem);
SSLOGERROR(ERRCLS_INT_PAR, ESS523, ERRZERO, "Unknown task");
RETVALUE(RFAILED);
}
SS_RELEASE_SEMA(&osCp.tTskTblSem);
#endif
/* lock the timer table */
ret = SLock(&osCp.tmrTblLock);
if (ret != ROK)
{
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS524, (ErrVal) ret,
"Could not lock timer table");
#endif
RETVALUE(ret);
}
/* check if we've got room for another timer */
if (osCp.numTmrs == SS_MAX_TMRS)
{
SUnlock(&osCp.tmrTblLock);
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS525, ERRZERO, "Too many timers");
#endif
RETVALUE(ROUTRES);
}
/* fill in the information we have into the timer entry */
tmr = &osCp.tmrTbl[osCp.nxtTmrEntry];
tmr->tmrId = osCp.nxtTmrEntry;
tmr->ownerEnt = ent;
tmr->ownerInst = inst;
tmr->interval = (U16) period;
tmr->tmrActvFn = tmrFnct;
/* ask the implementation to start the timer */
ret = ssdRegTmr(tmr);
if (ret != ROK)
{
tmr->tmrId = 0;
tmr->ownerEnt = ENTNC;
tmr->ownerInst = INSTNC;
tmr->interval = 0;
tmr->tmrActvFn = NULLP;
} else
{
tmr->used = TRUE;
osCp.nxtTmrEntry = tmr->nxt;
osCp.numTmrs++;
}
/* unlock the timer table */
SUnlock(&osCp.tmrTblLock);
RETVALUE(ret);
}
/*
*
* Fun: SDeregTmr
*
* Desc: This function is used to deregister a timer function.
*
* Ret: ROK - ok
* RFAILED - failed, general (optional)
*
* Notes:
*
* File: ss_timer.c
*
*/
#ifdef ANSI
PUBLIC S16 SDeregTmr
(
Ent ent, /* entity */
Inst inst, /* instance */
S16 period, /* period */
PFS16 tmrFnct /* timer function */
)
#else
PUBLIC S16 SDeregTmr(ent, inst, period, tmrFnct)
Ent ent; /* entity */
Inst inst; /* instance */
S16 period; /* period */
PFS16 tmrFnct; /* timer function */
#endif
{
S16 ret;
S16 idx;
SsTmrEntry *tmr;
TRC1(SDeregTmr);
#if (ERRCLASS & ERRCLS_INT_PAR)
if (ent >= SS_MAX_ENT || inst >= SS_MAX_INST)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS526, ERRZERO, "Invalid entity/instance");
RETVALUE(RFAILED);
}
/* check period */
if (period <= 0)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS527, ERRZERO, "Invalid period");
RETVALUE(RFAILED);
}
/* check timer function */
if (tmrFnct == NULLP)
{
SSLOGERROR(ERRCLS_INT_PAR, ESS528, ERRZERO, "Null pointer");
RETVALUE(RFAILED);
}
/* check task ID */
/* lock TAPA task table */
SS_ACQUIRE_SEMA(&osCp.tTskTblSem, ret);
if (ret != ROK)
{
SSLOGERROR(ERRCLS_DEBUG, ESS529, ERRZERO,
"Could not lock TAPA task table");
RETVALUE(RFAILED);
}
if (osCp.tTskIds[ent][inst] == SS_TSKNC)
{
SS_RELEASE_SEMA(&osCp.tTskTblSem);
SSLOGERROR(ERRCLS_INT_PAR, ESS530, ERRZERO, "Unknown task");
RETVALUE(RFAILED);
}
SS_RELEASE_SEMA(&osCp.tTskTblSem);
#endif
/* lock the timer table */
ret = SLock(&osCp.tmrTblLock);
if (ret != ROK)
{
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS531, (ErrVal) ret,
"Could not lock timer table");
#endif
RETVALUE(ret);
}
/* Note: Right now, we're using ent, inst and tmrActvFn to locate
* the timer,, this will change to using tmrId, some day.
*/
/* locate the timer to delete in the timer table */
for (idx = 0; idx < SS_MAX_TMRS; idx++)
{
if (osCp.tmrTbl[idx].ownerEnt == ent
&& osCp.tmrTbl[idx].ownerInst == inst
&& osCp.tmrTbl[idx].tmrActvFn == tmrFnct)
{
break;
}
}
if (idx == SS_MAX_TMRS)
{
SUnlock(&osCp.tmrTblLock);
#if (ERRCLASS & ERRCLS_DEBUG)
SSLOGERROR(ERRCLS_DEBUG, ESS532, ERRZERO, "Could not locate timer");
#endif
RETVALUE(RFAILED);
}
/* ask the implementation to shut down this timer */
tmr = &osCp.tmrTbl[idx];
ret = ssdDeregTmr(tmr);
if (ret == ROK)
{
tmr->used = FALSE;
tmr->tmrId = 0;
tmr->ownerEnt = ENTNC;
tmr->ownerInst = INSTNC;
tmr->interval = 0;
tmr->tmrActvFn = NULLP;
tmr->nxt = osCp.nxtTmrEntry;
osCp.nxtTmrEntry = (SsIdx)idx;
osCp.numTmrs--;
}
/* unlock the timer table */
SUnlock(&osCp.tmrTblLock);
RETVALUE(ret);
}
/********************************************************************30**
End of file: ss_timer.c 1.3 - 10/14/98 14:22:57
*********************************************************************31*/
/********************************************************************40**
Notes:
*********************************************************************41*/
/********************************************************************50**
*********************************************************************51*/
/********************************************************************60**
Revision history:
*********************************************************************61*/
/********************************************************************90**
ver pat init description
------------ -------- ---- ----------------------------------------------
1.1 --- kp 1. initial release
1.2 --- bsr 1. Regenerated the error codes
1.3 --- kp 1. Regenerated error codes
*********************************************************************91*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -