Example #1
0
int
main(int argc, char **argv)
{
	int		i, nloop;
	mqd_t	mq1, mq2;
	char	buff[MSGSIZE];
	pid_t	childpid;
	struct mq_attr	attr;

	if (argc != 2)
		err_quit("usage: lat_pxmsg <#loops>");
	nloop = atoi(argv[1]);

	attr.mq_maxmsg = MAXMSG;
	attr.mq_msgsize = MSGSIZE;
	mq1 = Mq_open(Px_ipc_name(NAME1), O_RDWR | O_CREAT, FILE_MODE, &attr);
	mq2 = Mq_open(Px_ipc_name(NAME2), O_RDWR | O_CREAT, FILE_MODE, &attr);

	if ( (childpid = Fork()) == 0) {
		for ( ; ; ) {			/* child */
			if (Mq_receive(mq1, buff, MSGSIZE, NULL) != 1)
				err_quit("mq_receive error");
		    Mq_send(mq2, buff, 1, 0);
		}
		exit(0);
	}
		/* 4parent */
	doit(mq1, mq2);

	Start_time();
	for (i = 0; i < nloop; i++)
		doit(mq1, mq2);
	printf("latency: %.3f usec\n", Stop_time() / nloop);

	Kill(childpid, SIGTERM);
	Mq_close(mq1);
	Mq_close(mq2);
	Mq_unlink(Px_ipc_name(NAME1));
	Mq_unlink(Px_ipc_name(NAME2));
	exit(0);
}
Example #2
0
/*
 * =====================================================================
 * Function:MsgQDelete()
 * Description: delete a message queue
 * Input:   mqname -- name of new message queue, just for Linux
 *                    In Linux, the queue is identified by name.
 *          msgQId -- msgQ id
 * Output:  N/A
 * Return:  OK on success or ERROR otherwise.
 *======================================================================
 */
int MsgQDelete(const char* mqname, MSG_QUEUE_ID msgQId)
{
#ifdef LINUX_OS
    if (mqname == AII_NULL || msgQId == AII_NULL)
    {
        return (-1);
    }

    free(msgQId);
    msgQId = AII_NULL;
    return Mq_unlink(mqname);

#elif VXWORKS_OS
    if (msgQId == AII_NULL)
    {
        return (-1);
    }
    return msgQDelete(msgQId);
#endif
}