The lstLib on VxWorks defines the structure and functions of linked list operations. Flexible use will bring great convenience to programming.
The following is an example that shows the definition of LIST and NODE structures, as well as the create, add and next methods
#include<vxworks.h>
#include<lstLib.h>
typedef struct cmdData
{
NODE node;
UINT32 cmd;
UINT32 cmdIdx;
}cmdDATA;
LIST cmdList;
cmdDATA *pCmd=NULL;
void createCmdList(void)
{
int i=0;
lstInit(&cmdList);
for(i=0;i<20;i++)
{
pCmd=(cmdDATA *)calloc(1,sizeof(cmdDATA));
pCmd->cmd=i+1;
pCmd->cmdIdx=i;
lstAdd(&cmdList,(NODE *)pCmd);
}
}
void dumpCmdList(void)
{
int count=0;
cmdDATA *pCmd=NULL;
for(pCmd=(cmdDATA *)lstFirst(&cmdList);
pCmd!=NULL;
pCmd=lstNext((NODE *)pCmd))
{
count++;
printf("cmd=0x%4x,cmdId=0x%04x\n",pCmd->cmd,pCmd->cmdIdx);
}
}
operation result