CN118174980A - Message processing method and device, electronic equipment, storage medium and vehicle - Google Patents
Message processing method and device, electronic equipment, storage medium and vehicle Download PDFInfo
- Publication number
- CN118174980A CN118174980A CN202211574992.XA CN202211574992A CN118174980A CN 118174980 A CN118174980 A CN 118174980A CN 202211574992 A CN202211574992 A CN 202211574992A CN 118174980 A CN118174980 A CN 118174980A
- Authority
- CN
- China
- Prior art keywords
- space
- buffer queue
- available
- identifier
- position identifier
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000003672 processing method Methods 0.000 title claims abstract description 18
- 238000000034 method Methods 0.000 claims abstract description 49
- 230000006854 communication Effects 0.000 claims abstract description 24
- 238000004891 communication Methods 0.000 claims abstract description 21
- 238000004590 computer program Methods 0.000 claims description 19
- 230000008569 process Effects 0.000 description 17
- 230000007717 exclusion Effects 0.000 description 15
- 238000010586 diagram Methods 0.000 description 10
- 230000000694 effects Effects 0.000 description 5
- 230000004044 response Effects 0.000 description 5
- 230000009471 action Effects 0.000 description 3
- 230000006870 function Effects 0.000 description 3
- 230000005540 biological transmission Effects 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 230000000903 blocking effect Effects 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L47/00—Traffic control in data switching networks
- H04L47/50—Queue scheduling
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L2012/40208—Bus networks characterized by the use of a particular bus standard
- H04L2012/40215—Controller Area Network CAN
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L2012/40267—Bus for use in transportation systems
- H04L2012/40273—Bus for use in transportation systems the transportation system being a vehicle
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer And Data Communications (AREA)
Abstract
The disclosure relates to a message processing method, a device, an electronic device, a storage medium and a vehicle, and relates to the technical field of controller area network communication, wherein the method comprises the following steps: responding to a message read-write instruction, acquiring an enqueue position identifier, an dequeue position identifier and a maximum readable position identifier of a buffer queue, wherein the message read-write instruction indicates to execute the operation of writing or reading message data for the buffer queue; comparing the enqueue position identifier, the dequeue position identifier and the maximum readable position identifier to obtain the space occupation condition of the buffer queue, wherein the space occupation condition comprises: the space is available completely, the space part is available, and the space is not available; and when the space occupation condition of the buffer queue is the target condition, executing the operation of writing or reading the message data aiming at the position indicated by the target position mark. By adopting the scheme provided by the disclosure, CAN communication efficiency and performance CAN be improved.
Description
Technical Field
The disclosure relates to the technical field of controller area network communication, in particular to a message processing method, a message processing device, electronic equipment, a storage medium and a vehicle.
Background
The vehicle implements communication interactions between the control system and the various components through a controller area network (Controller Area Network, CAN). In the actual use process of the vehicle, the data volume processed by CAN communication is larger, and the buffer queue is generally utilized to buffer the data in the CAN communication process, so that the data loss is prevented. At present, a mode of mutual exclusion lock is mainly adopted in the CAN communication process, taking a thread A and a thread B as examples, if the thread A successfully acquires the mutual exclusion lock to access the buffer queue, the thread B cannot successfully acquire the mutual exclusion lock, and needs to reenter the buffer queue to wait for the thread A to release the mutual exclusion lock, so that the buffer queue is blocked, and the performance of CAN communication is affected.
Disclosure of Invention
In order to solve the technical problems or at least partially solve the technical problems, the disclosure provides a message processing method, a device, an electronic device, a storage medium and a vehicle, which break through the limitation of mutual exclusion lock and improve CAN communication efficiency and performance.
In order to achieve the above object, the technical solution provided by the embodiments of the present disclosure is as follows:
in a first aspect, the present disclosure provides a method for processing a message, where the method includes:
responding to a message read-write instruction, acquiring an enqueue position identifier, an dequeue position identifier and a maximum readable position identifier of a buffer queue, wherein the message read-write instruction indicates to execute the operation of writing or reading message data for the buffer queue;
Comparing the enqueue position identifier, the dequeue position identifier and the maximum readable position identifier to obtain the space occupation condition of the buffer queue, wherein the space occupation condition comprises: the space is available completely, the space part is available, and the space is not available;
When the space occupation condition of the buffer queue is a target condition, executing the operation of writing or reading the message data aiming at the position indicated by the target position mark;
when the message read-write instruction indicates to execute the operation of writing the message data aiming at the buffer queue, and the target situation is that the space is fully available or the space is partially available, the target position mark is the enqueue position mark; or when the message read-write instruction indicates that the operation of reading the message data is executed aiming at the buffer queue, and the target position mark is the dequeue position mark when the target condition is that the space part is available or the space is not available.
As an optional implementation manner of the embodiment of the present disclosure, comparing the enqueue position identifier, the dequeue position identifier and the maximum readable position identifier to obtain a space occupation condition of the buffer queue includes:
If the dequeue position identifier is equal to the maximum readable position identifier, determining that the space occupation condition of the buffer queue is that the space is completely available;
If the dequeue position identifier is not equal to the maximum readable position identifier and the dequeue position identifier is added with the equivalent dequeue position identifier, determining that the space occupation condition of the buffer queue is that no space remains available;
If the dequeue location identifier is not equal to the maximum readable location identifier and the enqueue location identifier is added with a dequeue location identifier, determining that the space occupation condition of the buffer queue is that the space is available.
As an optional implementation manner of the embodiment of the present disclosure, when the message read-write instruction indicates that an operation of reading message data is performed for the buffer queue, and the target position identifier is a dequeue position identifier when the target condition is that a space portion is available or that no space remains available;
When the space occupation condition of the buffer queue is a target condition, performing operations of writing or reading message data aiming at the position indicated by the target position mark, including:
when the space occupation condition of the buffer queue is that the space is available or the space is not available, comparing the enqueue position mark with the maximum readable position mark;
And if the enqueue position identification is equal to the maximum readable position identification, reading the message data from the dequeue position indicated by the dequeue position identification.
As an optional implementation manner of the embodiment of the present disclosure, after comparing the enqueue location identifier and the maximum readable location identifier when the space occupation condition of the buffer queue is that the space is partially available or that the space is not available, the method further includes:
if the enqueue position identification is not equal to the maximum readable position identification, determining that the enqueue position indicated by the enqueue position identification waits for writing the message data or is writing the message data;
After the message data is written into the column position, the message data is read from the column position indicated by the column position identification.
As an optional implementation manner of the embodiment of the present disclosure, when the message read-write instruction indicates that an operation of writing message data is performed for the buffer queue, and the target position identifier is an enqueue position identifier when the target condition is that the space is fully available or a space portion is available;
When the space occupation condition of the buffer queue is the target condition, after the operation of writing or reading the message data is executed aiming at the position indicated by the target position mark, the method further comprises the following steps:
and adding one to the maximum readable position mark to update the maximum readable position mark.
As an optional implementation manner of the embodiment of the present disclosure, when the message read-write instruction indicates that an operation of reading message data is performed for the buffer queue, and the target position identifier is a dequeue position identifier when the target condition is that a space portion is available or that no space remains available;
When the space occupation condition of the buffer queue is the target condition, after the operation of writing or reading the message data is executed aiming at the position indicated by the target position mark, the method further comprises the following steps:
and sending the message data to a bus to perform bus communication by using the buffer queue.
In a second aspect, the present disclosure provides a message processing apparatus, including:
the acquisition module is used for responding to a message read-write instruction, acquiring an enqueue position identifier, a dequeue position identifier and a maximum readable position identifier of the buffer queue, wherein the message read-write instruction indicates the operation of writing or reading message data to the buffer queue;
the comparison module is used for comparing the enqueue position identifier, the dequeue position identifier and the maximum readable position identifier to obtain the space occupation condition of the buffer queue, wherein the space occupation condition comprises: the space is available completely, the space part is available, and the space is not available;
The read-write module is used for executing the operation of writing or reading the message data aiming at the position indicated by the target position mark when the space occupation condition of the buffer queue is the target condition;
when the message read-write instruction indicates to execute the operation of writing the message data aiming at the buffer queue, and the target situation is that the space is fully available or the space is partially available, the target position mark is the enqueue position mark; or when the message read-write instruction indicates that the operation of reading the message data is executed aiming at the buffer queue, and the target position mark is the dequeue position mark when the target condition is that the space part is available or the space is not available.
As an optional implementation manner of the embodiment of the present disclosure, the comparing module is specifically configured to determine that the space occupation condition of the buffer queue is that all the space is available if the dequeue location identifier is equal to the maximum readable location identifier;
If the dequeue position identifier is not equal to the maximum readable position identifier and the dequeue position identifier is added with the equivalent dequeue position identifier, determining that the space occupation condition of the buffer queue is that no space remains available;
If the dequeue location identifier is not equal to the maximum readable location identifier and the enqueue location identifier is added with a dequeue location identifier, determining that the space occupation condition of the buffer queue is that the space is available.
As an optional implementation manner of the embodiment of the present disclosure, when the message read-write instruction indicates that an operation of reading message data is performed for the buffer queue, and the target position identifier is a dequeue position identifier when the target condition is that a space portion is available or that no space remains available;
The read-write module is specifically configured to compare the enqueue position identifier with the maximum readable position identifier when the space occupation condition of the buffer queue is that the space is partially available or that the space is not available;
And if the enqueue position identification is equal to the maximum readable position identification, reading the message data from the dequeue position indicated by the dequeue position identification.
As an optional implementation manner of the embodiment of the present disclosure, when the space occupation condition of the buffer queue is that a space portion is available or that no space remains available, the read-write module is further configured to compare the enqueue location identifier with the maximum readable location identifier, and if the enqueue location identifier is not equal to the maximum readable location identifier, determine that the enqueue location indicated by the enqueue location identifier waits for writing the message data, or is writing the message data;
After the message data is written into the column position, the message data is read from the column position indicated by the column position identification.
As an optional implementation manner of the embodiment of the present disclosure, when the message read-write instruction indicates that an operation of writing message data is performed for the buffer queue, and the target position identifier is an enqueue position identifier when the target condition is that the space is fully available or a space portion is available;
and the read-write module is also used for adding one to the maximum readable position mark to update the maximum readable position mark after the operation of writing or reading the message data is executed aiming at the position indicated by the target position mark when the space occupation condition of the buffer queue is the target condition.
As an optional implementation manner of the embodiment of the present disclosure, when the message read-write instruction indicates that an operation of reading message data is performed for the buffer queue, and the target position identifier is a dequeue position identifier when the target condition is that a space portion is available or that no space remains available;
and the read-write module is also used for sending the message data to a bus after executing the operation of writing or reading the message data aiming at the position indicated by the target position mark when the space occupation condition of the buffer queue is the target condition so as to utilize the buffer queue to carry out bus communication.
In a third aspect, the present disclosure provides an electronic device comprising: a processor, a memory and a computer program stored on the memory and executable on the processor, which when executed by the processor implements the message processing method according to the first aspect or any of its alternative embodiments.
In a fourth aspect, the present disclosure provides a computer-readable storage medium comprising: the computer readable storage medium stores thereon a computer program implementing the message processing method according to the first aspect or any optional implementation manner thereof.
In a fifth aspect, the present disclosure provides a vehicle comprising a message processing apparatus according to the second aspect or any one of its alternative embodiments; or an electronic device as described in the third aspect.
In a sixth aspect, the present disclosure provides a computer program product comprising: the computer program product comprises a computer program for implementing the message processing method according to the first aspect or any of its alternative embodiments when said computer program is run on a computer.
Compared with the prior art, the technical scheme provided by the embodiment of the disclosure has the following advantages:
The method for processing the message includes the steps that an enqueue position identifier, an dequeue position identifier and a maximum readable position identifier in a buffer queue are obtained in response to a message read-write instruction, the space occupation condition of the buffer queue is determined through comparison of the enqueue position identifier, the dequeue position identifier and the maximum readable position identifier, and in combination with the instruction of the message read-write instruction, message data are written into the buffer queue when the message read-write instruction indicates that the buffer queue has the residual available space, and the message data are written into the enqueue position indicated by the enqueue position identifier when the space occupation condition of the buffer queue is that the residual available space exists; and reading the message data from the dequeue position indicated by the dequeue position identification under the condition that the message read-write instruction indicates reading the message data from the buffer queue and the space occupation condition of the buffer queue is that the residual available space exists or the residual available space does not exist. The limitation of the mutual exclusion lock is broken through, whether the buffer queue is readable or writable is judged through the enqueue position identification, the dequeue position identification and the maximum readable position identification in the buffer queue, so that message data is written in the position indicated by the enqueue position identification or read from the position indicated by the dequeue position, and the CAN communication efficiency and performance are improved.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the disclosure and together with the description, serve to explain the principles of the disclosure.
In order to more clearly illustrate the embodiments of the present disclosure or the solutions in the prior art, the drawings that are required for the description of the embodiments or the prior art will be briefly described below, and it will be obvious to those skilled in the art that other drawings can be obtained from these drawings without inventive effort.
Fig. 1 is a flow chart of a message processing method according to an embodiment of the disclosure;
FIG. 2 is a schematic diagram of a data structure of a buffer queue according to an embodiment of the disclosure;
Fig. 3 is a schematic structural diagram of a message processing apparatus according to an embodiment of the present disclosure;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the disclosure.
Detailed Description
In order that the above objects, features and advantages of the present disclosure may be more clearly understood, a further description of aspects of the present disclosure will be provided below. It should be noted that, without conflict, the embodiments of the present disclosure and features in the embodiments may be combined with each other.
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present disclosure, but the present disclosure may be practiced otherwise than as described herein; it will be apparent that the embodiments in the specification are only some, but not all, embodiments of the disclosure.
In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the technical terms required to be used in the description of the embodiments or the prior art will be briefly described as follows:
In the programming, the concept of the object mutual exclusion lock is introduced to ensure the integrity of the shared data operation. Each object corresponds to a tag, which may be referred to as a "mutex lock," that is used to ensure that only one thread can access the object at any one time. The exclusive lock ensures that the shared resource is accessed by only one thread at any time, and when one thread is locked, the other threads fail to be locked. The mutex lock failure thread blocking is implemented by the operating system kernel. When the locking fails, the kernel sets the thread into a sleep state, and after the lock is released, the kernel wakes the thread at a proper time, and after the thread acquires the lock, the thread can continue to execute. Therefore, when the mutex lock fails, the user mode is trapped into the kernel mode, so that the kernel switches threads, and the cost of twice thread context switching exists.
Context switch refers to the kernel layer of the operating system performing the following activities on the central processor: (1) Suspending a process, and storing the context of the process in the CPU in a memory; (2) Retrieving the context of the next process in memory and restoring it in the registers of the CPU; (3) Jump to the location pointed to by the program counter to resume the process. It is understood that a context switch is a process in which the kernel suspends the current execution of the CPU and then continues to execute one of the many processes previously suspended. Frequent context switching can cause excessive loss to system performance.
Compare and swap (CAS), which is a kind of atomic operation, is used to implement uninterrupted data swap operations in multi-threaded programming, so as to avoid the problem of data inconsistency caused by uncertainty of execution sequence and unpredictability of interrupt when multiple threads rewrite certain data at the same time. This operation replaces the data in the memory with a new value when the value is the same by comparing the value in the memory with the specified data. The CAS operation includes three operands, memory location (V), expected original value (A), and new value (B). If the value of the memory location matches the expected original value, the processor automatically updates the location value to a new value. Otherwise, the processor does nothing.
In the related art, data in the CAN communication process is buffered by using a mode of adding a mutual exclusion lock to a buffer queue, specifically, if the data needs to be written into the buffer queue, a thread is called to acquire the mutual exclusion lock first, and whether acquisition is successful is judged; and under the condition that the acquisition is successful, the data can be written into the buffer queue, so that the mutual exclusion lock is released, and under the condition that the mutual exclusion lock is not successfully acquired, the current thread reenters the buffer queue and is rescheduled after waiting for the mutual exclusion lock to be successfully acquired. The data volume transmitted in the actual CAN communication of the vehicle is large, and once the mutual exclusion lock is not successfully acquired, the vehicle needs to reenter the buffer queue to wait, which CAN cause the buffer queue to be blocked, cause frequent switching of thread context, cause performance loss and influence the communication efficiency of the CAN communication.
In order to solve the above technical problems, an embodiment of the disclosure provides a method, an apparatus, an electronic device, a storage medium, and a vehicle for implementing message processing, where the method for implementing message processing first responds to a message read-write instruction, and obtains an enqueue position identifier, a dequeue position identifier, and a maximum readable position identifier of a buffer queue, where the message read-write instruction may indicate writing of message data into the buffer queue, or indicate reading of message data from the buffer queue, and then compares the enqueue position identifier, dequeue position identifier, and maximum readable position identifier to determine whether a space occupation condition of the buffer queue is empty, or there is a remaining available space, or there is no remaining available space, so as to implement a judgment on the space occupation condition of the buffer queue, so as to determine whether the buffer queue is readable or writable. Further, when the message read-write instruction indicates to write message data into the buffer queue and the space occupation condition of the buffer queue is that the residual available space exists, writing the message data into the enqueuing position indicated by the enqueuing position identification; and reading the message data from the dequeue position indicated by the dequeue position identification under the condition that the message read-write instruction indicates reading the message data from the buffer queue and the space occupation condition of the buffer queue is that the residual available space exists or no residual available space exists. The method CAN meet the requirement of larger data throughput of CAN communication, reduce performance loss and improve the communication efficiency of CAN communication.
It should be noted that, the protection scope of the message processing method according to the embodiments of the present disclosure is not limited to the order of execution of the steps listed in the embodiments, and all the schemes implemented by adding or removing steps and replacing steps according to the prior art according to the principles of the present disclosure are included in the protection scope of the present disclosure.
As shown in fig. 1, fig. 1 is a flow chart of a message processing method according to an embodiment of the disclosure, where the method may be applied to a central processor of a vehicle control system, and the disclosure is not limited thereto in detail. The message processing method comprises the following steps S101 to S103:
S101, responding to a message read-write instruction, and acquiring an enqueue position identifier, a dequeue position identifier and a maximum readable position identifier of a buffer queue.
The message read-write instruction is generated by the central processing unit and is used for executing the operation of writing or reading the message data aiming at the buffer queue. The message read-write instruction is used for indicating to write message data into the buffer queue or indicating to read message data from the buffer queue. The message read-write instruction is specifically used for indicating reading or writing, and can be distinguished according to the flag bit in the message read-write instruction. For example, if the flag is at the position 1, the message read-write instruction is used for indicating to write the message data into the buffer queue; and the mark position 0 is used for indicating the reading of the message data from the buffer queue by the message read-write instruction.
The message data is generated according to actual operation of the vehicle control system, such as a work log, etc., which is not limited by the present disclosure.
In some embodiments, in response to a message read-write instruction, indicating that writing or reading of message data is expected to be performed on a buffer queue, the embodiment of the present disclosure obtains an enqueue position identifier, an dequeue position identifier, and a maximum readable position identifier of the buffer queue of a memory, where the enqueue position identifier is used to identify when new message data is written into the buffer queue, and an array position index for storing the message data by using an array may be marked as writeIndex; the dequeue position mark is used for marking the array position index of the next read message data in the buffer queue and can be marked as readIndex; the maximum readable location identifier is a maximum array location index value for identifying readable message data in the buffer queue, which is incremented by one and can be denoted maximumReadIndex.
As shown in fig. 2, exemplary, fig. 2 is a schematic data structure of a buffer queue in an embodiment of the present disclosure, and reads a subscript of the buffer queue in response to a message read-write command to obtain an enqueue location identifier, an dequeue location identifier, and a maximum readable location identifier, where an array 201, 204, 205 does not store message data, an array 202 and an array 203 already store message data, and the dequeue location identifier points to the array 202, which indicates that the next message data read from the buffer queue is the message data stored in the array 202; the enqueue location identifier points to the array 204, indicating that new message data is to be written to the array 204; the maximum readable location identifier points to array 205, indicating that the maximum array of current readable message data for the buffer queue is array 204.
Further, S102 is performed. To determine whether to perform a read or write operation.
S102, comparing the enqueue position identification, the dequeue position identification and the maximum readable position identification to obtain the space occupation condition of the buffer queue.
Wherein, the space occupation condition includes: the space is available entirely, the space is available partially, and no space remains available. All available space indicates that all arrays in the buffer queue do not store message data; the space occupation condition is that the space is partially available, which indicates that an array capable of executing writing operation exists in the buffer queue, and the space occupation condition is that the space is not available, which indicates that message data is stored in each array in the buffer queue, and the buffer queue is full.
In some embodiments, after the enqueue position identifier, the dequeue position identifier and the maximum readable position identifier of the buffer queue are obtained, the space occupation condition of the buffer queue can be directly judged according to the three position identifiers, and if the dequeue position identifier is equal to the maximum readable position identifier, the space occupation condition of the buffer queue is determined to be that the space is fully available; if the dequeue position identifier is not equal to the maximum readable position identifier and the dequeue position identifier is added with the equivalent dequeue position identifier, determining that the space occupation condition of the buffer queue is that no space remains available; if the dequeue location identifier is not equal to the maximum readable location identifier and the enqueue location identifier is added with a dequeue location identifier, determining that the space occupation condition of the buffer queue is that the space is available.
In some embodiments, in the case where the message read-write instruction indicates writing of the message data into the buffer queue, it is necessary to determine whether the buffer queue can write the message data, optionally, the embodiments of the present disclosure provide an implementation manner, compare whether the dequeue location identifier is equal to the maximum readable location identifier, and if the dequeue location identifier is equal to the maximum readable location identifier, determine that the space occupation condition of the buffer queue is all available, and further determine that the buffer queue can write the message data; if the dequeue position identifier is not equal to the maximum readable position identifier, further judging whether the enqueue position identifier is added with a dequeue position identifier or not, if the enqueue position identifier is added with a dequeue position identifier, determining that the space occupation condition of the buffer queue is available as a space part, and determining that the buffer queue can write message data.
In some embodiments, in the case where the message read-write instruction indicates that the message data is read from the buffer queue, it is necessary to determine whether the buffer queue has the message data, and optionally, the embodiments of the present disclosure provide an implementation manner, where whether the dequeue location identifier is equal to the maximum readable location identifier is compared, and if the dequeue location identifier is not equal to the maximum readable location identifier, it is determined that the space occupation condition of the buffer queue is that a space portion is available or that no space remains available, and it is understood that an array of the buffer queue has the message data stored therein and is readable.
And S103, when the space occupation condition of the buffer queue is the target condition, executing the operation of writing or reading the message data aiming at the position indicated by the target position mark.
According to the different message read-write instructions and different target conditions, different target position identifiers are corresponding. When the message read-write instruction indicates to execute the operation of writing the message data aiming at the buffer queue, and the target position mark is the enqueue position mark when the target condition is that the space is fully available or the space is partially available; and executing operation of reading message data aiming at the buffer queue in the message read-write instruction, wherein the target condition is that the space is available partially or that the space is not available left, and the target position identifier is the dequeue position identifier.
The following will describe the process of writing the message data into the buffer queue and the process of reading the message data from the buffer queue according to the difference of the target position identifiers:
(1) The target position mark is an inline position mark
In some embodiments, when the message read-write instruction indicates writing the message data into the buffer queue, and the space occupation condition of the buffer queue is empty or there is a remaining available space, it indicates that there is an array in the buffer queue where the message data is not stored, and the writing operation may be performed, where the target location identifier is a enqueue location identifier, and writing the message data into the enqueue location indicated by the enqueue location identifier.
Optionally, after writing the message data to the enqueue position indicated by the enqueue position identifier, updating the maximum readable position identifier of the buffer queue, where the new maximum readable position identifier is equal to the enqueue position identifier plus one.
If the message read-write instruction indicates to write the message data into the buffer queue, but the space occupation condition of the buffer queue is that no space is left, the new enqueue position identifier is obtained again, and according to the comparison between the new enqueue position identifier and the dequeue position identifier as well as the maximum readable position identifier, whether the message data can be written into the enqueue position indicated by the new enqueue position identifier is judged, and in the process, the thread does not trigger the context switch.
(2) The target location identifier is a dequeue location identifier
In some embodiments, when the message read-write instruction indicates that the message data is read from the buffer queue, and the space occupation condition of the buffer queue is that there is remaining available space or no remaining available space, it indicates that there is an array in the buffer queue in which the message data has been stored, a read operation may be performed, the target location identifier is a dequeue location identifier, and the message data is read from a dequeue location indicated by the dequeue location identifier.
In some embodiments, when a message read/write instruction indicates that message data is read from a buffer queue and a space occupation condition of the buffer queue is that there is a remaining available space or no remaining available space, a conflict is prevented from occurring in a multi-thread parallel read/write buffer queue.
And if the enqueue position identification is equal to the maximum readable position identification, indicating that no other threads currently write message data into the enqueue position indicated by the enqueue position identification of the buffer queue, allowing the current thread to read the message data from the dequeue position indicated by the dequeue position identification.
If the enqueue position identifier is not equal to the maximum readable position identifier, it indicates that other threads currently exist to write message data to the enqueue position indicated by the enqueue position identifier of the buffer queue, or indicates that other threads currently exist to apply for the enqueue position indicated by the enqueue position identifier, and waits for writing the message data to the enqueue position, it can be understood that the enqueue position identifier is not equal to the maximum readable position identifier, it indicates that the buffer queue currently exists incompletely written message data, and if the current threads need to read the message data from the dequeue position indicated by the dequeue position identifier, it is necessary to wait for other threads to completely write the message data to the buffer queue, so as to avoid thread scheduling conflict and keep the consistency of the data. After the message data is written into the column position, reading the message data from the column position indicated by the column position identification is determined.
In some embodiments, after reading the message data from the dequeue location indicated by the dequeue location identification, the message data is sent onto the bus for bus communication using the buffer queue.
In summary, an embodiment of the present disclosure provides a method for processing a message, where first, in response to a message read-write instruction, an enqueue position identifier, an dequeue position identifier, and a maximum readable position identifier in a buffer queue are obtained, by comparing the enqueue position identifier, the dequeue position identifier, and the maximum readable position identifier, a space occupation condition of the buffer queue is determined, and in combination with an instruction of the message read-write instruction, when the message read-write instruction instructs to write message data into the buffer queue, and when the space occupation condition of the buffer queue is that there is remaining available space, the message data is written into the enqueue position indicated by the enqueue position identifier; and reading the message data from the dequeue position indicated by the dequeue position identification under the condition that the message read-write instruction indicates reading the message data from the buffer queue and the space occupation condition of the buffer queue is that the residual available space exists or the residual available space does not exist. The limitation of the mutual exclusion lock is broken through, whether the buffer queue is readable or writable or not is judged based on the CAS mechanism, the enqueue position identification, the dequeue position identification and the maximum readable position identification in the buffer queue, so that message data is written in the position indicated by the enqueue position identification or read from the position indicated by the dequeue position, CAN communication efficiency is improved, and system loss for CAN communication based on the mutual exclusion lock is reduced.
As shown in fig. 3, fig. 3 is a schematic structural diagram of a message processing apparatus according to an embodiment of the present disclosure, where the message processing apparatus includes:
The obtaining module 301 is configured to obtain, in response to a message read-write instruction, an enqueue position identifier, an dequeue position identifier, and a maximum readable position identifier of the buffer queue, where the message read-write instruction indicates an operation of writing or reading message data to the buffer queue;
the comparing module 302 is configured to compare the enqueue location identifier, the dequeue location identifier, and the maximum readable location identifier, so as to obtain a space occupation situation of the buffer queue, where the space occupation situation includes: the space is available completely, the space part is available, and the space is not available;
the read-write module 303 is configured to perform an operation of writing or reading the message data with respect to the location indicated by the target location identifier when the space occupation condition of the buffer queue is the target condition;
The message read-write instruction instructs to execute the operation of writing the message data aiming at the buffer queue, wherein the target condition is that the space is fully available or the space is partially available, and the target position mark is the enqueue position mark; or the message read-write instruction indicates to execute the operation of reading the message data aiming at the buffer queue, the target condition is that the space is available partially or the space is not available left, and the target position identifier is the dequeue position identifier.
In some embodiments, the comparing module 302 is specifically configured to determine that the space occupation condition of the buffer queue is that the space is completely available if the dequeue location identifier is equal to the maximum readable location identifier;
If the dequeue position identifier is not equal to the maximum readable position identifier and the dequeue position identifier is added with the equivalent dequeue position identifier, determining that the space occupation condition of the buffer queue is that no space remains available;
If the dequeue location identifier is not equal to the maximum readable location identifier and the enqueue location identifier is added with a dequeue location identifier, determining that the space occupation condition of the buffer queue is that the space is available.
In some embodiments, the message read-write instruction instructs to perform an operation of reading the message data for the buffer queue, where the target condition is that a space portion is available or that no space remains available, and the target location identifier is an dequeue location identifier;
The read-write module 303 is specifically configured to compare the enqueue location identifier with the maximum readable location identifier when the space occupation condition of the buffer queue is that the space is partially available or that no space remains available;
And if the enqueue position identification is equal to the maximum readable position identification, reading the message data from the dequeue position indicated by the dequeue position identification.
In some embodiments, the read-write module 303 is further configured to determine that the enqueue position indicated by the enqueue position identifier waits for writing the message data or is writing the message data if the enqueue position identifier is not equal to the maximum readable position identifier after comparing the enqueue position identifier with the maximum readable position identifier when the space occupation condition of the buffer queue is that the space portion is available or that no space remains available;
After the message data is written into the column position, the message data is read from the column position indicated by the column position identification.
In some embodiments, the message read-write instruction instructs to perform an operation of writing the message data with respect to the buffer queue, where the target condition is that all space is available or a portion of space is available, and the target location identifier is an enqueue location identifier;
The read-write module 303 is further configured to add one to the maximum readable location identifier to update the maximum readable location identifier after performing the operation of writing or reading the message data with respect to the location indicated by the target location identifier when the space occupation condition of the buffer queue is the target condition.
In some embodiments, the message read-write instruction instructs to perform an operation of reading the message data for the buffer queue, where the target condition is that a space portion is available or that no space remains available, and the target location identifier is an dequeue location identifier;
The read-write module 303 is further configured to send the message data to the bus after performing the operation of writing or reading the message data with respect to the location indicated by the target location identifier when the space occupation condition of the buffer queue is the target condition, so as to use the buffer queue to perform bus communication.
As shown in fig. 4, fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure, where the electronic device includes: the system comprises a processor 401, a memory 402 and a computer program stored in the memory 402 and capable of running on the processor 401, wherein the computer program realizes each process of the message processing method in the method embodiment when being executed by the processor, and can achieve the same technical effect, and for avoiding repetition, the description is omitted herein.
The embodiments of the present disclosure provide a computer readable storage medium, on which a computer program is stored, where the computer program is executed by each process of the message processing method in the foregoing method embodiment, and the same technical effects can be achieved, so that repetition is avoided, and no further description is given here.
The computer readable storage medium may be a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk.
The embodiments of the present disclosure provide a computer program product, where the computer program product stores a computer program, and the computer program is executed by the processor to implement each process of the message processing method in the embodiment of the method, and achieve the same technical effects, so that repetition is avoided, and no further description is given here.
Embodiments of the present disclosure provide a vehicle including: a message processing device as described above; or an electronic device as described above. The vehicle is used for executing each process of the message processing method in the above method embodiment provided by any embodiment of the disclosure, and can achieve the same technical effects, and for avoiding repetition, the description is omitted here.
It will be appreciated by those skilled in the art that embodiments of the present disclosure may be provided as a method, system, or computer program product. Accordingly, the present disclosure may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present disclosure may take the form of a computer program product embodied on one or more computer-usable storage media having computer-usable program code embodied therein.
In the several embodiments provided in the present disclosure, it should be understood that the disclosed apparatus and method may be implemented in other manners. The apparatus embodiments described above are merely illustrative, for example, flow diagrams and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In this disclosure, the Processor may be a central processing unit (Central Processing Unit, CPU), but may also be other general purpose processors, digital signal processors (DIGITAL SIGNAL Processor, DSP), application SPECIFIC INTEGRATED Circuit (ASIC), off-the-shelf Programmable gate array (Field-Programmable GATE ARRAY, FPGA) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
In the present disclosure, memory may include volatile memory, random Access Memory (RAM), and/or nonvolatile memory, such as Read Only Memory (ROM) or flash RAM, in a computer readable medium. Memory is an example of a computer-readable medium.
In the present disclosure, computer readable media include both permanent and non-permanent, removable and non-removable storage media. Storage media may embody any method or technology for storage of information, which may be computer readable instructions, data structures, program modules, or other data. Examples of storage media for a computer include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Disks (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium which can be used to store information that can be accessed by a computing device. Computer-readable media, as defined herein, does not include transitory computer-readable media (transmission media), such as modulated data signals and carrier waves.
It should be noted that in this document, relational terms such as "first" and "second" and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The above is merely a specific embodiment of the disclosure to enable one skilled in the art to understand or practice the disclosure. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the disclosure. Thus, the present disclosure is not intended 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 (10)
1. A method for processing a message, comprising:
Responding to a message read-write instruction, acquiring an enqueue position identifier, an dequeue position identifier and a maximum readable position identifier of a buffer queue, wherein the message read-write instruction indicates an operation of writing or reading message data to the buffer queue;
Comparing the enqueue position identifier, the dequeue position identifier and the maximum readable position identifier to obtain a space occupation condition of the buffer queue, wherein the space occupation condition comprises: the space is available completely, the space part is available, and the space is not available;
when the space occupation condition of the buffer queue is a target condition, executing the operation of writing or reading the message data aiming at the position indicated by the target position mark;
When the message read-write instruction indicates that the operation of writing message data is executed for the buffer queue, and the target situation is that the space is available entirely or the space is available partially, the target position identifier is an enqueue position identifier; or when the message read-write instruction indicates that the operation of reading the message data is executed for the buffer queue, and the target position identifier is a dequeue position identifier when the target condition is that a space part is available or no space is available.
2. The method of claim 1, wherein the comparing the in-column location identifier, the out-column location identifier, and the maximum readable location identifier to obtain the space occupation status of the buffer queue comprises:
If the dequeue position identifier is equal to the maximum readable position identifier, determining that the space occupation condition of the buffer queue is that the space is fully available;
if the dequeue position identifier is not equal to the maximum readable position identifier and the enqueue position identifier is added with one equal to the dequeue position identifier, determining that the space occupation condition of the buffer queue is that space is not available;
And if the dequeue position identifier is not equal to the maximum readable position identifier and the enqueue position identifier is added with a value which is not equal to the dequeue position identifier, determining that the space occupation condition of the buffer queue is available as a space part.
3. The method of claim 1, wherein the target location identifier is a dequeue location identifier when the message read-write instruction indicates that the operation of reading message data is performed for the buffer queue, the target condition is that space is partially available or that no space remains available;
And when the space occupation condition of the buffer queue is a target condition, performing operations of writing or reading message data according to the position indicated by the target position identifier, including:
When the space occupation condition of the buffer queue is that the space is available or the space is not available, comparing the enqueue position identification with the maximum readable position identification;
and if the enqueue position identifier is equal to the maximum readable position identifier, reading the message data from the dequeue position indicated by the dequeue position identifier.
4. The method of claim 3, wherein after comparing the enqueue location identity and the maximum readable location identity when the buffer queue space occupation is that space is partially available or no space remains available, the method further comprises:
if the enqueue position identifier is not equal to the maximum readable position identifier, determining that the enqueue position indicated by the enqueue position identifier waits for writing message data or is writing the message data; and after the enqueue position identifier is equal to the maximum readable position identifier and the message data is indicated to be written into the enqueue position, reading the message data from the dequeue position indicated by the dequeue position identifier.
5. The method of claim 1, wherein the target location identifier is a enqueue location identifier when the message read-write instruction indicates that an operation to write message data is performed for the buffer queue, the target condition is that space is fully available or a portion of space is available;
When the space occupation condition of the buffer queue is a target condition, after performing the operation of writing or reading the message data aiming at the position indicated by the target position mark, the method further comprises:
And adding one to the maximum readable position mark to update the maximum readable position mark.
6. The method of claim 1, wherein the target location identifier is a dequeue location identifier when the message read-write instruction indicates that the operation of reading message data is performed for the buffer queue, the target condition is that space is partially available or that no space remains available;
When the space occupation condition of the buffer queue is a target condition, after performing the operation of writing or reading the message data aiming at the position indicated by the target position mark, the method further comprises:
And sending the message data to a bus to perform bus communication by using the buffer queue.
7. A message processing apparatus, comprising:
the system comprises an acquisition module, a buffer queue, a message reading and writing module and a message reading and writing module, wherein the acquisition module is used for responding to a message reading and writing instruction, acquiring an enqueue position identifier, a dequeue position identifier and a maximum readable position identifier of the buffer queue, and the message reading and writing instruction indicates the operation of writing or reading message data to the buffer queue;
the comparison module is configured to compare the enqueue position identifier, the dequeue position identifier, and the maximum readable position identifier, so as to obtain a space occupation condition of the buffer queue, where the space occupation condition includes: the space is available completely, the space part is available, and the space is not available;
the read-write module is used for executing the operation of writing or reading the message data aiming at the position indicated by the target position mark when the space occupation condition of the buffer queue is the target condition;
When the message read-write instruction indicates that the operation of writing message data is executed for the buffer queue, and the target situation is that the space is available entirely or the space is available partially, the target position identifier is an enqueue position identifier; or when the message read-write instruction indicates that the operation of reading the message data is executed for the buffer queue, and the target position identifier is a dequeue position identifier when the target condition is that a space part is available or no space is available.
8. An electronic device, comprising: a processor, a memory and a computer program stored on the memory and executable on the processor, which when executed by the processor implements the message processing method according to any of claims 1 to 6.
9. A computer-readable storage medium, comprising: the computer readable storage medium stores thereon a computer program which, when executed by a processor, implements the message processing method according to any of claims 1 to 6.
10. A vehicle, characterized by comprising:
a message processing apparatus as claimed in claim 7 or an electronic device as claimed in claim 8.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211574992.XA CN118174980A (en) | 2022-12-08 | 2022-12-08 | Message processing method and device, electronic equipment, storage medium and vehicle |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211574992.XA CN118174980A (en) | 2022-12-08 | 2022-12-08 | Message processing method and device, electronic equipment, storage medium and vehicle |
Publications (1)
Publication Number | Publication Date |
---|---|
CN118174980A true CN118174980A (en) | 2024-06-11 |
Family
ID=91357402
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211574992.XA Pending CN118174980A (en) | 2022-12-08 | 2022-12-08 | Message processing method and device, electronic equipment, storage medium and vehicle |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN118174980A (en) |
-
2022
- 2022-12-08 CN CN202211574992.XA patent/CN118174980A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US9798595B2 (en) | Transparent user mode scheduling on traditional threading systems | |
US9396353B2 (en) | Data allocation among devices with different data rates | |
US20140122849A1 (en) | Apparatus and method for handling exception events | |
US9213562B2 (en) | Garbage collection safepoint system using non-blocking asynchronous I/O call to copy data when the garbage collection safepoint is not in progress or is completed | |
EP3462324B1 (en) | Pointers in a memory managed system | |
JPS5983249A (en) | Control of queue | |
US10535368B1 (en) | Reader bias based locking technique enabling high read concurrency for read-mostly workloads | |
CN110727675A (en) | Method and device for processing linked list | |
CN114265670B (en) | Memory block sorting method, medium and computing device | |
US10198365B2 (en) | Information processing system, method and medium | |
CN114168271B (en) | Task scheduling method, electronic device and storage medium | |
CN105550029A (en) | Process scheduling method and device | |
CN104461730A (en) | Virtual resource allocation method and device | |
JP4342554B2 (en) | Low contention lock | |
US7334229B1 (en) | Mutual exclusion at the record level with priority inheritance for embedded systems using one semaphore | |
US7281100B2 (en) | Data processing system and method | |
CN118174980A (en) | Message processing method and device, electronic equipment, storage medium and vehicle | |
CN109558249B (en) | Control method and device for concurrent operation | |
US9135058B2 (en) | Method for managing tasks in a microprocessor or in a microprocessor assembly | |
CN110874273B (en) | Data processing method and device | |
CN109614218B (en) | Semiconductor device with a semiconductor layer having a plurality of semiconductor layers | |
CN113253925B (en) | Method and device for optimizing read-write performance | |
CN114675968A (en) | Thread running method, system and device and readable storage medium | |
JP2007133604A (en) | Computer system, operational state determination program and operational state determination method | |
JP2010026575A (en) | Scheduling method, scheduling device, and multiprocessor system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |