VxWorks下的taskLock/taskUnlock在Linux下的实现

sinat_30424685 2015-08-17 04:32:07
各位好:

VxWorks下的taskLock/taskUnlock在Linux下,是否有类似的系统函数调用,
如果没有的话,要Linux下要如何实现其功能?

下面是VxWorks的kernel source
-------------------------------------------------------------------------------------------------------
/* taskLib.c - task management library */

/*#include "vxWorks.h"
#include "errno.h"
#include "semLib.h"
#include "string.h"
#include "regs.h"
#include "intLib.h"
#include "taskArchLib.h"
#include "stdio.h"
#include "memLib.h"
#include "qFifoGLib.h"
#include "sysLib.h" /* CPU==SIM* */
#include "private/eventLibP.h"
#include "private/sigLibP.h"
#include "private/classLibP.h"
#include "private/objLibP.h"
#include "private/smObjLibP.h"
#include "private/smFixBlkLibP.h"
#include "private/taskLibP.h"
#include "private/kernelLibP.h"
#include "private/workQLibP.h"
#include "private/windLibP.h"
#include "private/eventP.h"


/* locals */

LOCAL OBJ_CLASS taskClass; /* task object class */
LOCAL int nameForNameless; /* name for nameless tasks */
LOCAL BOOL taskLibInstalled; /* protect from double inits */

/*******************************************************************************
*
* taskLock - disable task rescheduling
*
ecute.
*
* The taskUnlock() routine is not callable from interrupt service routines.
*
* RETURNS: OK or ERROR.
*
* ERRNO: S_intLib_NOT_ISR_CALLABLE
*
* SEE ALSO: taskLock()
*/

STATUS taskLock (void)
{
TASK_LOCK(); /* increment lock cnt */

return (OK);
}

STATUS taskLock (void)
{
TASK_LOCK(); /* increment lock cnt */

return (OK);
}


STATUS taskUnlock (void)
{
FAST WIND_TCB *pTcb = taskIdCurrent;

#ifdef WV_INSTRUMENTATION
/* windview - level 3 event logging */
EVT_CTX_0 (EVENT_TASKUNLOCK);
#endif

if ((pTcb->lockCnt > 0) && ((-- pTcb->lockCnt) == 0)) /* unlocked? */
{
kernelState = TRUE; /* KERNEL ENTER */

if ((Q_FIRST (&pTcb->safetyQHead) != NULL) && (pTcb->safeCnt == 0))
{

#ifdef WV_INSTRUMENTATION
/* windview - level 2 event logging */
EVT_TASK_1 (EVENT_OBJ_TASK, pTcb); /* log event */
#endif

windPendQFlush (&pTcb->safetyQHead); /* flush safe queue */
}

windExit (); /* KERNEL EXIT */
}

return (OK);
}
...全文
542 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sean-zhao 2015-08-28
  • 打赏
  • 举报
回复
引用 2 楼 sinat_30424685 的回复:
[quote=引用 1 楼 linglongqiongge 的回复:] 原子量操作的变量计数器 linux里也有
不好意思,具体是哪个变量呢? 能否实现taskLock/taskUnlock的功能? [/quote] 我觉得你说的这个和Linux的atomic_t挺像的,具体可以到spinlock.h看看 /* * include/linux/spinlock.h - generic spinlock/rwlock declarations * * here's the role of the various spinlock/rwlock related include files: * * on SMP builds: * * asm/spinlock_types.h: contains the raw_spinlock_t/raw_rwlock_t and the * initializers * * linux/spinlock_types.h: * defines the generic type and initializers * * asm/spinlock.h: contains the __raw_spin_*()/etc. lowlevel * implementations, mostly inline assembly code * * (also included on UP-debug builds:) * * linux/spinlock_api_smp.h: * contains the prototypes for the _spin_*() APIs. * * linux/spinlock.h: builds the final spin_*() APIs. * * on UP builds: * * linux/spinlock_type_up.h: * contains the generic, simplified UP spinlock type. * (which is an empty structure on non-debug builds) * * linux/spinlock_types.h: * defines the generic type and initializers * * linux/spinlock_up.h: * contains the __raw_spin_*()/etc. version of UP * builds. (which are NOPs on non-debug, non-preempt * builds) * * (included on UP-non-debug builds:) * * linux/spinlock_api_up.h: * builds the _spin_*() APIs. * * linux/spinlock.h: builds the final spin_*() APIs. */
sinat_30424685 2015-08-27
  • 打赏
  • 举报
回复
引用 1 楼 linglongqiongge 的回复:
原子量操作的变量计数器 linux里也有
不好意思,具体是哪个变量呢? 能否实现taskLock/taskUnlock的功能?
sinat_30424685 2015-08-27
  • 打赏
  • 举报
回复
貌似Linux下POSIX函数:pthread_spin_lock/pthread_spin_unlock功能比较类似。
sean-zhao 2015-08-18
  • 打赏
  • 举报
回复
原子量操作的变量计数器 linux里也有

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧