Message processing method and device, storage medium and electronic equipment

By assigning object identification to processes of embedded real-time operating system and identifying message objects, the communication error problem caused by thread failure to identify message objects is solved, and the reliability and stability of the system are improved.

CN118964058APending Publication Date: 2024-11-15SUPCON TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410989388.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-23
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

In an embedded real-time operating system, in the communication between threads and message objects, threads fail to identify the destruction of message objects in time, resulting in communication errors, reducing system reliability, and may cause memory trampling or overflow, space pollution and other problems.

Method used

By assigning object identifiers to the process, identifying whether the message object corresponding to the process exists, and processing messages based on the message processing logic corresponding to the process type, ensuring that the process communicates with the original message object and avoiding incorrect communication.

Benefits of technology

Improve the communication reliability of the system, prevent memory trampling or overflow, space pollution, ensure that message objects are not used incorrectly, and enhance system stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118964058A_ABST
    Figure CN118964058A_ABST
Patent Text Reader

Abstract

The invention provides a message processing method and device, a storage medium and electronic equipment, and is applied to the technical field of computers, and the method comprises the steps: when a current process in a ready state is not a process awakened from a dormant state, distributing an object identifier for the current process, and determining the current process as a target process; when the message object corresponding to the object identifier of the target process exists, determining the message object corresponding to the target process as a target message object; and processing the message in the target message object based on a message processing logic corresponding to the process type of the target process. Before the process communicates with the message object, the object identifier is used for identifying whether the message object corresponding to the current process exists or not, if yes, the message in the message object is processed based on the message processing logic corresponding to the process type of the current process, and it is ensured that the message object communicating with the current process is the original message object; communication errors are avoided, and the reliability of the system is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a message processing method and device, a storage medium and an electronic device. Background Art

[0002] In an embedded real-time operating system (RTOS), communication between threads is a key link to ensure efficient and stable operation of the system. RTOS is widely used in various fields because it can process events and data within strict time limits. For RTOS, the real-time performance and reliability of the system are crucial.

[0003] Communication between threads is usually implemented through message objects, such as mailboxes, message objects (MessageQueues), etc. In the process of communication between threads and message objects, there is a situation where the original message object of the thread is accidentally destroyed, and the thread fails to recognize this change in time, and the thread communicates with the wrong message object, which leads to communication errors and reduces system reliability. Summary of the invention

[0004] In view of this, an embodiment of the present invention provides a message processing method and device, a storage medium and an electronic device. The present invention uses an object identifier to identify whether there is a message object corresponding to a process. If there is, the message in the message object is processed based on the message processing logic corresponding to the process type of the process. This ensures that the process communicates with its original message object, avoids communication errors, and improves the reliability of the system.

[0005] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:

[0006] A message processing method, comprising:

[0007] When the current process in the ready state is not a process awakened from the dormant state, an object identifier is assigned to the current process, and the current process is determined as a target process;

[0008] Based on the object identifier of the target process, determining whether a message object corresponding to the target process exists, the message object being used to store a message;

[0009] When the message object corresponding to the target process exists, determining the message object corresponding to the target process as the target message object;

[0010] The message in the target message object is processed based on the message processing logic corresponding to the process type of the target process.

[0011] The above method may optionally further include:

[0012] When the message object corresponding to the target process does not exist, a process error message is generated and the target process is exited.

[0013] The above method may optionally further include:

[0014] When the current process is a process awakened from a dormant state, determining whether the awakening type of the current process is normal;

[0015] If the wake-up type of the current process is not normal, a process error message is generated and the current process is exited;

[0016] If the wake-up type of the current process is normal, the step of determining the current process as the target process is performed.

[0017] In the above method, optionally, the processing of the message in the target message object based on the message processing logic corresponding to the process type of the target process includes:

[0018] When the process type of the target process is a sending type, determining whether a preset sending blocking linked list is empty and the number of messages in the target message object has not reached a preset maximum value;

[0019] When the sending blocking linked list is empty and the number of messages in the target message object has not reached a preset maximum value, causing the target process to send a message to the target message object;

[0020] When the sending blocking linked list is not empty, or the number of messages in the target message object reaches a preset maximum value, determining that the target process is blocked, and mounting the target process to the sending blocking linked list to sleep;

[0021] When the process type of the target process is a receiving type, determining whether a preset receiving blocking linked list is empty and whether the message in the target message object is not empty;

[0022] When the receiving blocking linked list is empty and the message in the target message object is not empty, enabling the target process to read the message in the target message object;

[0023] When the receiving blocking linked list is not empty, or the message in the target message object is empty, it is determined that the target process is blocked, and the target process is mounted to the receiving blocking linked list to sleep.

[0024] The above method may optionally further include:

[0025] When there is a send process wake-up command, the process corresponding to the send process wake-up command in the send blocking linked list is awakened, and based on the send process wake-up command, the wake-up type of the awakened process is marked.

[0026] The above method may optionally further include:

[0027] When there is a receiving process wake-up command, the process corresponding to the receiving process wake-up command in the receiving blocking linked list is awakened, and based on the receiving process wake-up command, the wake-up type of the awakened process is marked.

[0028] A message processing device, comprising:

[0029] an allocation unit, configured to allocate an object identifier to the current process when the current process in the ready state is not a process awakened from the dormant state, and determine the current process as a target process;

[0030] A first determining unit, configured to determine whether a message object corresponding to the target process exists based on an object identifier of the target process, the message object being used to store a message;

[0031] a second determining unit, configured to determine the message object corresponding to the target process as a target message object when the message object corresponding to the target process exists;

[0032] The processing unit is used to process the message in the target message object based on the message processing logic corresponding to the process type of the target process.

[0033] The above device may optionally further include:

[0034] The first generating unit is used to generate process error information and exit the target process when the message object corresponding to the target process does not exist.

[0035] The above device may optionally further include:

[0036] The third determination unit is used to determine whether the wake-up type of the current process is normal when the current process is a process awakened from a sleep state; if the wake-up type of the current process is not normal, generate process error information and exit the current process; if the wake-up type of the current process is normal, execute the step of determining the current process as the target process.

[0037] In the above device, optionally, the processing unit executes the step of processing the message in the target message object based on the message processing logic corresponding to the process type of the target process, including:

[0038] When the process type of the target process is a sending type, determining whether a preset sending blocking linked list is empty and the number of messages in the target message object has not reached a preset maximum value;

[0039] When the sending blocking linked list is empty and the number of messages in the target message object has not reached a preset maximum value, causing the target process to send a message to the target message object;

[0040] When the sending blocking linked list is not empty, or the number of messages in the target message object reaches a preset maximum value, determining that the target process is blocked, and mounting the target process to the sending blocking linked list to sleep;

[0041] When the process type of the target process is a receiving type, determining whether a preset receiving blocking linked list is empty and whether the message in the target message object is not empty;

[0042] When the receiving blocking linked list is empty and the message in the target message object is not empty, enabling the target process to read the message in the target message object;

[0043] When the receiving blocking linked list is not empty, or the message in the target message object is empty, it is determined that the target process is blocked, and the target process is mounted to the receiving blocking linked list to sleep.

[0044] The above device may optionally further include:

[0045] The first awakening unit is used to awaken the process corresponding to the sending process awakening command in the sending blocking linked list when there is a sending process awakening command, and mark the awakening type of the awakened process based on the sending process awakening command.

[0046] The above device may optionally further include:

[0047] The second awakening unit is used to awaken the process corresponding to the received process awakening command in the received blocking linked list when there is a received process awakening command, and mark the awakening type of the awakened process based on the received process awakening command.

[0048] A storage medium includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the message processing method as described above.

[0049] An electronic device includes a memory and one or more instructions, wherein the one or more instructions are stored in the memory and are configured to be executed by one or more processors to perform the message processing method as described above.

[0050] Compared with the prior art, the present invention has the following advantages:

[0051] The present invention provides a message processing method and device, a storage medium and an electronic device, including: when the current process in the ready state is not a process awakened from the dormant state, an object identifier is assigned to the current process, and the current process is determined as a target process; based on the object identifier of the target process, whether a message object corresponding to the target process exists, when the message object corresponding to the target process exists, the message object corresponding to the target process is determined as the target message object; based on the message processing logic corresponding to the process type of the target process, the message in the target message object is processed. Before the process of the present invention communicates with the message object, the object identifier of the current process is used to identify whether the message object corresponding to the current process exists. If it exists, the message in the message object is processed based on the message processing logic corresponding to the process type of the current process, thereby ensuring that the message object communicated by the current process is the original message object, avoiding communication errors, and improving the reliability of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0053] Figure 1 A flowchart of a message processing method provided by an embodiment of the present invention;

[0054] Figure 2 A flow chart of a method for processing a message in a target message object when the process type of the target process is a sending type provided by an embodiment of the present invention;

[0055] Figure 3 A flow chart of a method for processing a message in a target message object when the process type of the target process is a receiving type provided by an embodiment of the present invention;

[0056] Figure 4 A schematic diagram of the structure of a message processing device provided by an embodiment of the present invention;

[0057] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0058] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0059] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.

[0060] As can be seen from the background technology, during the process of communication between a thread and a message object, the original message object of the thread may be accidentally destroyed, and the thread fails to recognize this change in time, and the thread communicates with the wrong message object. This situation will cause system communication errors and reduce system reliability. In addition to the above problems, it will also cause problems such as memory trampling or overflow, space pollution, etc.

[0061] In order to solve the above-mentioned problems, the present invention provides a message processing solution. When a process is a non-wake-up process, an object identifier is assigned to the process, and the object identifier is used to determine whether a message object corresponding to the process exists. If it exists, the message in the message object corresponding to the process is processed according to the message processing logic corresponding to the process type of the process, thereby ensuring that the process communicates with its original message object, avoiding communication errors, improving the communication reliability of the system, and avoiding problems such as memory trampling or overflow, space pollution, etc.

[0062] The solution provided by the present invention is applied to an embedded real-time operating system, referring to Figure 1 , is a flow chart of a message processing method provided by an embodiment of the present invention, which is specifically described as follows:

[0063] S101. Determine whether the current process in the ready state is a process awakened from the sleep state; if the current process is not a process awakened from the sleep state, execute S102; if the current process is a process awakened from the sleep state, execute S108.

[0064] A process in the Ready state is one that is ready to execute.

[0065] Preferably, the processes of the present application are divided into two categories, one is a sending process and the other is a receiving process.

[0066] A method for determining whether the current process is a process awakened from a dormant state may be: determining whether the current process has a mount identifier, or determining whether the current process is a process removed from a mounted linked list; when the current process has a mount identifier, or is a process removed from a mounted linked list, it may be determined that the current process is a process awakened from a dormant state.

[0067] Preferably, the dormant state can also be understood as a pause state.

[0068] S102. Allocate an object identifier for the current process.

[0069] When the current process is not a process awakened from a dormant state, the current process can be considered as a newly generated process. Such a process needs to be assigned an object identifier, which is the identifier of the message object corresponding to the current one.

[0070] After the message object is created, an object identifier is generated. A random number can be used as the object identifier of the message object. Preferably, the object identifier is unique.

[0071] After the object identifier is allocated to the current process, S103 is executed.

[0072] S103: Determine the current process as the target process.

[0073] After executing S103, execute S104.

[0074] S104. Based on the object identifier of the target process, determine whether the message object corresponding to the target process exists; when the message object corresponding to the target process exists, execute S105; when the message object corresponding to the target process does not exist, execute S107.

[0075] Preferably, there is at least one message object in the system, and the object identifier of the target process is traversed through the various message objects currently existing in the system to determine whether there is a message object corresponding to the object identifier of the target process in the system. If so, it means that the message object corresponding to the target process exists, and it also means that the message object for communication with the target process has not been destroyed, and then S105 can be executed. Preferably, the object identifier of the message object corresponding to the target is consistent with the object identifier of the target process.

[0076] When there is no message object corresponding to the object identifier of the target process in the system, it is recognized that the message object communicating with the target process has been destroyed, and S107 is executed.

[0077] Preferably, the message object can be a message object or a mailbox, and the message object is used to store messages; preferably, the message object can be set to a first-in-first-out policy.

[0078] S105. Determine the message object corresponding to the target process as the target message object.

[0079] The target message object is the message object that the target process plans to communicate with.

[0080] After executing S105, execute S106.

[0081] S106. Process the message in the target message object based on the message processing logic corresponding to the process type of the target process.

[0082] It should be noted that different types of processes have different message processing logics. The processes of the present invention are divided into two types: sending processes and receiving processes. The message processing logics of these two types of processes are different.

[0083] Different types of processes use different message processing logics to process messages in message objects, so that different types of processes can achieve different effects after execution, and different types of processes can communicate with message objects and then process messages in message objects.

[0084] S107: Generate process error information and exit the target process.

[0085] It should be noted that when it is identified that the message object of the process has been destroyed, a process error message of the target process is generated, and the target process is exited so that the target process is not executed, thereby ensuring that the target process does not communicate with the wrong message object, avoiding such erroneous operations, preventing storage space pollution, avoiding memory trampling or overflow, and improving system reliability.

[0086] S108, determining whether the wake-up type of the current process is normal; if the wake-up type of the current process is not normal, executing S109; if the wake-up type of the current process is normal, returning to execute S103.

[0087] S109: Generate process error information and exit the current process.

[0088] When the current process is a process awakened from a dormant state, it is necessary to determine whether the awakening type of the current process is normal. Preferably, the awakening type can also be regarded as the awakening reason.

[0089] When the wake-up type of the current process is normal, the above step S103 is executed; when the wake-up type of the current process is not normal, it is necessary to generate process error information of the current process and exit the current process.

[0090] Preferably, the wake-up types include but are not limited to resource allocation wake-up, timeout wake-up, and destruction wake-up, wherein resource allocation wake-up is normal, and timeout wake-up and destruction wake-up are abnormal.

[0091] Preferably, the process error information can be used to remind the user that the process has been abnormally returned.

[0092] In the method provided by the embodiment of the present invention, when the current process in the ready state is not a process awakened from the dormant state, an object identifier is assigned to the current process, and the current process is determined as the target process; based on the object identifier of the target process, it is determined whether the message object corresponding to the target process exists, and when the message object corresponding to the target process exists, the message object corresponding to the target process is determined as the target message object; based on the message processing logic corresponding to the process type of the target process, the message in the target message object is processed. Before the process of the present invention communicates with the message object, the object identifier of the current process is used to identify whether the message object corresponding to the current process exists. If it exists, the message in the message object is processed based on the message processing logic corresponding to the process type of the current process, thereby ensuring that the message object communicated by the current process is the original message object, avoiding communication errors, and improving the reliability of the system.

[0093] Reference Figure 2 , which is a flow chart of a method for processing a message in a target message object when the process type of the target process is a sending type provided by an embodiment of the present invention, and is specifically described as follows:

[0094] S201. Determine whether the preset sending blocking list is empty and the number of messages in the target message object has not reached the preset maximum value; when the sending blocking list is empty and the number of messages in the target message object has not reached the preset maximum value, execute S202; when the sending blocking list is not empty, or the number of messages in the target message object reaches the preset maximum value, execute S205.

[0095] Preferably, the table value of the sending blocking linked list can be used to determine whether the sending blocking linked list is empty. When the table value of the sending blocking linked list is equal to 0, it means that the sending blocking linked list is empty; when the table value of the sending blocking linked list is less than 0, it means that the sending blocking linked list is not empty. Furthermore, the initial value of the table value of the sending blocking linked list is 0, and the maximum value of the table value is also 0.

[0096] When the number of messages in the target message object reaches the preset maximum value, it means that the target message object is in a full sending state, that is, the number of messages saved in the target message object has reached the maximum number of messages that the target message object can carry. The preset maximum value can be set according to actual needs.

[0097] S202: Enable the target process to send a message to the target message object.

[0098] When the sending blocking list is empty and the number of messages in the target message object has not reached the preset maximum value, execute S202; execute the target process, so that the target process sends a message to the target message object.

[0099] S203, whether the conditions for generating a receiving process wake-up command are met; if the conditions for generating a receiving process wake-up command are met, execute S204; if the conditions for generating a receiving process wake-up command are not met, end.

[0100] When determining whether the conditions for generating a receiving process wake-up are met, after the target process sends a message to the target message object, when the receiving blocking list is not empty, the conditions for generating a receiving process wake-up are met; when there are idle processing resources, the conditions for generating a receiving process wake-up are met; when there is a timed-out process in the receiving blocking list, the conditions for generating a receiving process wake-up are met; when there is a signal to destroy the process in the receiving blocking list, the conditions for generating a receiving process wake-up are met.

[0101] S204: Generate a receiving process wake-up command.

[0102] It should be noted that the contents of the receiving process wake-up commands generated by different scenarios that meet the conditions for generating the receiving process wake-up commands are different. After the target process sends a message to the target message object, when the receiving blocking list is not empty and when there are idle processing resources, the receiving process wake-up commands generated by these two scenarios contain normal wake-up information; when there is a timed-out process in the receiving blocking list and when there is a signal to destroy the process in the receiving blocking list, the receiving process wake-up commands generated by these two scenarios contain abnormal wake-up information.

[0103] A receiving process wake-up command can be generated based on specific scenarios that meet the receiving process wake-up conditions. Specifically, for example, after the target process sends a message to the target message object, the receiving blocking list chain is not empty, or when a receiving process wake-up command is generated when there are idle processing resources, when the process is subsequently woken up from the receiving blocking list according to the receiving process wake-up command, the first process in the receiving blocking list will be woken up; when a receiving process wake-up command is generated when there is a timed-out process in the receiving blocking list, when the process is subsequently woken up from the receiving blocking list according to the receiving process wake-up command, the timed-out process in the receiving blocking list will be woken up; when a receiving process wake-up command is generated when there is a signal to destroy the process in the receiving blocking list, when the process is subsequently woken up from the receiving blocking list according to the receiving process wake-up command, all processes in the receiving blocking list will be woken up.

[0104] S205: Determine that the target process is blocked, and mount the target process to the send blocking list for hibernation.

[0105] Preferably, after the target process is mounted to the sending blocking linked list, the table value of the sending blocking linked list may be reduced by one.

[0106] Furthermore, after the target process is mounted to the send blocking list and sleeps, the sleep time of the target process is set, which can be understood as the waiting time, that is, the maximum time the target process is in the send blocking list. When the sleep time is exceeded, it means that the target process has timed out.

[0107] The processes in the send blocking list are arranged in the order in which they enter the list.

[0108] S206, whether there is a process wake-up command sent, when there is a process wake-up command sent, execute S207; when there is no process wake-up command received, end.

[0109] It should be noted that the content of generating the send process wake-up command will be described below and will not be repeated here.

[0110] S207: Wake up the process corresponding to the sending process wake-up command in the sending blocking list, and mark the wake-up type of the awakened process based on the sending process wake-up command.

[0111] For instructions on waking up the process corresponding to the sending process wake-up command in the sending blocking list, please refer to the instructions below and will not be repeated here.

[0112] It should be noted that when normal wakeup information exists in the process wakeup command sent, the wakeup type of the process marked to be awakened is normal; when abnormal wakeup information exists in the process wakeup command sent, the wakeup type of the process marked to be awakened is abnormal.

[0113] Preferably, after waking up the process in the sending blocking linked list, the table value of the sending blocking linked list is added to the number of awakened processes, and when the obtained table value is greater than the maximum value, the table value of the sending blocking linked list is initialized.

[0114] In the method provided by the embodiment of the present invention, when the process type of the target process is a sending type, whether the target process meets the condition for sending the message is determined by judging whether the sending blocking list is empty and whether the number of messages in the target message object reaches a preset maximum value. When the target process meets the condition for sending the message, the message is sent to the target message object, and after the target process sends the message to the target object, when the receiving blocking list is not empty, the first process in the receiving blocking list is awakened, or when there are idle processing resources, the first process in the receiving blocking list is awakened, thereby avoiding high-priority threads from preempting low-priority threads, ensuring the message sending of low-priority threads, and improving the reliability of the system.

[0115] Reference Figure 3, which is a flowchart of a method for processing a message in a target message object when the process type of the target process is a receiving type provided by an embodiment of the present invention, and is specifically described as follows:

[0116] S301. Determine whether the preset receiving blocking list is empty and whether the message in the target message object is not empty; when the receiving blocking list is empty and the message in the target message object is not empty, execute S302; when the receiving blocking list is not empty, or the message in the target message object is empty, execute S305.

[0117] Preferably, the table value of the receiving blocking linked list can be used to determine whether the receiving blocking linked list is empty. When the table value of the receiving blocking linked list is equal to 0, it means that the receiving blocking linked list is empty; when the table value of the receiving blocking linked list is less than 0, it means that the receiving blocking linked list is not empty. Furthermore, the initial value of the table value of the receiving blocking linked list is 0, and the maximum value of the table value is also 0.

[0118] When the message in the target message object is not empty, it means that there are consumable messages in the target message object; when the message in the target message object is empty, it means that there are no consumable messages in the target message object. When the subsequent process reads the message from the message object, it reads empty, that is, receives empty.

[0119] S302: Enable the target process to read the message in the target message object.

[0120] Execute the target process so that the target process consumes the message in the target message object.

[0121] Preferably, when the message object is a first-in-first-out queue, the messages in the message object are consumed one by one in the order in which they are arranged.

[0122] S303, whether the conditions for generating a send process wake-up command are met; if the conditions for generating a send process wake-up command are met, execute S304; if the conditions for generating a send process wake-up command are not met, end.

[0123] When determining whether the conditions for generating a sending process wake-up are met, after the target process reads the message in the target message object, when the sending blocking linked list is not empty, the conditions for generating a sending process wake-up are met; when there are idle processing resources, the conditions for generating a sending process wake-up are met; when there is a timed-out process in the sending blocking linked list, the conditions for generating a sending process wake-up are met; when there is a signal to destroy the process in the sending blocking linked list, the conditions for generating a sending process wake-up are met.

[0124] S304: Generate a sending process wake-up command.

[0125] It should be noted that the contents of the send process wake-up commands generated by different scenarios that meet the conditions for generating a send process wake-up command are different. After the target process reads the message in the target message object, when the send blocking list is not empty and when there are idle processing resources, the send process wake-up commands generated by these two scenarios contain normal wake-up information; when there is a timed-out process in the send blocking list and when there is a signal to destroy the process in the send blocking list, the send process wake-up commands generated by these two scenarios contain abnormal wake-up information.

[0126] A send process wake-up command can be generated based on specific scenarios that meet the send process wake-up conditions. For example, after the target process reads the message in the target message object, the send blocking list chain is not empty, or when a send process wake-up command is generated when there are idle processing resources, when the process is subsequently woken up from the send blocking list according to the send process wake-up command, the first process in the send blocking list will be woken up; when a send process wake-up command is generated when there is a timed-out process in the send blocking list, when the process is subsequently woken up from the send blocking list according to the send process wake-up command, the timed-out process in the send blocking list will be woken up; when a send process wake-up command is generated when there is a signal to destroy the process in the send blocking list, when the process is subsequently woken up from the send blocking list according to the send process wake-up command, all processes in the send blocking list will be woken up.

[0127] S305: Determine whether the target process is blocked, and mount the target process to a receiving blocking list.

[0128] Preferably, after the target process is mounted to the receiving blocking linked list, the table value of the receiving blocking linked list may be reduced by one.

[0129] Furthermore, after the target process is mounted to the receiving blocking list and put into sleep mode, the sleep time of the target process is set, which can be understood as the waiting time, that is, the maximum time the target process is in the receiving blocking list. When the sleep time is exceeded, it means that the target process has timed out.

[0130] The processes in the receive blocking list are arranged in the order in which they enter the list.

[0131] S306: Is there a receiving process wake-up command? If there is a receiving process wake-up command, execute S307; if there is no receiving process wake-up command, end.

[0132] It should be noted that the contents of generating the receiving process wake-up command are detailed above and will not be repeated here.

[0133] S307: Wake up the process corresponding to the received process wake-up command in the received blocking list, and mark the wake-up type of the awakened process based on the received process wake-up command.

[0134] The instructions for waking up the process corresponding to the receiving process wake-up command in the receiving blocking list can refer to the above instructions, which will not be repeated here.

[0135] It should be noted that when the received process wakeup command contains normal wakeup information, the wakeup type of the process marked to be awakened is normal; when the received process wakeup command contains abnormal wakeup information, the wakeup type of the process marked to be awakened is abnormal.

[0136] Preferably, after waking up the process in the receiving blocking linked list, the table value of the receiving blocking linked list is added to the number of awakened processes, and when the obtained table value is greater than the maximum value, the table value of the receiving blocking linked list is initialized.

[0137] The present invention uses a receiving blocking linked list and a sending blocking linked list to record blocked receiving threads and blocked sending threads, thereby strictly implementing the first-in-first-out message transmission and preventing high-priority threads from preempting low-priority thread resources.

[0138] The present invention discloses a message processing mechanism, which can ensure the message reliability of an embedded operating system. The scheme uses an object identifier to identify whether the original message object of a process exists, thereby ensuring that the process is no longer executed after the original message object of the process is destroyed. By using the mechanism, it is ensured that the message object will not be used again after being destroyed, thereby preventing space pollution, and ensuring that the thread awakened by normal resources will not operate the destroyed thread communication object, thereby preventing the occurrence of erroneous operation when the static thread communication object is used again after being destroyed, and the problem of dirty data in the space of the dynamic thread communication object. In addition, the message is strictly transmitted in a first-in-first-out order to ensure that the message is not preempted.

[0139] In the solution provided by the present invention, a receiving blocking linked list and a sending blocking linked list are used to control the wake-up order of blocked processes. When there are processing resources, the processes are woken up in the order of entry into the table, and low-priority resources will not be preempted, thereby ensuring that low-priority processes will not be preempted by high-priority processes.

[0140] Therefore, the solution provided by the present invention can solve the problems in the current thread communication method, in which the first-in-first-out blocking method is used to wake up the blocked threads in the order of suspension when resources are insufficient, but it cannot guarantee that the awakened threads can obtain resources to continue execution, and high-priority or same-priority threads preempt resources or destroy thread communication objects; resulting in the low-priority thread being unable to obtain the first message or send the current message after normal awakening; resulting in the low-priority thread operating the destroyed thread communication object after normal awakening.

[0141] The solution provided by the present invention is an optimization mechanism based on thread communication, which is applied in embedded real-time operating systems in the industrial field and can be configured by users, making thread communication safer and more stable, meeting the advantages of different thread communication application scenarios of users. Users can configure the use of first-in-first-out, combined with the original blocked thread wake-up order (FIFO, PRI), which can meet all user application scenarios.

[0142] and Figure 1 Corresponding to the method shown in the figure, the present invention provides a message processing device, which is used to support Figure 1 To implement the method shown, the device is set in an embedded real-time operating system.

[0143] Reference Figure 4 , is a structural diagram of a message processing device provided by an embodiment of the present invention, and is specifically described as follows:

[0144] The allocation unit 401 is used to allocate an object identifier to the current process when the current process in the ready state is not a process awakened from the dormant state, and determine the current process as a target process;

[0145] A first determining unit 402 is used to determine whether a message object corresponding to the target process exists based on the object identifier of the target process, and the message object is used to store the message;

[0146] A second determining unit 403 is configured to determine the message object corresponding to the target process as a target message object when the message object corresponding to the target process exists;

[0147] The processing unit 404 is used to process the message in the target message object based on the message processing logic corresponding to the process type of the target process.

[0148] In the device provided by the embodiment of the present invention, when the current process in the ready state is not a process awakened from the dormant state, an object identifier is assigned to the current process, and the current process is determined as the target process; based on the object identifier of the target process, it is determined whether the message object corresponding to the target process exists, and when the message object corresponding to the target process exists, the message object corresponding to the target process is determined as the target message object; based on the message processing logic corresponding to the process type of the target process, the message in the target message object is processed. Before the process of the present invention communicates with the message object, the object identifier of the current process is used to identify whether the message object corresponding to the current process exists. If it exists, the message in the message object is processed based on the message processing logic corresponding to the process type of the current process, thereby ensuring that the message object communicated by the current process is the original message object, avoiding communication errors, and improving the reliability of the system.

[0149] In another embodiment provided by the present invention, the device further comprises:

[0150] The first generating unit is used to generate process error information and exit the target process when the message object corresponding to the target process does not exist.

[0151] In another embodiment provided by the present invention, the device further comprises:

[0152] The third determination unit is used to determine whether the wake-up type of the current process is normal when the current process is a process awakened from a sleep state; if the wake-up type of the current process is not normal, generate process error information and exit the current process; if the wake-up type of the current process is normal, execute the step of determining the current process as the target process.

[0153] In another embodiment provided by the present invention, the processing unit 404 of the device executes the step of processing the message in the target message object based on the message processing logic corresponding to the process type of the target process, including:

[0154] When the process type of the target process is a sending type, determining whether a preset sending blocking linked list is empty and the number of messages in the target message object has not reached a preset maximum value;

[0155] When the sending blocking linked list is empty and the number of messages in the target message object has not reached a preset maximum value, causing the target process to send a message to the target message object;

[0156] When the sending blocking linked list is not empty, or the number of messages in the target message object reaches a preset maximum value, determining that the target process is blocked, and mounting the target process to the sending blocking linked list to sleep;

[0157] When the process type of the target process is a receiving type, determining whether a preset receiving blocking linked list is empty and whether the message in the target message object is not empty;

[0158] When the receiving blocking linked list is empty and the message in the target message object is not empty, enabling the target process to read the message in the target message object;

[0159] When the receiving blocking linked list is not empty, or the message in the target message object is empty, it is determined that the target process is blocked, and the target process is mounted to the receiving blocking linked list to sleep.

[0160] In another embodiment provided by the present invention, the device further comprises:

[0161] The first awakening unit is used to awaken the process corresponding to the sending process awakening command in the sending blocking linked list when there is a sending process awakening command, and mark the awakening type of the awakened process based on the sending process awakening command.

[0162] In another embodiment provided by the present invention, the device further comprises:

[0163] The second awakening unit is used to awaken the process corresponding to the received process awakening command in the received blocking linked list when there is a received process awakening command, and mark the awakening type of the awakened process based on the received process awakening command.

[0164] An embodiment of the present invention further provides a storage medium, which includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the above-mentioned message processing method.

[0165] The embodiment of the present invention further provides an electronic device, the structural diagram of which is shown in FIG. Figure 5 As shown, it specifically includes a memory 601 and one or more instructions 602, wherein the one or more instructions 602 are stored in the memory 601 and are configured to be executed by one or more processors 603 to execute the one or more instructions 602 to perform the above-mentioned message processing method.

[0166] It should be noted that the information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0167] The specific implementation processes and derivative methods of the above-mentioned embodiments are all within the protection scope of the present invention.

[0168] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.

[0169] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0170] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A message processing method, characterized in that: include: When the current process in the ready state is not a process awakened from the dormant state, an object identifier is assigned to the current process, and the current process is determined as a target process; Based on the object identifier of the target process, determining whether a message object corresponding to the target process exists, the message object being used to store a message; When the message object corresponding to the target process exists, determining the message object corresponding to the target process as the target message object; The message in the target message object is processed based on the message processing logic corresponding to the process type of the target process.

2. The method according to claim 1, characterized in that Also includes: When the message object corresponding to the target process does not exist, a process error message is generated and the target process is exited.

3. The method according to claim 1, characterized in that Also includes: When the current process is a process awakened from a dormant state, determining whether the awakening type of the current process is normal; If the wake-up type of the current process is not normal, a process error message is generated and the current process is exited; If the wake-up type of the current process is normal, the step of determining the current process as the target process is performed.

4. The method according to claim 1, characterized in that: The processing of the message in the target message object based on the message processing logic corresponding to the process type of the target process includes: When the process type of the target process is a sending type, determining whether a preset sending blocking linked list is empty and the number of messages in the target message object has not reached a preset maximum value; When the sending blocking linked list is empty and the number of messages in the target message object has not reached a preset maximum value, causing the target process to send a message to the target message object; When the sending blocking linked list is not empty, or the number of messages in the target message object reaches a preset maximum value, determining that the target process is blocked, and mounting the target process to the sending blocking linked list to sleep; When the process type of the target process is a receiving type, determining whether a preset receiving blocking linked list is empty and whether the message in the target message object is not empty; When the receiving blocking linked list is empty and the message in the target message object is not empty, enabling the target process to read the message in the target message object; When the receiving blocking linked list is not empty, or the message in the target message object is empty, it is determined that the target process is blocked, and the target process is mounted to the receiving blocking linked list to sleep.

5. The method according to claim 4, characterized in that Also includes: When there is a send process wake-up command, the process corresponding to the send process wake-up command in the send blocking linked list is awakened, and based on the send process wake-up command, the wake-up type of the awakened process is marked.

6. The method according to claim 4, characterized in that Also includes: When there is a receiving process wake-up command, the process corresponding to the receiving process wake-up command in the receiving blocking linked list is awakened, and based on the receiving process wake-up command, the wake-up type of the awakened process is marked.

7. A message processing device, characterized in that: include: an allocation unit, configured to allocate an object identifier to the current process when the current process in the ready state is not a process awakened from the dormant state, and determine the current process as a target process; A first determining unit, configured to determine whether a message object corresponding to the target process exists based on an object identifier of the target process, the message object being used to store a message; a second determining unit, configured to determine the message object corresponding to the target process as a target message object when the message object corresponding to the target process exists; The processing unit is used to process the message in the target message object based on the message processing logic corresponding to the process type of the target process.

8. The device according to claim 7, characterized in that Also includes: The first generating unit is used to generate process error information and exit the target process when the message object corresponding to the target process does not exist.

9. A storage medium, characterized in that: The storage medium includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the message processing method according to any one of claims 1 to 6.

10. An electronic device, characterized in that: The system comprises a memory and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by one or more processors to execute the message processing method according to any one of claims 1 to 6.