testosmsgqflush.c

来自「ReWorks里一个有关消息队列的例子。」· C语言 代码 · 共 81 行

C
81
字号
#include "msgqTest.h"

#define MESSAGE_SIZE (sizeof(long) * 4)  
static long    buffer[ MESSAGE_SIZE / sizeof(long) ];
static long    recBuf[ MESSAGE_SIZE / sizeof(long) ];
static unsigned32 MsgQ_id;
static unsigned32 msg_count,flush_count;

int testOSMsgQFlush()
{
    OS_STATUS status;
    
    
    printf("*** test of OSMsgQFlush ***\n");
    printf("create a MsgQ.\n");
    status = OSMsgQCreate("msg",10,20,OS_DEFAULT,&MsgQ_id); 
    if(status != OS_OK)
    {
 		printf("OSMsgQCreate error:[%s]\n",serrno(errno));
		return (-1);
 	}
 	
 	printf("send two msgs to the MsgQ.\n");
	strcpy( buffer, "hello" );
	status = OSMsgQSend( MsgQ_id, buffer, MESSAGE_SIZE ); 
    if(status != OS_OK)
    {
 		printf("OSMsgQSend error:[%s]\n",serrno(errno));
		return (-1);
 	}	
 	
 	strcpy( buffer, "world" );
	status = OSMsgQSend( MsgQ_id, buffer, MESSAGE_SIZE ); 
    if(status != OS_OK)
    {
 		printf("OSMsgQSend error:[%s]\n",serrno(errno));
		return (-1);
 	}
  	
  	status = OSMsgQPendingNumGet(MsgQ_id,&msg_count);
    if(status != OS_OK)
    {
 		printf("OSMsgQPendingNumGet error:[%s]\n",serrno(errno));
		return (-1);
 	}
 	else
 	{
    	printf("OSMsgQPendingNumGet:there are %d msgs in the MsgQ\n",msg_count);  
  	}
  	
  	printf("OSMsgQFlush flush the MsgQ.\n",flush_count);
  	status = OSMsgQFlush(MsgQ_id,&flush_count);
    if(status != OS_OK)
    {
 		printf("OSMsgQFlush error:[%s]\n",serrno(errno));
		return (-1);
 	}
 	else
 	{
    	printf("OSMsgQFlush:flush %d msgs in the MsgQ\n",flush_count);  
  	}
  	
  	status = OSMsgQPendingNumGet(MsgQ_id,&msg_count);
    if(status != OS_OK)
    {
 		printf("OSMsgQPendingNumGet error:[%s]\n",serrno(errno));
		return (-1);
 	}
 	else
 	{
    	printf("OSMsgQPendingNumGet:now there are %d msgs in the MsgQ\n",msg_count);  
  	}
  	
   	OSMsgQDelete(MsgQ_id); 
   	printf("*** OSMsgQFlush test OK! ***\n\n");
	return 1;
}   
 


⌨️ 快捷键说明

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