⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testosmsgqflush.c

📁 ReWorks里一个有关消息队列的例子。
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -