⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 taskhooklib.c

📁 VxWorks操作系统内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
STATUS taskSwapHookDetach    (    FUNCPTR     swapHook,       /* swap hook for disconection */    int         tid,            /* task to disconnect from swap hook */    BOOL        in,             /* conection for swap in */    BOOL        out             /* conection for swap out */    )    {    int ix;    taskLock ();			/* disable task switching */    /* find hook in hook table */    for (ix = 0; ix < VX_MAX_TASK_SWAP_RTNS; ++ix)	{	if (taskSwapTable [ix] == swapHook)	    {	    if (taskSwapMaskClear (tid, ix, in, out) != OK)		{		taskUnlock ();			/* re-enable task switching */		return (ERROR);			/* must of been a bum tid */		}	    else		{		taskSwapReference[ix] -= (in)  ? 1 : 0; /* deref. swap hook */		taskSwapReference[ix] -= (out) ? 1 : 0; /* deref. swap hook */		taskUnlock ();			/* re-enable task switching */		return (OK);		}	    }	}    /* hook not found in table */    taskUnlock ();		/* re-enable task switching */    errnoSet (S_taskLib_TASK_HOOK_NOT_FOUND);    return (ERROR);    }/********************************************************************************* taskSwapHookDelete - delete previously added task switch routine** This routine removes the specified routine from the list of* routines to be called by attached tasks during context switch.** RETURNS: OK, or ERROR if the routine is not in the table of task delete* routines.** SEE ALSO: taskSwapHookAdd()** NOMANUAL*/STATUS taskSwapHookDelete    (    FUNCPTR swapHook            /* routine to be deleted from list */    )    {    int ix;    taskLock ();			/* disable task switching */    /* find hook in hook table */    for (ix = 0; ix < VX_MAX_TASK_SWAP_RTNS; ++ix)	{	if (taskSwapTable [ix] == swapHook)	    {	    if (taskSwapReference [ix] != 0)	/* reference swap hook */		{		taskUnlock ();			/* re-enable task switching */		errnoSet (S_taskLib_TASK_SWAP_HOOK_REFERENCED);		return (ERROR);		}	    else		{		taskSwapTable [ix] = NULL; 	/* take out of table */		taskUnlock ();			/* re-enable task switching */		return (OK);		}	    }	}    /* hook not found in table */    taskUnlock ();		/* re-enable task switching */    errnoSet (S_taskLib_TASK_HOOK_NOT_FOUND);    return (ERROR);    }/********************************************************************************* taskDeleteHookAdd - add a routine to be called at every task delete** This routine adds a specified routine to a list of routines* that will be called whenever a task is deleted.  The routine should be* declared as follows:* .CS*     void deleteHook*         (*         WIND_TCB *pTcb	/@ pointer to deleted task's WIND_TCB @/*         )* .CE** RETURNS: OK, or ERROR if the table of task delete routines is full.** SEE ALSO: taskDeleteHookDelete()** INTERNAL:* Unlike the other "hook add" routines, this routine keeps the delete hooks in* the table in REVERSE of the order in which they are added.  Thus the most* recently added hook is the FIRST entry in the table.  This causes the delete* hooks to be run in the reverse order when a task is deleted.  This is* necessary since a task delete hook may depend on another facility that* has a delete hook, e.g., stdio uses task variables.  If we ensure that the* delete hooks are added in hierarchical order (i.e., any delete hook only* uses facilities whose delete hooks have already been added), then running* them in reverse order guarantees that facilities are not cleaned up* prematurely.*/STATUS taskDeleteHookAdd    (    FUNCPTR deleteHook  /* routine to be called when a task is deleted */    )    {    FAST int ix;    STATUS status = OK;    taskLock ();			/* disable task switching */    if (taskDeleteTable [VX_MAX_TASK_DELETE_RTNS - 1] != NULL)	{	/* no free slot found */	errnoSet (S_taskLib_TASK_HOOK_TABLE_FULL);	status = ERROR;	}    else	{	/* move all the hooks down one slot in the table */	for (ix = VX_MAX_TASK_DELETE_RTNS - 2; ix >= 0; --ix)	    taskDeleteTable [ix + 1] = taskDeleteTable [ix];	taskDeleteTable [0] = deleteHook;	}    taskUnlock ();			/* re-enable task switching */    return (status);    }/********************************************************************************* taskDeleteHookDelete - delete a previously added task delete routine** This routine removes a specified routine from the list of* routines to be called at each task delete.** RETURNS: OK, or ERROR if the routine is not in the table of task delete* routines.** SEE ALSO: taskDeleteHookAdd()*/STATUS taskDeleteHookDelete    (    FUNCPTR deleteHook          /* routine to be deleted from list */    )    {    return (taskHookDelete (deleteHook, taskDeleteTable,			    VX_MAX_TASK_DELETE_RTNS));    }/********************************************************************************* taskHookAdd - add a hook routine to a hook table** This routine does not guard against duplicate entries.** RETURNS: OK, or ERROR if task hook table is full.*/LOCAL STATUS taskHookAdd    (    FUNCPTR hook,       /* routine to be added to table */    FUNCPTR table[],    /* table to which to add */    int maxEntries      /* max entries in table */    )    {    FAST int ix;    taskLock ();			/* disable task switching */    /* find slot after last hook in table */    for (ix = 0; ix < maxEntries; ++ix)	{	if (table[ix] == NULL)	    {	    table[ix] = hook;	    taskUnlock ();	/* re-enable task switching */	    return (OK);	    }	}    /* no free slot found */    taskUnlock ();		/* re-enable task switching */    errnoSet (S_taskLib_TASK_HOOK_TABLE_FULL);    return (ERROR);    }/********************************************************************************* taskHookDelete - delete a hook from a hook table** RETURNS: OK, or ERROR if task hook could not be found.*/LOCAL STATUS taskHookDelete    (    FUNCPTR hook,       /* routine to be deleted from table */    FUNCPTR table[],    /* table from which to delete */    int maxEntries      /* max entries in table */    )    {    FAST int ix;    taskLock ();			/* disable task switching */    /* find hook in hook table */    for (ix = 0; ix < maxEntries; ++ix)	{	if (table [ix] == hook)	    {	    /* move all the remaining hooks up one slot in the table */	    do		table [ix] = table [ix + 1];	    while (table [++ix] != NULL);	    taskUnlock ();	/* re-enable task switching */	    return (OK);	    }	}    /* hook not found in table */    taskUnlock ();		/* re-enable task switching */    errnoSet (S_taskLib_TASK_HOOK_NOT_FOUND);    return (ERROR);    }/********************************************************************************* taskSwapMaskSet - set a task's swap-in/swap-out mask** This routine sets the bit for the specified index in the specified task's* swap-in/swap-out mask.  The parameter index is the index into the* taskSwapTable for the swap hook of interest.** INTERNAL* The most significant bit corresponds to the first element of the* swap table.  This was done because optimized versions of the kernel* utilize the fact that the most significant bit sets the carry flag on a* shift left operation.** RETURNS: OK, or ERROR if the swap mask could not be set.** NOMANUAL*/LOCAL STATUS taskSwapMaskSet    (    int  tid,   /* task to change swap-in mask */    int  index, /* index of task swap routine in taskSwapTable */    BOOL in,    /* call swap routine when task is switched in */    BOOL out    /* call swap routine when task is switched out */    )    {    WIND_TCB *pTcb = taskTcb (tid);    USHORT    ixBit = (1 << (15 - index));    if (pTcb == NULL)				/* invalid task ID */	return (ERROR);    if (((in) && (pTcb->swapInMask & ixBit)) ||        ((out) && (pTcb->swapOutMask & ixBit)))	{	errno = S_taskLib_TASK_SWAP_HOOK_SET;	return (ERROR);	}    if (in)	pTcb->swapInMask |= ixBit;		/* turn on swapInMask bit */    if (out)	pTcb->swapOutMask |= ixBit;		/* turn on swapOutMask bit */    return (OK);    }/********************************************************************************* taskSwapMaskClear - clear a task's swap-in/swap-out mask** This routine clears the bit for the specified index in the specified task's* swap-in/swap-out mask.  The parameter index is the index into the* taskSwapTable for the swap hook of interest.** INTERNAL* The most significant bit corresponds to the first element of the* swap table.  This was done for kernel efficiency.** RETURNS: OK, or ERROR if the swap mask could not be cleared.** NOMANUAL*/LOCAL STATUS taskSwapMaskClear    (    int  tid,   /* task to change swap-in mask */    int  index, /* index of task swap routine in taskSwapTable */    BOOL in,    /* swap routine called when task is switched in */    BOOL out    /* swap routine called when task is switched out */    )    {    WIND_TCB *pTcb  = taskTcb (tid);    USHORT    ixBit = (1 << (15 - index));    if (pTcb == NULL)				/* invalid task ID */	return (ERROR);    if (((in) && !(pTcb->swapInMask & ixBit)) ||        ((out) && !(pTcb->swapOutMask & ixBit)))	{	errno = S_taskLib_TASK_SWAP_HOOK_CLEAR;	return (ERROR);	}    if (in)	pTcb->swapInMask &= ~ixBit;		/* turn off swapInMask bit */    if (out)	pTcb->swapOutMask &= ~ixBit;		/* turn off swapOutMask bit */    return (OK);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -