mymsgq.c

来自「vxWorks下的消息队列程序」· C语言 代码 · 共 64 行

C
64
字号
/* In this example, task t1 creates the message queue and sends a message 
 * to task t2. Task t2 receives the message from the queue and simply 
 * displays the message. 
 */
 
/* includes */ 
#include "vxWorks.h" 
#include "msgQLib.h"
 
/* defines */ 
#define MAX_MSGS (10) 
#define MAX_MSG_LEN (100)
 
MSG_Q_ID myMsgQId;

task3(void)
{
/* create message queue */
    if ((myMsgQId = msgQCreate (MAX_MSGS, MAX_MSG_LEN, MSG_Q_PRIORITY))  
        == NULL) 
        return (ERROR);
  
}
 
task2 (void) 
    { 
    char msgBuf[MAX_MSG_LEN];
 
 
    /* get message from queue; if necessary wait until msg is available */ 
    if (msgQReceive(myMsgQId, msgBuf, MAX_MSG_LEN, WAIT_FOREVER) == ERROR) 
        return (ERROR);
 
    /* display message */ 
    printf ("Message from task 1:\n%s\n", msgBuf); 
    }
 
#define MESSAGE "Greetings from Task 1" 
task1 (void) 
    { 

   if (msgQSend (myMsgQId, MESSAGE, MAX_MSG_LEN, WAIT_FOREVER, 
                  MSG_PRI_NORMAL) == ERROR) 
        return (ERROR); 

    /* send a normal priority message, blocking if queue is full
    if (msgQSend (myMsgQId, MESSAGE, sizeof (MESSAGE), WAIT_FOREVER, 
                  MSG_PRI_NORMAL) == ERROR) 
        return (ERROR); 
     */
    }
 
void mymsgQ(void)
{
taskSpawn("t3",100,0,0x20000,(FUNCPTR)task3,0,0,0,0,0,0,0,0,0,0);
taskSpawn("t2",100,0,0x20000,(FUNCPTR)task2,0,0,0,0,0,0,0,0,0,0);
taskSpawn("t1",100,0,0x20000,(FUNCPTR)task1,0,0,0,0,0,0,0,0,0,0);
}


myprint()
{
printf("Hello world\n");
}

⌨️ 快捷键说明

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