BLOG記事用論壇

 找回密碼
 註冊
搜索
熱搜:
查看: 991|回復: 0

Ready List

[複製鏈接]
發表於 2023-6-6 12:39:03 | 顯示全部樓層 |閱讀模式


  1.         y             = OSUnMapTbl[OSRdyGrp];        /* Find highest priority's task priority number   */
  2.         x             = OSUnMapTbl[OSRdyTbl[y]];
  3.         OSPrioHighRdy = (INT8U)((y << 3) + x);
複製代碼


The operation y << 3 is a bit shift operation in programming. Specifically, it is a left-shift operation that shifts the bits of the number y three places to the left.

In binary representation, shifting a number by one place to the left is equivalent to multiplying it by 2. Therefore, shifting a number y three places to the left is equivalent to multiplying y by 2^3, or 8.

In the context of this code snippet, y << 3 is used to calculate the priority of the highest priority task that is ready to run (OSPrioHighRdy). The formula (y << 3) + x is used to calculate this priority based on the ready group (OSRdyGrp) and the ready table (OSRdyTbl[y]). The left-shift operation is used here to quickly multiply y by 8, which is part of the calculation for the priority.


What does this code do?
  1. if ((OSRdyTbl[prio >> 3] &= ~OSMapTbl[prio & 0x07]) == 0)
  2. OSRdyGrp &= ~OSMapTbl[prio >> 3];
複製代碼

This code is a part of a real-time operating system, specifically the MicroC/OS-II (or uC/OS-II), and it's used for task scheduling.

The operating system maintains a list of tasks that are ready to run. This list is often implemented as a bit map for efficiency. In uC/OS-II, the ready list is divided into two parts: OSRdyGrp (Ready Group) and OSRdyTbl (Ready Table). Each bit in the Ready Group corresponds to a byte in the Ready Table. If a bit in the Ready Group is set, it means that there's at least one task of the corresponding priority ready to run.

Here's the breakdown of what the code does:

OSRdyTbl[prio >> 3] &= ~OSMapTbl[prio & 0x07]: This line of code removes the task from the Ready Table. The task's priority is used to identify which bit in the Ready Table to clear. The priority is divided by 8 (prio >> 3) to find the byte in the Ready Table, and the remainder of the division (prio & 0x07) is used to find the bit within that byte.

if ((OSRdyTbl[prio >> 3] &= ~OSMapTbl[prio & 0x07]) == 0): This conditional checks if all the tasks of the corresponding priority group are blocked or not ready. If the byte in the Ready Table is zero after clearing the bit, it means that there are no more tasks of that priority group that are ready to run.

OSRdyGrp &= ~OSMapTbl[prio >> 3]: If there are no more tasks of that priority group ready to run, this line of code clears the corresponding bit in the Ready Group.

So overall, this code is used when a task is blocked or not ready to run. It removes the task from the Ready List and updates the Ready Group if necessary.

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|綜合討論區

GMT+8, 2026-6-24 18:45 , Processed in 0.097028 second(s), 9 queries , File On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回復 返回頂部 返回列表