Queue communication method, terminal, and storage medium
By performing priority decay and sorting based on the initial priority and dwell time of messages in the embedded operating system, the problem of high-priority messages being blocked is solved, improving the real-time performance and efficiency of message transmission.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGZHOU JINQILI INFORMATION TECH CO LTD
- Filing Date
- 2025-09-30
- Publication Date
- 2026-05-05
AI Technical Summary
In existing embedded real-time operating systems, high-priority messages are easily blocked by low-priority messages or messages that have been in the queue for a long time, which affects the real-time performance of message transmission and makes it difficult to take advantage of the fast communication of queues.
By determining the initial priority of messages added to the queue, and performing priority decay based on message dwell time and current priority, and sorting and transmitting messages in combination with their current priority, the priority of the target receiving object is increased to ensure the rapid processing of high-priority messages.
This effectively prevents high-priority messages from being blocked by low-priority or messages that have been waiting in the queue for a long time, improves the real-time performance of multi-task communication, and leverages the advantages of fast communication through queues.
Smart Images

Figure CN120950277B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of embedded operating systems, and more particularly to a queue communication method, a terminal, and a storage medium. Background Technology
[0002] Current embedded real-time operating systems primarily implement queue communication through the following steps: users create and design their own queues. However, in scenarios where multiple messages share a single queue for sending and receiving, the queue's first-in, first-out (FIFO) message transmission means that high-priority messages must wait for the messages preceding them in the queue to finish transmitting before they can be transmitted. This message transmission method easily leads to high-priority messages being blocked by lower-priority or long-standing messages in the queue, affecting real-time message transmission and hindering the realization of the queue's advantages for fast communication. Summary of the Invention
[0003] To overcome the shortcomings of the prior art, this application proposes a queue communication method, terminal and storage medium, which can solve the problem that in the prior art, high-priority messages are easily blocked by low-priority messages or messages that have been in the queue for a long time in the queue communication between multiple messages, which affects the real-time performance of message transmission and makes it difficult to give full play to the advantages of fast queue communication between multiple messages.
[0004] To address the aforementioned problems, this application adopts the following technical solution: a queue communication method, the method comprising:
[0005] S101: Determine the initial priority of the message to be added to the queue, and perform priority decay based on the message's dwell time and current priority;
[0006] S102: Sort the messages according to their current priority, and transmit the messages based on the sorting results.
[0007] Furthermore, determining the initial priority of messages added to the queue includes:
[0008] It is confirmed that a new message has been detected and added to the queue;
[0009] Obtain the priority of the message delivery object corresponding to the new message, and determine the initial priority of the new message based on the priority.
[0010] Furthermore, the priority decay based on the message's dwell time and current priority includes:
[0011] If it is determined that the current priority of the message is not the lowest priority, then the priority of the message is gradually reduced based on the current priority and the dwell time.
[0012] Furthermore, the step of gradually reducing the priority of the message based on the current priority and the dwell time includes:
[0013] If it is determined that the dwell time reaches an integer multiple of the preset dwell time, the priority is reduced by one step until the message priority is reduced to the lowest priority.
[0014] or
[0015] If it is determined that the message has not been sent, the priority of the message is reduced once every preset dwell time until the priority of the message is reduced to the lowest priority.
[0016] Further, the method includes:
[0017] Get the number of messages in the queue;
[0018] If it is determined that the message data has reached the maximum number of messages, then the addition of new messages is rejected.
[0019] Furthermore, the message transmission based on the message sorting result includes:
[0020] Retrieve the highest priority message from the queue and increase the priority of the target receiving object corresponding to the message.
[0021] If it is determined that the target receiving object has received the message, then the priority of the target receiving object is reduced.
[0022] Furthermore, the step of increasing the priority of the target receiving object corresponding to the message includes:
[0023] Detect the state of the target receiving object;
[0024] If it is determined that the target receiving object is in a blocked state, then the target receiving object is woken up and its priority is raised to the same level as the current priority of the message.
[0025] Furthermore, each message corresponds to a first time threshold and a second time threshold, wherein the first time threshold is less than the second time threshold, and the method includes:
[0026] If it is determined that the dwell time of the message has reached the corresponding first time threshold, an alarm is triggered.
[0027] If it is determined that the dwell time of the message has reached the corresponding second time threshold, the message is discarded.
[0028] Based on the same inventive concept, this application also proposes an intelligent terminal, which includes a processor and a memory. The processor is communicatively connected to the memory, and the memory stores program data. The program data is used to execute the queue communication method as described in the above embodiments.
[0029] Based on the same inventive concept, this application also proposes a computer-readable storage medium storing a computer program that is used to execute the queue communication method described above.
[0030] Compared to existing technologies, the advantages of this application are as follows: It determines the initial priority of messages added to the queue, performs priority decay based on message dwell time and initial priority, sorts messages according to their current priority, and transmits messages based on the sorting result. This application can decay the priority of messages based on their dwell time and sort them according to their current priority, effectively avoiding the problem of high-priority messages being blocked by low-priority or long-staying messages in the queue, improving the real-time performance of multi-task communication, and effectively leveraging the advantages of fast queue communication between multiple tasks. Attached Figure Description
[0031] Figure 1 This is a flowchart of an embodiment of the queue communication method of this application;
[0032] Figure 2 This is a flowchart of message sending and sorting in the queue communication method of this application;
[0033] Figure 3 This is a flowchart illustrating message processing based on dwell time in the queue communication method of this application;
[0034] Figure 4 This is a structural diagram of an embodiment of the smart terminal of this application;
[0035] Figure 5 This is a structural diagram of an embodiment of a computer-readable storage medium of this application. Detailed Implementation
[0036] The following specific examples illustrate the implementation of this application. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. This application can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this application. It should be noted that the various embodiments of this disclosure described and shown in the accompanying drawings can be combined with each other without conflict, and the structural components or functional modules therein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the accompanying drawings is not intended to limit the scope of the claimed disclosure, but merely represents selected embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.
[0037] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this disclosure. The singular forms “a,” “the,” and “the” as used in this disclosure and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
[0038] Please see Figures 1 to 3 ,in, Figure 1 This is a flowchart of one embodiment of the queue communication method of this application; Figure 2 This is a flowchart of message sending and sorting in the queue communication method of this application; Figure 3 This is a flowchart illustrating message processing based on dwell time in the queue communication method of this application. (Combined with...) Figures 1 to 3 The queue communication method of this application is described in detail.
[0039] In this embodiment, the device executing the queue communication method is a smart terminal, which can be a car, home appliance, robot, electricity meter, or other object using an embedded operating system.
[0040] The queue communication methods include:
[0041] S101: Determine the initial priority of messages added to the queue, and perform priority decay based on message dwell time and current priority.
[0042] In this embodiment, the message added to the queue can be a message delivery object (such as a thread) placed in the queue. The smart terminal executing the method of this application can treat the message to be sent as a task and add it to the same queue. Alternatively, multiple queues can be set according to actual needs or the characteristics of the operating system. The queue to which the message is added is determined according to the object that sends or receives the message.
[0043] Optionally, the object that needs to send or receive messages can be a thread. After establishing the queue, the thread that currently needs to transmit messages is obtained, and the message of that thread is added to the queue. Multiple queues can also be set up, and one or more queues can be selected to execute the methods of this application, while other queues execute existing queue communication methods.
[0044] In this embodiment, determining the initial priority of a message added to the queue includes: determining that a new message has been detected added to the queue; obtaining the priority of the message delivery object corresponding to the new message; and determining the initial priority of the new message based on the priority. Specifically, when it is detected that a message delivery object needs to deliver a message, the message to be delivered can be treated as a task and added to a queue used to manage the message sending order.
[0045] In this embodiment, the priority of a message passing object (such as a thread) can be determined as the priority of its corresponding message. Alternatively, the message priority can be determined based on at least one of the following: the type of the message passing object, the corresponding message receiving object, and the content of the message.
[0046] In one embodiment, if it is determined that a thread puts a message into the queue, the current priority of that thread is obtained, and that priority is determined as the initial priority of the message in the queue.
[0047] In this embodiment, after determining the initial priority of a newly added message in the queue, the message's order in the queue can be determined based on this initial priority, and the message is sent based on this order. Specifically, messages in the queue are ordered according to their priority, with higher-priority messages sent first and lower-priority messages sent later (i.e., higher-priority messages are placed at the front of the queue), thereby preventing high-priority messages from being blocked and improving the working efficiency and smoothness of the smart terminal.
[0048] In this embodiment, to prevent newly added messages from being blocked by higher-priority messages for an extended period during message sending, the message priority can be gradually reduced based on the message's dwell time. Obtaining the message's dwell time includes: if it is determined that the message has not been sent, calculating the dwell time based on the current time and the time the message was added to the queue.
[0049] In one embodiment, the time when each message is added to the queue can be recorded, and it can be detected in real time whether all messages in the queue have been sent. If not, messages that are not currently in the sending state in the queue can be obtained, and the dwell time of each message can be calculated based on the difference between the current time and the time when the message was added to the queue.
[0050] In this embodiment, priority decay is performed based on message dwell time and initial priority, including: if it is determined that the current initial priority of the message is not the lowest priority, then the priority of the message is gradually reduced based on the current priority and dwell time.
[0051] In this embodiment, if it is determined that the current priority or initial priority of a message is the lowest priority, then priority downgrading of the message is not required.
[0052] In this embodiment, if multiple messages are at the same priority, when sorting messages based on priority, the multiple messages of the same priority can also be sorted according to the time when they were added to the queue, wherein the message added to the queue first is placed before the message added to the queue later.
[0053] In this embodiment, the longer a message resides, the greater its priority level decreases, until its reduced priority reaches the lowest priority. The magnitude of this lowest priority and the number of priority levels can be determined based on actual needs and are not limited here.
[0054] In this embodiment, the priority of a message is gradually reduced based on the current priority and dwell time, including: if it is determined that the dwell time reaches an integer multiple of a preset dwell time, the priority is reduced once until the priority of the message is reduced to the lowest priority; or if it is determined that the message has not been sent, the priority of the message is reduced once every preset dwell time until the priority of the message is reduced to the lowest priority.
[0055] In this embodiment, to avoid some messages being affected by priority downgrading, priority downgrading can be avoided when a message is detected to have a certain priority (such as the optimal priority) or to be a specific type of message.
[0056] Alternatively, different preset dwell times or different message decay methods can be set for different types of messages (such as decaying some messages by two levels at a time) so that some unimportant messages can be quickly reduced to low priority.
[0057] In this embodiment, the preset dwell time can be 10 ticks (a relative time unit in the system), 20 ticks, 15 seconds, or other time lengths. The length of the dwell time can be determined according to actual needs.
[0058] In one embodiment, the preset dwell time can be 10 ticks. The time each message is added to the queue can be recorded, and the dwell time of each message can be obtained in real time. When the dwell time reaches an integer multiple of 10 ticks, the priority is decayed once until the message is sent or the dwell time reaches an integer multiple of the preset dwell time (such as 1x, 2x, 3x, and other multiples). Alternatively, when a message is not sent, the priority of messages above the lowest priority is decayed once every 10 ticks. This gradually reduces the priority of messages dwelling in the queue.
[0059] Optionally, to avoid congestion caused by too many messages in the queue, the method of this application further includes: a method comprising: obtaining the number of messages in the queue; and if it is determined that the number of messages has reached the maximum number of messages, then rejecting the addition of new messages.
[0060] In one embodiment, the maximum message count can be 20. After a message is sent, it is removed from the queue, and the current message count in the queue is monitored in real time. If the message count is less than 20, a new message is allowed to be added to the queue; if the message count reaches 20, a new message is rejected. Alternatively, the new message can be added to another queue that has not reached its maximum message count, or the queue can be waited for until the message count is less than the maximum message count before adding the message. Alternatively, the message can be left unsent by sending a message indicating that the queue is full to the corresponding message delivery object, causing the message delivery object to postpone sending the message or perform other operations.
[0061] In this embodiment, after obtaining the message's dwell time, an alarm or message discarding can be performed based on the length of the dwell time. Each message corresponds to a first time threshold and a second time threshold, where the first time threshold is less than the second time threshold. The method includes: if the message's dwell time reaches the corresponding first time threshold, an alarm is triggered; if the message's dwell time reaches the corresponding second time threshold, the message is discarded.
[0062] In this embodiment, to prevent high-priority messages from remaining unprocessed for extended periods, an alarm can be triggered by the target receiving object corresponding to the message. Specifically, the system detects whether the target receiving object is blocked by other objects (such as threads) by alerting it. If so, the target receiving object is woken up, its priority is raised to the same level as the message's priority, and the message is then sent to that target receiving object. Alternatively, an alarm message can be sent only to the target receiving object to remind it to receive the message.
[0063] In this embodiment, if the target receiving object fails to wake up or the message is never sent, causing the message's dwell time to reach the second time threshold, the message can be directly discarded to prevent it from occupying a position in the queue. The difference between the second time threshold and the first time threshold can be 20 ticks.
[0064] S102: Sort messages according to their current priority and transmit messages based on the sorting results.
[0065] In this embodiment, upon detecting a new message added to the queue or the priority of one or more existing messages decaying, the current priority of all messages in the queue can be obtained. The messages are then sorted in descending order based on their current priority, with higher-priority messages being sent first. If priorities are the same, they are sorted in ascending order by timestamp, ensuring that messages added to the queue earlier are sent first, guaranteeing fairness.
[0066] In one embodiment, the message whose priority has changed can be retrieved, designated as the first message, and its current priority determined. Other messages in the queue with that priority are then queried. A preliminary message sorting is performed based on the timestamps and order of these messages (the first message and others). The order of messages in the entire queue is then adjusted based on the preliminary sorting result to obtain the current message sorting result.
[0067] In this embodiment, message transmission can be performed through dynamic priority boosting. Message transmission based on message sorting includes: retrieving the highest-priority message from the queue and boosting the priority of the target receiving object corresponding to that message; if it is determined that the target receiving object has received the message, then lowering the priority of the target receiving object. Boosting the priority of the target receiving object ensures that high-priority communications are processed quickly.
[0068] In this embodiment, the priority of the target receiving object can be raised to the same level as the priority of its corresponding message. Alternatively, it can detect whether the priority of the target receiving object is lower than the priority of its corresponding message; if so, the priority is raised; otherwise, no priority adjustment is performed.
[0069] In this embodiment, the target receiving object can be a thread of the smart terminal. Multiple threads in the smart terminal communicate with each other through a queue to avoid interference and improve communication efficiency.
[0070] In this embodiment, to ensure that the target receiving object can effectively receive the message, the priority of the target receiving object corresponding to the message is increased, including: detecting the state of the target receiving object; if it is determined that the target receiving object is in a blocked state, the target receiving object is woken up and its priority is increased to the same as the current priority of the message.
[0071] Optionally, if it is determined that the target receiving object is not in a blocked state, its priority can be directly increased to the same priority as the message it needs to receive. After the priority increase is completed, the message is sent to the target receiving object, and after it is determined that the target receiving object has received the message (e.g., by sending a feedback message indicating that the message has been received), the target receiving object's priority is restored to its original priority.
[0072] In one embodiment, messages are sent one by one according to their order. After determining the message to be sent, it is checked whether the target receiving object corresponding to that message is in a blocked state. If so, the target receiving object is woken up, and its priority is temporarily increased to the priority corresponding to the message. After the target receiving object receives the message, its priority is restored to its original priority.
[0073] The method of this application will be further described below through specific embodiments of the queue communication method.
[0074] In one embodiment, a queue is created and initialized, waiting for messages to be added. When a message is added, it is checked whether the current queue has reached its maximum message count. If so, the message is discarded; otherwise, it is added to the queue. The message to be sent and its corresponding target receiver are determined. If the target receiver's priority is higher than the newly added message, the message is sent and the messages in the queue are sorted. Otherwise, the target receiver's priority is first increased to match the message to be sent. After the target receiver receives the message, its priority is restored to its original priority, and the sent messages are removed from the queue. The remaining messages in the queue are then sorted.
[0075] If messages still exist in the queue (i.e., not all messages in the queue have been received), the message priority is gradually reduced as the message's dwell time increases until it reaches the lowest priority. Furthermore, when the message's dwell time reaches the first time threshold, an alarm is triggered. This can involve forcibly waking up the target receiving object (such as a thread) and determining if it is blocked by a higher-priority object. If so, its priority is raised to match the message's priority so it can receive messages. After the message's dwell time reaches the second time threshold, the message is discarded. If all messages in the queue have been sent, the queue communication ends.
[0076] Beneficial effects: The queue communication method of this application determines the initial priority of messages added to the queue, decays the priority based on the message's dwell time and initial priority, sorts the messages according to their current priority, and transmits the messages based on the sorting result. This application can decay the priority of messages based on their dwell time and sort them according to their current priority, effectively avoiding the problem of high-priority messages being blocked by low-priority messages or messages that have been in the queue for a long time, improving the real-time performance of multi-task communication, and effectively leveraging the advantages of fast queue communication between multiple tasks.
[0077] Based on the same inventive concept, this application also proposes a smart terminal, please refer to [link to relevant documentation]. Figure 4 , Figure 4 This is a structural diagram of an embodiment of the smart terminal of this application. (In conjunction with...) Figure 4 The smart terminal described in this application is described in detail.
[0078] In this embodiment, the smart terminal includes a processor and a memory. The processor and the memory are communicatively connected. The memory stores program data, which is used to execute the queue communication method as described in the above embodiment.
[0079] In this embodiment, the processor is the control center of the smart terminal. It connects various parts of the smart terminal via various interfaces and lines, and performs various functions and processes data by running or executing software programs and / or modules stored in the memory, and by calling data stored in the memory, thereby providing overall monitoring of the smart terminal. Optionally, the processor may include one or more processing units; preferably, the processor may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may also not be integrated into the processor.
[0080] The smart terminal also includes a power supply (such as a battery) to power various components. Preferably, the power supply can be connected to the processor logic through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system.
[0081] The memory can be used to store software programs and modules. The processor executes various functional applications and data processing of the smart terminal by running the software programs and modules stored in the memory. The memory can mainly include a program storage area and a data storage area. The program storage area can store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area can store data created according to the use of the smart terminal (such as audio data, phone book, etc.). In addition, the memory can include high-speed random access memory, and can also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0082] Based on the same inventive concept, this application also proposes a computer-readable storage medium, please refer to [link to relevant documentation]. Figure 5 , Figure 5 This is a structural diagram of an embodiment of the computer-readable storage medium of this application, in conjunction with... Figure 5 The computer-readable storage medium of this application is described.
[0083] In this embodiment, a computer-readable storage medium stores a computer program that is used to perform the queue communication method as described in the above embodiments.
[0084] The computer-readable storage medium may include, but is not limited to, floppy disks, optical disks, CD-ROMs (compact disc-read-only memory), magneto-optical disks, ROMs (read-only memory), RAMs (random access memory), EPROMs (erasable programmable read-only memory), EEPROMs (electrically erasable programmable read-only memory), magnetic cards or optical cards, flash memory, or other types of media / machine-readable media suitable for storing machine-executable instructions. The computer-readable storage medium may be a product not connected to a computer device or a component used in a computer device.
[0085] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0086] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A queue communication method, characterized in that, The method includes: S101: Determine the initial priority of messages added to the queue, including: It is confirmed that a new message has been detected and added to the queue; Obtain the priority of the message delivery object corresponding to the new message, and determine the priority as the initial priority of the new message, wherein the message delivery object is a thread; Priority decay is performed based on the message's dwell time and current priority; If it is determined that the current priority of the message is not the lowest priority, then the priority of the message is gradually reduced according to the current priority and the dwell time; S102: Sort the messages according to their current priority, and transmit the messages based on the sorting results, including: Retrieve the highest priority message from the queue and increase the priority of the target receiving object corresponding to the message. If it is determined that the target receiving object has received the message, then the priority of the target receiving object is reduced.
2. The queue communication method according to claim 1, characterized in that, The step of gradually reducing the priority of the information based on the current priority and the dwell time includes: If it is determined that the dwell time reaches an integer multiple of the preset dwell time, the priority is reduced by one step until the message priority is reduced to the lowest priority. or If it is determined that the message has not been sent, the priority of the message is reduced once every preset dwell time until the priority of the message is reduced to the lowest priority.
3. The queue communication method according to claim 1, characterized in that, The method includes: Get the number of messages in the queue; If it is determined that the message data has reached the maximum number of messages, then the addition of new messages is rejected.
4. The queue communication method according to claim 1, characterized in that, The step of raising the priority of the target receiving object corresponding to the message includes: Detect the state of the target receiving object; If it is determined that the target receiving object is in a blocked state, then the target receiving object is woken up and its priority is raised to the same level as the current priority of the message.
5. The queue communication method according to claim 1, characterized in that, Each message corresponds to a first time threshold and a second time threshold, wherein the first time threshold is less than the second time threshold, and the method includes: If it is determined that the dwell time of the message has reached the corresponding first time threshold, an alarm is triggered. If it is determined that the dwell time of the message has reached the corresponding second time threshold, the message is discarded.
6. A smart terminal, characterized in that, The smart terminal includes a processor and a memory, the processor being communicatively connected to the memory, the memory storing program data, and the program data being used to execute the queue communication method according to any one of claims 1-5.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that is used to perform the queue communication method according to any one of claims 1-5.
Citation Information
Patent Citations
Message processing method and device, equipment and medium
CN119806748A