006-FreeRTOS202212-将节点按照升序排列插入到链表



/*-----------------------------------------------------------*/

void vListInsert( List_t * const pxList,
                  ListItem_t * const pxNewListItem )
{
	ListItem_t * pxIterator;
    	const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;

    	/* Only effective when configASSERT() is also defined, these tests may catch the list data structures being overwritten in memory.  
		They will not catch data errors caused by incorrect configuration or use of FreeRTOS. */
	/*只有在定义了configASSERT()时才有效,这些测试可能会捕获内存中被覆盖的链表数据结构。
		他们不会捕捉到由于不正确的配置或使用FreeRTOS而导致的数据错误*/
    	listTEST_LIST_INTEGRITY( pxList );
    	listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );

    	/* Insert the new list item into the list, sorted in xItemValue order. */
	/*将新链表项插入链表中,按xItemValue顺序排序*/

    	/* If the list already contains a list item with the same item value then the new list item should be placed after it.  
		This ensures that TCBs which are stored in ready lists (all of which have the same xItemValue value) get a share of the CPU.  
		However, if the xItemValue is the same as the back marker the iteration loop below will not end.  
		Therefore the value is checked first, and the algorithm slightly modified if necessary. */
	/*如果链表中已包含具有相同排序值的链表项,则应将新的链表项放在该链表项之后。
		这确保了存储在就绪链表中的TCB(任务控制块)(所有这些链表都具有相同的xItemValue值)获得CPU的份额。
		但是,如果xItemValue与后标记相同,则下面的迭代循环将不会结束。
		因此,首先检查该值,必要时对算法进行轻微修改*/
    	if( xValueOfInsertion == portMAX_DELAY )
    	{
        	pxIterator = pxList->xListEnd.pxPrevious;
    	}
    	else
    	{
        	/* *** NOTE ********************************************************** */
		/* If you find your application is crashing here then likely causes are listed below.  
			In addition see https://www.FreeRTOS.org/FAQHelp.html for more tips, and ensure configASSERT() is defined!
      			https://www.FreeRTOS.org/a00110.html#configASSERT
		/*如果你发现你的应用程序在这里崩溃,那么下面列出了可能的原因。
			此外,请参阅https://www.FreeRTOS.org/FAQHelp.html有关更多提示,请确保已定义configASSERT()!
			https://www.FreeRTOS.org/a00110.html#configASSERT
      
        	1) Stack overflow - see https://www.FreeRTOS.org/Stacks-and-stack-overflow-checking.html
		1) 堆栈溢出-请参阅https://www.FreeRTOS.org/Stacks-and-stack-overflow-checking.html
     		2) Incorrect interrupt priority assignment, especially on Cortex-M parts where numerically high priority values denote low actual interrupt priorities, which can seem counter intuitive.  
			See https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html and the definition of configMAX_SYSCALL_INTERRUPT_PRIORITY on https://www.FreeRTOS.org/a00110.html
		2) 不正确的中断优先级分配,尤其是在Cortex-M部件上,数字上的高优先级值表示实际中断优先级低,这可能会违反直觉。
			参考https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html以及上的configMAX_SYSCALL_INTERRUPT_PRIORITY的定义https://www.FreeRTOS.org/a00110.html
		3) Calling an API function from within a critical section or when the scheduler is suspended, or calling an API function that does not end in "FromISR" from an interrupt.
		3) 从临界段或调度程序暂停时调用API函数,或从中断调用不以“FromISR”结尾的API函数。
   		4) Using a queue or semaphore before it has been initialised or before the scheduler has been started (are interrupts firing before vTaskStartScheduler() has been called?).
		4) 在初始化队列或信号量之前或在启动调度程序之前使用它(是否在调用vTaskStartScheduler()之前触发中断?)。
		5) If the FreeRTOS port supports interrupt nesting then ensure that the priority of the tick interrupt is at or below configMAX_SYSCALL_INTERRUPT_PRIORITY.
		5) 如果FreeRTOS端口支持中断嵌套,则确保tick中断的优先级等于或低于configMAX_SYSCALL_interrupt_priority。
         	/* **********************************************************************/
		for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM.  This is checked and valid. */
																							/*lint !e440 The iterator moves to a different value, not xValueOfInsertion. */
		{
  			/* There is nothing to do here, just iterating to the wanted insertion position. */
			/*这里没有什么可做的,只是迭代到所需的插入位置*/
		}
	}

    	pxNewListItem->pxNext = pxIterator->pxNext;
    	pxNewListItem->pxNext->pxPrevious = pxNewListItem;
    	pxNewListItem->pxPrevious = pxIterator;
    	pxIterator->pxNext = pxNewListItem;

    	/* Remember which list the item is in.  This allows fast removal of the item later. */
	/*记住该链表项在哪个链表中。这样以后可以快速删除该项目*/
    	pxNewListItem->pxContainer = pxList;

    	( pxList->uxNumberOfItems )++;
}


/*-----------------------------------------------------------*/

将节点按照升序排列插入到链表 详细过程如下图 ,参考<[野火®]《FreeRTOS 内核实现与应用开发实战—基于STM32》>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值