首页 > 其他分享 >队列

队列

时间:2024-07-16 15:10:07浏览次数:4  
标签:const BaseType 队列 void QueueHandle xQueue

队列创建

宏定义:configSUPPORT_STATIC_ALLOCATION

//静态创建
QueueHandle_t xQueueCreateStatic( UBaseType_t uxQueueLength, 
UBaseType_t uxItemSize,   
uint8_t *pucQueueStorageBuffer, 
StaticQueue_t *pxQueueBuffer ); 

/* The queue is to be created to hold a maximum of 10 uint64_t variables. */
#define QUEUE_LENGTH 10
#define ITEM_SIZE sizeof( uint64_t )
/* The variable used to hold the queue's data structure. */
static StaticQueue_t xStaticQueue;
/* The array to use as the queue's storage area. This must be at least
(uxQueueLength * uxItemSize) bytes. 至少队列最大长度,用于保存队列数据*/
uint8_t ucQueueStorageArea[ QUEUE_LENGTH * ITEM_SIZE ];

QueueHandle_t xQueue;
 /* Create a queue capable of containing 10 uint64_t values. */
 xQueue = xQueueCreateStatic( QUEUE_LENGTH,
 ITEM_SIZE,
 ucQueueStorageArea,
 &xStaticQueue );


//动态创建:FreeRTOS进行RAM分配队列存储空间 /* Define the data type that will be queued. */ typedef struct A_Message { char ucMessageID; char ucData[ 20 ]; } AMessage; /* Define the queue parameters. */ #define QUEUE_LENGTH 5 #define QUEUE_ITEM_SIZE sizeof( AMessage ) xQueue = xQueueCreate( QUEUE_LENGTH, QUEUE_ITEM_SIZE ); //创建队列,不需要提供队列数据存储地方
vQueueDelete( xQueue ); //队列删除

队列接收

//队列数据接收
BaseType_t xQueueReceive( QueueHandle_t xQueue, 
 void *pvBuffer, 
 TickType_t xTicksToWait );



/* Create a task, passing in the queue handle as the task parameter. */
 xTaskCreate( vAnotherTask, 
 “Task”, 
 STACK_SIZE, 
 ( void * ) xQueue, /* The queue handle is used as the task parameter. */
 TASK_PRIORITY, 
 NULL );

void vAnotherTask( void *pvParameters )
{
QueueHandle_t xQueue;
AMessage xMessage;
 
 /* The queue handle is passed into this task as the task parameter. Cast the 
 void * parameter back to a queue handle. */
 xQueue = ( QueueHandle_t ) pvParameters;
 
 for( ;; )
 {
 /* Wait for the maximum period for data to become available on the queue. 
 The period will be indefinite if INCLUDE_vTaskSuspend is set to 1 in 
 FreeRTOSConfig.h. */
 if( xQueueReceive( xQueue, &xMessage, portMAX_DELAY ) != pdPASS )
 {
 /* Nothing was received from the queue – even after blocking to wait
 for data to arrive. */
 }
 else
 {
 /* xMessage now contains the received data. */
 }
 }
}


BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, 
 void *pvBuffer, 
 BaseType_t *pxHigherPriorityTaskWoken );

/*Note
1. xQueueReceiveFromISR()调用能使任务从block状态解除
2. xQueueReceiveFromISR()只能指明是否进行一个上下文切换请求
3. 不能在任务调度之前调用,即任务调度之前就能响应的中断不能调用该函数接口
*/

//重置队列 队列中所有数据都将被丢弃
BaseType_t xQueueReset( QueueHandle_t xQueue );




 

 

队列发送:

BaseType_t xQueueSend( QueueHandle_t xQueue, 
 const void * pvItemToQueue, 
 TickType_t xTicksToWait );
BaseType_t xQueueSendToFront( QueueHandle_t xQueue, 
 const void * pvItemToQueue, 
 TickType_t xTicksToWait );
BaseType_t xQueueSendToBack( QueueHandle_t xQueue, 
 const void * pvItemToQueue, 
 TickType_t xTicksToWait );
//xQueueSend() and xQueueSendToBack() perform the same operation so are equivalent.

BaseType_t xQueueSendFromISR( QueueHandle_t xQueue, 
 const void *pvItemToQueue, 
 BaseType_t *pxHigherPriorityTaskWoken );
BaseType_t xQueueSendToBackFromISR( QueueHandle_t xQueue, 
 const void *pvItemToQueue, 
 BaseType_t *pxHigherPriorityTaskWoken );
BaseType_t xQueueSendToFrontFromISR( QueueHandle_t xQueue, 
 const void *pvItemToQueue, 
 BaseType_t *pxHigherPriorityTaskWoken );

 

 

队列查询:

//队列空查询
BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t pxQueue );

//队列full查询
BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t pxQueue );

//查询队列中有多少项
UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );

UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue );


//队列overwrite操作 主要用于队列长度为1 的队列,表示一种状态
BaseType_t xQueueOverwrite( QueueHandle_t xQueue, const void *pvItemToQueue );

BaseType_t xQueueOverwriteFromISR( QueueHandle_t xQueue, 
 const void *pvItemToQueue,
 BaseType_t *pxHigherPriorityTaskWoken );
/*pxHigherPriorityTaskWoken:如果overwrite操作导致一个block任务为unblock,且优先级比当前task高,将pxHigherPriorityTaskWoken设置为TRUE*/

//读取数据,但不将该数据从队列中移除 返回一个项目的数据
BaseType_t xQueuePeek( QueueHandle_t xQueue, 
 void *pvBuffer, TickType_t
 xTicksToWait );

BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void *pvBuffer );

 

 

队列集:

//队列集创建:
xActivatedMember = xQueueSelectFromSet( xQueueSet, pdMS_TO_TICKS( 200 ) );

//从队列集中移除某项:
if( xQueueRemoveFromSet( xQueue, xQueueSet ) != pdPASS )

//从队列集中读取数据
QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet, const TickType_t xTicksToWait );   QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet );


 

标签:const,BaseType,队列,void,QueueHandle,xQueue
From: https://www.cnblogs.com/zypprocess/p/18296656

相关文章

  • 使用RocketMQ 实现基于标签过滤的消息队列生产和消费
    在分布式系统中,消息队列(MessageQueue,MQ)是一种常见的通信方式,它能够解耦系统组件,提供异步通信,提升系统的伸缩性和可靠性。ApacheRocketMQ是一款开源的分布式消息中间件,具有高性能、低延迟、高可靠性和高可用性等特点。本文将介绍如何使用ApacheRocketMQ实现基于标签过......
  • Day10(栈与队列) | 150. 逆波兰表达式求值 239. 滑动窗口最大值 347.前 K 个高频元
    150.逆波兰表达式求值给你一个字符串数组tokens,表示一个根据逆波兰表示法表示的算术表达式。请你计算该表达式。返回一个表示表达式值的整数。注意:有效的算符为'+'、'-'、'*'和'/'。每个操作数(运算对象)都可以是一个整数或者另一个表达式。两个整数之间的除法总是......
  • 代码随想录算法训练营第六十六天 | Bellman_ford 队列优化算法(SPFA)、Bellman_ford之
    Bellman_ford队列优化算法(SPFA)题目链接:https://kamacoder.com/problempage.php?pid=1152文档讲解:https://programmercarl.com/kamacoder/0094.%E5%9F%8E%E5%B8%82%E9%97%B4%E8%B4%A7%E7%89%A9%E8%BF%90%E8%BE%93I-SPFA.html思路Bellman_ford算法每次松弛都是对所......
  • zookeeper+kafka消息队列群集部署
    目录消息队列1:什么是消息队列2:消息队列的特征3:为什么需要消息队列Kafka基础与入门1:kafka基本概念2:kafka角色术语3:kafka拓扑架构4:Topic和partition5:Producer生产机制6:Consumer消费机制zookeeper概念介绍1:zookeeper应用举例2:zookeeper的工作原理是什么?3:zookeeper......
  • 延迟队列
     绑定队列编写监听器@RabbitListener(bindings=@QueueBinding(value=@Queue(MqConstants.Queue.LEARNING_RECORD_QUEUE),exchange=@Exchange(value=MqConstants.Exchange.LEARNING_DELAY_EXCHANGE,type=ExchangeTypes.TOPIC,delayed="true&quo......
  • 【数据结构】线性结构——数组、链表、栈和队列
    目录前言一、数组(Array)1.1优点1.2缺点1.3适用场景二、链表(LinkedList)2.1优点2.2缺点2.3适用场景三、栈(Stack)3.1优点3.2缺点3.3适用场景四、队列(Queue)4.1优点4.2缺点4.3适用场景......
  • 【JavaScript脚本宇宙】解密六大Node.js消息队列库:选对工具,事半功倍
    从Bull到NSQ:探索Node.js消息队列库的全貌前言在现代软件开发中,消息队列是一种常见的通信模式,用于实现异步任务处理、解耦系统组件、以及实现可靠的事件驱动架构。Node.js作为一个流行的后端开发平台,有许多优秀的消息队列库可以供开发者选择和使用。本文将介绍六个流行的No......
  • POSIX消息队列
    一.POSIX消息队列概述什么是POSIX消息队列?POSIX消息队列是POSIX标准(PortableOperatingSystemInterface)的一部分,它提供了一种进程间通信(IPC)机制,允许不同的进程通过队列交换消息。应用场景:需要异步通信或者多个进程需要协调工作中1.1POSIX消息队列特点**独立性:**消息队......
  • 代码随想录算法训练营第10天|232. 用栈实现队列,225. 用队列实现栈,20. 有效的括号,1047.
    学习任务:Leetcode232.用栈实现队列Leetcode225.用队列实现栈Leetcode20.有效的括号Leetcode1047.删除字符串中的所有相邻重复项Leetcode232.用栈实现队列难度:简单|相关标签:栈、设计、队列题目:请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支......
  • 消息队列Kafka简单使用(可以直接上手)
    1.消息中间件简介消息中间件(MessageMiddleware)是一种在分布式系统中用于解耦不同服务或组件的软件,它通过异步消息传递的方式来实现服务之间的通信。消息中间件允许系统组件之间通过发送和接收消息进行交互,而无需知道彼此的具体实现细节,从而提高了系统的可扩展性、灵活性和......