testmq.c
来自「软件简介 1.vxworks中有关posix消息队列的一个例子 2.本软件基于c」· C语言 代码 · 共 64 行
C
64 行
/* In this example, the mqExInit() routine spawns two tasks that
* communicate using the message queue.
*/
/* testMQ.c - example using POSIX message queues */
/* includes */
#include "vxWorks.h"
#include "mqueue.h"
#include "fcntl.h"
#include "errno.h"
#include "mqEx.h"
#include "taskLib.h"
#include "stdio.h"
/* defines */
#define HI_PRIO 31
#define MSG_SIZE 16
int mqExInit (void)
{
/* create two tasks */
if (taskSpawn ("tRcvTask", 95, 0, 4000, (FUNCPTR)receiveTask, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0) == ERROR)
{
printf ("taskSpawn of tRcvTask failed\n");
return (ERROR);
}
if (taskSpawn ("tSndTask", 100, 0, 4000, (FUNCPTR)sendTask, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0) == ERROR)
{
printf ("taskSpawn of tSendTask failed\n");
return (ERROR);
}
return (OK);
}
void receiveTask (void)
{
mqd_t mqPXId; /* msg queue descriptor */
char msg[MSG_SIZE]; /* msg buffer */
int prio; /* priority of message */
/* open message queue using default attributes */
if ((mqPXId = mq_open (MQ_NAME, O_RDWR | O_CREAT, 0, NULL))
== (mqd_t) -1)
{
printf ("receiveTask: mq_open failed\n");
return;
}
/* try reading from queue */
if (mq_receive (mqPXId, msg, MSG_SIZE, &prio) == -1)
{
printf ("receiveTask: mq_receive failed\n");
return;
}
else
{
printf ("receiveTask: Msg of priority %d received:\n\t\t%s\n",
prio, msg);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?