s4_msgq.c

来自「tornado2.2开发」· C语言 代码 · 共 82 行

C
82
字号
#include "vxWorks.h"
#include "msgQLib.h"
#include "stdio.h"

#define MAX_MESSAGES 100
#define MAX_MESSAGE_LENGTHS 50
MSG_Q_ID msgQueueId;
MSG_Q_ID msgQueueIdadd;

static void taskOne(void)
{
    char msgBuf[MAX_MESSAGE_LENGTHS];
    char message[] = "Received Message from taskOne.";
    if (msgQSend(msgQueueId,message,MAX_MESSAGE_LENGTHS,
        WAIT_FOREVER,MSG_PRI_NORMAL)==ERROR)
    { 
        printf("msgQSend in taskOne failed.\n");
    }

    if (msgQReceive(msgQueueIdadd,msgBuf,MAX_MESSAGE_LENGTHS,
        WAIT_FOREVER)==ERROR)
    { 
        printf("msgQReceive in taskOne failed.\n");
    }
    else
    { 
        printf("taskOne %s\n",msgBuf);
    }
    msgQDelete(msgQueueIdadd);

}

static void taskTwo(void)
{
    char msgBuf[MAX_MESSAGE_LENGTHS];
    char message[] = "Received Message from taskTwo.";

    if (msgQReceive(msgQueueId,msgBuf,MAX_MESSAGE_LENGTHS,
        WAIT_FOREVER)==ERROR)
    { 
        printf("msgQReceive in taskTwo failed.\n");
    }
    else
    { 
        printf("taskTwo %s\n",msgBuf);
    }
    msgQDelete(msgQueueId);
    if (msgQSend(msgQueueIdadd,message,MAX_MESSAGE_LENGTHS,
        WAIT_FOREVER,MSG_PRI_NORMAL)==ERROR)
    { 
        printf("msgQSend in taskTwo failed.\n");
    }


}

void s4_msgq(void)
{
    int taskIdOne,taskIdTwo;
    if ((msgQueueId=msgQCreate(MAX_MESSAGES,MAX_MESSAGE_LENGTHS,
        MSG_Q_FIFO))==NULL)
    { 
        logMsg("msgQCreate failed.\n",0,0,0,0,0,0);
    }
    if ((msgQueueIdadd=msgQCreate(MAX_MESSAGES,MAX_MESSAGE_LENGTHS,
        MSG_Q_FIFO))==NULL)
    { 
        logMsg("msgQCreate failed.\n",0,0,0,0,0,0);
    }

    if ((taskIdOne = taskSpawn("t1",90,0x100,2000,
          (FUNCPTR)taskOne,0,0,0,0,0,0,0,0,0,0))==ERROR)
    { 
        logMsg("taskSpawn taskOne failed.\n",0,0,0,0,0,0);
    }
    if ((taskIdTwo = taskSpawn("t2",90,0x100,2000,
          (FUNCPTR)taskTwo,0,0,0,0,0,0,0,0,0,0))==ERROR)
    { 
        logMsg("taskSpawn taskTwo failed.\n",0,0,0,0,0,0);
    }
}

⌨️ 快捷键说明

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