Data processing method, device and equipment for shared memory and medium

By using write index values ​​to lock the storage block of data to be written in shared memory, the problem of multiple data publishers writing data at the same time is solved, and efficient data writing and reading operations are achieved.

CN115437798BActive Publication Date: 2026-03-17BEIJING CHJ AUTOMOTIVE TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-06-23
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

In existing technologies, it is difficult for multiple data publishers to write data to shared memory simultaneously, resulting in low data writing efficiency.

Method used

By using write index values ​​to record the location of storage blocks in shared memory where data is being written in real time, the storage block containing the data to be written is locked, while other storage blocks remain open, allowing multiple data publishers to write data simultaneously.

Benefits of technology

It enables multiple data publishers to write data simultaneously in shared memory, improving data writing efficiency and avoiding data inconsistency issues.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115437798B_ABST
    Figure CN115437798B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a data processing method, device and equipment and medium for sharing memory; wherein the method comprises: receiving a write operation request of target data, the write operation request being used to request writing the target data into the shared memory; obtaining a write index value in the shared memory and updating the write index value, the updated write index value being greater than the previous write index value by 1, the write index value being used to lock a storage block of to-be-written data; determining that the storage block corresponding to the updated write index value is a target storage block; and writing the target data into the target storage block. The present disclosure can effectively realize simultaneous writing of multiple data in the shared memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to a data processing method, apparatus, device, and medium for shared memory. Background Technology

[0002] The vehicle control system is based on a service-oriented architecture (SOA), which decomposes different functional services of the application (such as background control services and logging services). The services communicate with each other through interfaces and protocols. Therefore, a reliable and efficient communication mechanism is needed between services to meet the needs of data distribution.

[0003] The Data Distribution Service (DDS) can be used for data distribution. Data publishers can write messages to a topic in shared memory, and subscribers to that topic can read the messages from the shared memory. During data writing, the data publisher needs to lock the shared memory to perform the write operation. Once all data has been written, the next data publisher can then continue writing data to the shared memory.

[0004] Therefore, it is difficult to enable multiple data publishers to write data to shared memory simultaneously. Summary of the Invention

[0005] In order to solve the above-mentioned technical problems, or at least partially solve the above-mentioned technical problems, this disclosure provides a data processing method, apparatus, device and medium for shared memory.

[0006] In a first aspect, this disclosure provides a shared memory data processing method, including:

[0007] Receive a write operation request for target data, the write operation request being used to request that the target data be written to shared memory;

[0008] Obtain the write index value in the shared memory and update the write index value. The updated write index value is 1 greater than the original write index value. The write index value is used to lock the storage block of the data to be written.

[0009] The target storage block is determined to be the storage block corresponding to the updated write index value.

[0010] Write the target data into the target storage block.

[0011] Optionally, the method further includes:

[0012] Receive a read operation request from the target user equipment, the read operation request being used to request the reading of data from the first storage block in the shared memory;

[0013] If the state corresponding to the first storage block is detected to be the first state, then the data in the first storage block is read, wherein the first state is used to indicate that the data has been written to the first storage block;

[0014] After the data in the first storage block is read, a data read message is sent to the target user equipment according to the status of the first storage block. The data read message is used to indicate the reading result of the first storage block.

[0015] Optionally, sending a data read message to the target user equipment according to the state corresponding to the first storage block includes:

[0016] If the state corresponding to the first storage block is detected to be the first state, a first data read message is sent to the target user equipment, and the first data read message includes the data in the first storage block;

[0017] Alternatively, if the state corresponding to the first storage block is detected to be the second state, a second data read message is sent to the target user equipment, the second data read message being used to indicate that the data read in the first storage block has failed;

[0018] The second state is used to indicate that data is being written to the first storage block.

[0019] Optionally, before writing the target data into the target storage block, the method further includes:

[0020] Set the state corresponding to the target storage block to the second state;

[0021] After writing the target data into the target storage block, the process further includes:

[0022] Set the state corresponding to the target storage block to the first state.

[0023] Optionally, after setting the state corresponding to the target storage block to the first state, the method further includes:

[0024] Update the storage index value in the shared memory. The updated storage index value is 1 greater than the original storage index value. The storage index value is used to indicate the storage block in the shared memory that has completed the writing of data.

[0025] Optionally, before determining that the state corresponding to the first storage block is the first state, the method further includes:

[0026] Obtain the read index value corresponding to the target user equipment, wherein the read index value is used to indicate the storage block from which the target user equipment has completed reading data from the shared memory;

[0027] It is determined that the storage index value is greater than the read index value.

[0028] Optionally, after sending the first data read message to the target user equipment, the method further includes:

[0029] An update message for the read index value is sent to the target user equipment. The update message is used to instruct the target user equipment to update the read index value. The updated read index value is 1 greater than the original read index value.

[0030] Optionally, the method further includes:

[0031] A data read message is sent to the target user equipment, the data read message being used to instruct the target user equipment to read data from the shared memory.

[0032] Optionally, writing the target data into the target storage block includes:

[0033] If the target storage block is determined to be the first storage block in the shared memory, and the first storage block already contains data, then the target data is replaced and stored in the first storage block.

[0034] Secondly, this disclosure provides a shared memory data processing apparatus, comprising:

[0035] A receiving module is used to receive a write operation request for target data, wherein the write operation request is used to request that the target data be written to shared memory;

[0036] The acquisition module is used to acquire the write index value in the shared memory and update the write index value. The updated write index value is 1 greater than the original write index value. The write index value is used to lock the storage block of the data to be written.

[0037] The determination module is used to determine the target storage block as the storage block corresponding to the updated write index value.

[0038] The write module is used to write the target data into the target storage block.

[0039] Optionally, it may also include: a reading module and a sending module;

[0040] The receiving module is also configured to receive a read operation request from the target user equipment, wherein the read operation request is used to request to read data from the first storage block in the shared memory;

[0041] The read module is used to read data from the first storage block if the state corresponding to the first storage block is the first state, wherein the first state is used to indicate that data has been written to the first storage block;

[0042] The sending module is configured to send a data read message to the target user equipment according to the status of the first storage block after the data in the first storage block has been read. The data read message is used to indicate the reading result of the first storage block.

[0043] Optional, the sending module, specifically used for:

[0044] If the state corresponding to the first storage block is detected to be the first state, a first data read message is sent to the target user equipment, and the first data read message includes the data in the first storage block;

[0045] Alternatively, if the state corresponding to the first storage block is detected to be the second state, a second data read message is sent to the target user equipment, the second data read message being used to indicate that the data read in the first storage block has failed;

[0046] The second state is used to indicate that data is being written to the first storage block.

[0047] Optionally, it may also include: a settings module;

[0048] The setting module is used to set the state corresponding to the target storage block to the second state;

[0049] The setting module is also used to set the state corresponding to the target storage block to the first state.

[0050] Optionally, it also includes: an update module;

[0051] An update module is used to update the storage index value in the shared memory. The updated storage index value is 1 greater than the original storage index value. The storage index value is used to indicate the storage block in the shared memory that has completed the writing of data.

[0052] Optionally, the acquisition module is further configured to acquire a read index value corresponding to the target user equipment, wherein the read index value is used to indicate the storage block from which the target user equipment has completed reading data from the shared memory;

[0053] The determining module is also used to determine that the storage index value is greater than the read index value.

[0054] Optionally, the sending module is further configured to send an update message for the read index value to the target user equipment, the update message being used to instruct the target user equipment to update the read index value, wherein the updated read index value is 1 greater than the original read index value.

[0055] Optionally, the sending module is further configured to send a data read message to the target user equipment, the data read message being used to instruct the target user equipment to read data from the shared memory.

[0056] Optional, write module, specifically used for:

[0057] If the target storage block is determined to be the first storage block in the shared memory, and the first storage block already contains data, then the target data is replaced and stored in the first storage block.

[0058] Thirdly, this disclosure also provides an electronic device, including:

[0059] One or more processors;

[0060] Storage device for storing one or more programs.

[0061] When the one or more programs are executed by the one or more processors, the one or more processors implement any of the shared memory data processing methods described in the embodiments of the present invention.

[0062] Fourthly, this disclosure also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the shared memory data processing methods described in the embodiments of the present invention.

[0063] Compared with the prior art, the technical solution provided in this disclosure has the following advantages: by using index values ​​to record the storage location of the storage block in the shared memory where data is written, a data publisher does not need to lock the shared memory during the data writing process, so that multiple data publishers can write data simultaneously according to the index values, thereby effectively realizing the simultaneous writing of multiple data in the shared memory. Attached Figure Description

[0064] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.

[0065] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0066] Figure 1 This is a flowchart illustrating a shared memory data processing method provided in an embodiment of this disclosure;

[0067] Figure 2 This is a flowchart illustrating another data processing method for shared memory provided in an embodiment of this disclosure;

[0068] Figure 3 This is a schematic diagram illustrating data writing and data reading according to an embodiment of this disclosure;

[0069] Figure 4 This is a flowchart illustrating another data processing method for shared memory provided in this disclosure embodiment;

[0070] Figure 5 This is a flowchart illustrating yet another shared memory data processing method provided in this disclosure embodiment;

[0071] Figure 6 This is a schematic diagram of the structure of a shared memory data processing device provided in an embodiment of this disclosure;

[0072] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation

[0073] To better understand the above-mentioned objectives, features, and advantages of this disclosure, the solutions disclosed herein will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.

[0074] Numerous specific details are set forth in the following description in order to provide a full understanding of this disclosure, but this disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some, and not all, of the embodiments of this disclosure.

[0075] In vehicle control systems, different functional services of the application (such as background control services and logging services) are broken down. These services communicate with each other through interfaces and protocols, and the information required for communication is stored in shared memory. Data publishers can write messages to shared memory, while data subscribers can read messages from shared memory.

[0076] In existing technologies, when a data publisher writes a message to shared memory, it locks the shared memory and waits for the write operation to complete before opening the shared memory. During this period, other data publishers cannot perform write operations, and data subscribers cannot read data.

[0077] This embodiment locks only the storage block where data is being written to when writing data in shared memory, while leaving other storage blocks open. This allows other data publishers to perform write operations, while data subscribers can also effectively read data. This solves the problem of existing methods struggling to achieve simultaneous writing and reading.

[0078] Figure 1 This is a flowchart illustrating a shared memory data processing method provided in an embodiment of this disclosure. This embodiment is applicable to situations where multiple data publishers simultaneously write data to shared memory. The method in this embodiment can be executed by a shared memory data processing device, which can be implemented in hardware / software and configured in an electronic device. The shared memory data processing method described in any embodiment of this application can be implemented. Figure 1 As shown, the method specifically includes the following:

[0079] S110. Receive a write operation request for the target data. The write operation request is used to request that the target data be written to the shared memory.

[0080] In this embodiment, the write operation request for target data is a request sent to the shared memory by the data publisher when it needs to write data to the shared memory. When the electronic device receives the write operation request for target data, it can write the target data carried in the write operation request into the corresponding storage block in the shared memory.

[0081] The shared memory can include multiple topics, and each topic can contain multiple storage blocks. The write request for the target data can also include an identifier of the topic to which the target data is to be written, enabling the electronic device to directly locate the storage block of the target data in the shared memory.

[0082] S120. Obtain the write index value in the shared memory and update the write index value. The updated write index value is 1 greater than the original write index value. The write index value is used to lock the storage block of the data to be written.

[0083] In this embodiment, the write index value records the identifier of the storage block in the shared memory where the most recently written data was stored, thereby instructing the data publisher on the data writing operation, so that the data publisher can accurately know the location of the storage block in the shared memory where the data is currently being written based on the write index value.

[0084] The identification of storage blocks can be implemented using numbers, letters, or a combination of numbers and letters. This allows electronic devices to manage multiple storage blocks in shared memory in a unified manner.

[0085] After receiving a write operation request for target data, the electronic device needs to update the write index value recorded in the shared memory. In this embodiment, after receiving a write operation request, the electronic device can allocate a storage block in the shared memory according to the write index value for the data publisher to write the target data.

[0086] It should be noted that the write index values ​​in shared memory can be updated and stacked in ascending order, thereby ensuring that each storage block in shared memory can be effectively utilized.

[0087] S130. Determine the storage block corresponding to the updated write index value as the target storage block.

[0088] In this embodiment, the shared memory contains multiple storage blocks, and the write index value can sequentially traverse all storage blocks in the shared memory.

[0089] In this system, the identifiers of storage blocks in shared memory can be arranged in a preset order, and the write index value is the identifier of one of the storage blocks. This ensures that the storage block can be accurately located when the write index value is updated.

[0090] In this embodiment, the specific implementation of the preset rule can be achieved by having the numbers increase sequentially in order of size.

[0091] For example, the shared memory contains 10 storage blocks. The first to tenth storage blocks are identified by numbers 1-10. When the write index value is updated to 4, the fourth storage block can be directly located as the target storage block where the target data is to be stored.

[0092] S140. Write the target data into the target storage block.

[0093] In this embodiment, the electronic device writes the target data received from the data publisher into the target storage block. The electronic device can also write the target data into the target storage block by copying or other means.

[0094] The write index value in this embodiment supports the simultaneous writing of multiple data to different storage blocks in shared memory. This allows multiple data publishers to perform data write operations in shared memory simultaneously, effectively improving the write efficiency of data in shared memory. Simultaneously, it avoids data inconsistency issues caused by the uncertain execution order and unpredictable interruptions when multiple threads write data to the same storage block simultaneously.

[0095] In this scenario, after the electronic device allocates database resources for the first write operation (such as a write operation request for target data), it receives a second write operation request (such as a write operation request for another piece of data) while the target data is being written. At this point, the electronic device can update the write index value again and allocate the next storage block sequentially for the second write operation request, so that multiple pieces of data can be written to the shared memory simultaneously.

[0096] For example, if the write index value corresponding to the first write operation is 4, then the storage block where the target data is to be stored is the storage block corresponding to 4. When the electronic device receives a second write operation request while writing the target data to the storage block corresponding to 4, it updates the write index value to 5, and writes the target data to the storage block corresponding to 4, while simultaneously writing the data corresponding to the second write operation request to the storage block corresponding to 5.

[0097] In this embodiment, optionally, writing the target data into the target storage block includes:

[0098] If the target storage block is determined to be the first storage block in the shared memory, and the first storage block already contains data, then the target data will be replaced and stored in the first storage block.

[0099] In this embodiment, when all storage blocks included in the shared memory have been written with data, if the electronic device receives a write operation request for the target data, it can choose to overwrite the data in the first storage block in the shared memory with the target data. This allows the target data to be effectively written into the shared memory.

[0100] The embodiments disclosed herein can effectively utilize index values ​​to record the storage location of storage blocks in shared memory where data is written in real time. A data publisher does not need to lock the shared memory during the data writing process, enabling multiple data publishers to write data simultaneously according to the index values. Thus, it can effectively achieve simultaneous writing of multiple data in shared memory.

[0101] Figure 2 This is a flowchart illustrating another shared memory data processing method provided in this embodiment. Based on the above embodiments, this embodiment further includes, after step S140, the method of this embodiment:

[0102] S150: Receive a read operation request from the target user equipment. The read operation request is used to request the reading of data from the first storage block in the shared memory.

[0103] In this embodiment, the target user equipment (User Equipment) is one of the devices used by multiple data subscribers in shared memory. A read operation request from the target User Equipment is a request sent by the User Equipment to the shared memory when a data subscriber needs to read data from the shared memory. When the electronic device receives the read operation request from the target User Equipment, it can read the data from the corresponding storage block based on the identifier of the data to be read carried in the read operation request.

[0104] The shared memory can include multiple topics, and each topic can contain multiple storage blocks. The read operation request from the target user device can also include an identifier of the topic from which the target data is to be read, enabling the electronic device to directly locate the data to be read from the multiple storage blocks in the shared memory.

[0105] It should be noted that the target user equipment (User Equipment) can proactively send read operation requests to the electronic device. These requests can be sent according to a pre-set data read interval, or the User Equipment can send a read operation request to the electronic device upon receiving a data read message from the electronic device. This allows the User Equipment to promptly obtain updated data from the shared memory.

[0106] The first storage block can be determined by the target user equipment based on the storage blocks read from the shared memory.

[0107] In this embodiment, optionally, before determining that the state corresponding to the first storage block is the first state, the method of this embodiment further includes:

[0108] Obtain the read index value corresponding to the target user equipment, wherein the read index value is used to indicate the storage block from which the target user equipment has completed reading data from the shared memory;

[0109] Determine that the storage index value is greater than the read index value.

[0110] In this embodiment, the read index value is the identifier of the storage block that the target user equipment recorded the last time it read data from the shared memory. The identifier of the storage block is such as a number, or a letter, or a combination of numbers and letters.

[0111] When an electronic device determines that the storage index value is greater than the read index value, it indicates that new data has been written to the shared memory. At this point, the read data can be returned to the target user device, enabling the target user to effectively obtain the data to be read.

[0112] When an electronic device determines that the storage index value equals the read index value, it indicates that no new data has been written to the shared memory. At this point, the electronic device can return a response message to the target user device indicating a read operation request. This response message includes an indication that no new data has been written. This avoids the problem of increased resource consumption caused by the electronic device repeatedly reading data from the shared memory.

[0113] S160. After the data in the first storage block is read, a data read message is sent to the target user equipment according to the status of the first storage block. The data read message is used to indicate the reading result of the first storage block.

[0114] In this embodiment, during the data reading process, any storage block in the shared memory may experience a data write operation. In order to ensure successful data reading, it is necessary to check the status of the first storage block again after the data reading is completed, thereby preventing the generation of invalid data.

[0115] This embodiment provides a schematic diagram of data writing and data reading, which can be found in the following figures. Figure 3 As shown.

[0116] The shared memory can be divided into three storage spaces, each storing different information. For example, storage space (C) includes multiple storage blocks, some or all of which have been written with data. Storage space (B) stores the state of each storage block. Storage space (A) stores the write index value, the storage index value, the total number of all storage blocks in C (count), and the storage capacity (size) of each storage block in C.

[0117] It should be noted that the storage capacity of each storage block may be the same or different.

[0118] Data writing process:

[0119] After data is written to a storage block and no further data is written, the write index value and the storage index value are the same. Therefore, the obtained write index value (lock_index) is 4, which is stored in an intermediate variable (l_lock_index). Based on an atomic operation (Compare And Swap, CAS), the write index value is atomically incremented by 1, such as... Figure 3As shown, the write index value is 5. The state corresponding to l_lock_index is atomically marked as invalid (INVILAD), the target data (message) is copied to the fifth storage block in C corresponding to l_lock_index, the state of the meat corresponding to l_lock_index is atomically marked as valid (VAILAD), and the storage index value (write_index) is atomically incremented by 1. At this point, write_index = 5. Futex is used to wake up threads waiting for Futex, enabling data subscribers to obtain data promptly.

[0120] Data reading process:

[0121] The data subscriber calls `futex_wait` to put itself to sleep. When it receives a `wake` operation (which can be sent by the electronic device), the electronic device compares the storage index (`write_index`) with the read index (`read_index`). If `write_index` is greater than `read_index`, data needs to be read. Data is read if the first storage block is valid. After reading, the first storage block is checked again to ensure it is valid, and the read data is sent to the data subscriber. If the first storage block is found to be invalid again, the read data is discarded.

[0122] This embodiment can use the lower-level futex system call to complete the data update notification, which not only solves the deadlock problem during inter-process communication, but also improves the efficiency of data processing.

[0123] Figure 4 This is a flowchart illustrating another shared memory data processing method provided in this disclosure. This embodiment is based on the above embodiments, and one possible implementation of step S160 is as follows:

[0124] S1601. After the data in the first storage block is read, if the state corresponding to the first storage block is detected to be the first state, a first data read message is sent to the target user equipment. The first data read message includes the data in the first storage block.

[0125] In this embodiment, the state corresponding to the first storage block can characterize the state of the data stored in the first storage block, i.e., valid or invalid, or being written or written completely. The first state can be valid. When the electronic device determines that the state corresponding to the first storage block is valid, it means that data has been successfully written to the first storage block, and at this time no data publisher has performed a data writing operation.

[0126] In this embodiment, simultaneous reading and writing of data is supported. When the electronic device reads data from the first storage block, it may also store data that the data publisher has written to the first storage block. In this case, the data read from the first storage block is invalid, that is, the data originally stored in the first storage block has been disrupted by the write operation.

[0127] Therefore, after the electronic device finishes reading data from the first storage block, it needs to re-verify whether the state of the corresponding first storage block remains valid. If so, it indicates that no data publisher wrote data to the first storage block during the data reading process, meaning the read data is valid and usable. This effectively ensures that the data sent by the electronic device to the target user device is accurate.

[0128] In this embodiment, optionally, after sending the first data read message to the target user equipment, the method further includes:

[0129] Send an update message for the read index value to the target user equipment. The update message is used to instruct the target user equipment to update the read index value. The updated read index value is 1 greater than the original read index value.

[0130] In this embodiment, after the electronic device sends the data read from the first storage block to the target user device, it needs to remind the target user device to update the read index value of its local storage. This ensures that the target user device can provide an accurate read index value the next time it retrieves a message from the shared memory, thus guaranteeing the validity of the retrieved data.

[0131] S1602 If the state corresponding to the first storage block is detected to be the second state, a second data read message is sent to the target user equipment. The second data read message is used to indicate that the data read in the first storage block has failed.

[0132] The second state is used to indicate that data is being written to the first storage block.

[0133] In this embodiment, the state corresponding to the first storage block can characterize the state of the data stored in the first storage block, i.e., valid or invalid. The second state can be invalid. When the electronic device determines that the state corresponding to the first storage block is invalid, it indicates that data is being written to the first storage block, i.e., one or more data publishers are writing data to the first storage block.

[0134] At this point, the electronic device needs to discard the data read from the first storage block and send a data read failure message to the target user device, so that the target user device can promptly understand the operational status of the first storage block. This effectively avoids the problem of the electronic device sending abnormal data to the target user device, leading to lower accuracy of the data received by the target user device.

[0135] It should be noted that S1601 and S1602 in this embodiment are two detection results of the state corresponding to the first storage block, that is, the state corresponding to the first storage block may be valid or the state corresponding to the first storage block may be invalid.

[0136] In this embodiment, optionally, before writing the target data into the target storage block, the method further includes:

[0137] Set the state corresponding to the target storage block to the second state;

[0138] After writing the target data into the target storage block, the method in this embodiment further includes:

[0139] Set the state corresponding to the target storage block to the first state.

[0140] In this embodiment, the electronic device needs to lock the target storage block before writing the target data into the target storage block in the shared memory to prevent other data from being written at the same time, which would lead to poor data consistency in the target storage block.

[0141] After the electronic device writes the target data to the target storage block in shared memory, it indicates that the data writing in the target storage block is complete. The target storage block then needs to be opened so that write operations can be effectively performed when other data is written to it. This ensures the timeliness of the data in the target storage block.

[0142] In this embodiment, optionally, after setting the state corresponding to the target storage block to the first state, the method further includes:

[0143] Update the storage index value in shared memory. The updated storage index value is 1 greater than the original storage index value. The storage index value is used to indicate the storage block in shared memory where data has been written.

[0144] In this embodiment, after the electronic device sets the state corresponding to the target storage block to valid, it indicates that the data writing operation in the target storage block has been completed, that is, the data has been successfully stored in the target storage block. The storage index value of the shared memory is updated so that the storage block in the shared memory that has been written with data can be effectively identified, thereby making it easier for other users to accurately identify the updated data when retrieving data from the shared memory.

[0145] Figure 5 This is a flowchart illustrating another shared memory data processing method provided in this embodiment. Based on the above embodiments, this embodiment further includes, after step S140, the method of this embodiment:

[0146] S170. Send a data read message to the target user equipment. The data read message is used to instruct the target user equipment to read data from the shared memory.

[0147] In this embodiment, when the electronic device writes target data into the target storage block, it needs to promptly notify the data subscribers in the target storage block to retrieve the data, so that the data subscribers can promptly obtain the new data after the shared memory is updated.

[0148] In addition, the data reading message may also include the topic corresponding to the target data, so that the target user device can clearly understand the topic to which the acquired data belongs, thereby facilitating the target user to make reasonable use of the acquired data.

[0149] Figure 6 This is a schematic diagram of a shared memory data processing device provided in an embodiment of this disclosure; the device is configured in an electronic device and can implement the shared memory data processing method described in any embodiment of this application. The device specifically includes the following:

[0150] The receiving module 610 is used to receive a write operation request for target data, wherein the write operation request is used to request that the target data be written to shared memory;

[0151] The acquisition module 620 is used to acquire the write index value in the shared memory and update the write index value. The updated write index value is 1 greater than the original write index value. The write index value is used to lock the storage block of the data to be written.

[0152] The determination module 630 is used to determine the storage block corresponding to the updated write index value as the target storage block;

[0153] The writing module 640 is used to write the target data into the target storage block.

[0154] In this embodiment, optionally, the device further includes a reading module and a sending module;

[0155] The receiving module 610 is also configured to receive a read operation request from the target user equipment, wherein the read operation request is used to request to read data from the first storage block in the shared memory;

[0156] The read module is used to read data from the first storage block if the state corresponding to the first storage block is the first state, wherein the first state is used to indicate that data has been written to the first storage block;

[0157] The sending module is configured to send a data read message to the target user equipment according to the status of the first storage block after the data in the first storage block has been read. The data read message is used to indicate the reading result of the first storage block.

[0158] In this embodiment, optionally, the sending module is specifically used for:

[0159] If the state corresponding to the first storage block is detected to be the first state, a first data read message is sent to the target user equipment, and the first data read message includes the data in the first storage block;

[0160] Alternatively, if the state corresponding to the first storage block is detected to be the second state, a second data read message is sent to the target user equipment, the second data read message being used to indicate that the data read in the first storage block has failed;

[0161] The second state is used to indicate that data is being written to the first storage block.

[0162] In this embodiment, optionally, the device further includes: a setting module;

[0163] The setting module is used to set the state corresponding to the target storage block to the second state;

[0164] The setting module is also used to set the state corresponding to the target storage block to the first state.

[0165] In this embodiment, optionally, the device further includes: an update module;

[0166] An update module is used to update the storage index value in the shared memory. The updated storage index value is 1 greater than the original storage index value. The storage index value is used to indicate the storage block in the shared memory that has completed the writing of data.

[0167] In this embodiment, optionally, the acquisition module 620 is further configured to acquire the read index value corresponding to the target user equipment, wherein the read index value is used to indicate the storage block from which the target user equipment has completed reading data from the shared memory;

[0168] The determining module 630 is also used to determine that the storage index value is greater than the read index value.

[0169] In this embodiment, optionally, the sending module is further configured to send an update message of the read index value to the target user equipment, the update message being used to instruct the target user equipment to update the read index value, the updated read index value being 1 greater than the original read index value.

[0170] In this embodiment, optionally, the sending module is further configured to send a data read message to the target user equipment, the data read message being used to instruct the target user equipment to read data from the shared memory.

[0171] In this embodiment, optionally, the writing module is specifically used for:

[0172] If the target storage block is determined to be the first storage block in the shared memory, and the first storage block already contains data, then the target data is replaced and stored in the first storage block.

[0173] The shared memory data processing device of this invention can use index values ​​to record the storage location of the storage block in the shared memory in real time. A data publisher does not need to lock the shared memory during the data writing process, so that multiple data publishers can write data at the same time according to the index values. Thus, it can effectively realize the simultaneous writing of multiple data in the shared memory.

[0174] The shared memory data processing apparatus provided in the embodiments of the present invention can execute the shared memory data processing method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of executing the method.

[0175] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. For example... Figure 7 As shown, the electronic device includes a processor 710, a memory 720, an input device 730, and an output device 740; the number of processors 710 in the electronic device can be one or more. Figure 7 Taking a processor 710 as an example; the processor 710, memory 720, input device 730, and output device 740 in the electronic device can be connected via a bus or other means. Figure 7 Taking the example of a connection between China and Israel via a bus.

[0176] The memory 720, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and modules, such as the program instructions / modules corresponding to the shared memory data processing method in this embodiment of the invention. The processor 710 executes various functional applications and data processing of the electronic device by running the software programs, instructions, and modules stored in the memory 720, thereby implementing the shared memory data processing method provided in this embodiment of the invention.

[0177] The memory 720 may primarily include a program storage area and a data storage area. The program storage area may store the operating system and at least one application program required for a given function; the data storage area may store data created based on terminal usage. Furthermore, the memory 720 may include high-speed random access memory and non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 720 may further include memory remotely located relative to the processor 710, which can be connected to the electronic device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0178] Input device 730 can be used to receive input digital or character information, and to generate key signal inputs related to user settings and function control of the electronic device, and may include a keyboard, mouse, etc. Output device 740 may include display devices such as a display screen.

[0179] This disclosure also provides a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to implement the shared memory data processing method provided in this embodiment of the invention.

[0180] Of course, the computer-executable instructions provided in the embodiments of the present invention are not limited to the method operations described above, but can also perform related operations in the shared memory data processing method provided in any embodiment of the present invention.

[0181] Based on the above description of the implementation methods, those skilled in the art can clearly understand that the present invention can be implemented using software and necessary general-purpose hardware, and of course, it can also be implemented using hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk, or optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.

[0182] It is worth noting that in the embodiments of the search device described above, the various units and modules included are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be achieved; in addition, the specific names of each functional unit are only for easy differentiation and are not used to limit the scope of protection of the present invention.

[0183] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0184] The above description is merely a specific embodiment of this disclosure, enabling those skilled in the art to understand or implement it. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this disclosure. Therefore, this disclosure is not to be limited to the embodiments described herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A data processing method of shared memory, characterized by, The method comprises: receiving a write operation request of target data, the write operation request being used to request writing the target data into a shared memory; obtaining a write index value in the shared memory and updating the write index value, the updated write index value being greater than the write index value by 1, the write index value being used to lock a storage block of to-be-written data; determining that a storage block corresponding to the updated write index value is a target storage block; writing the target data into the target storage block; wherein the method further comprises: receiving a read operation request of a target user equipment, the read operation request being used to request reading data of a first storage block in the shared memory; obtaining a read index value corresponding to the target user equipment, wherein the read index value is used to indicate a storage block of the target user equipment from which data has been read in the shared memory; determining that the storage index value is greater than the read index value, the storage index value being used to indicate a storage block of the shared memory in which data has been written; detecting that a state corresponding to the first storage block is a first state, and then reading data in the first storage block, wherein the first state is used to indicate that the first storage block has completed writing data; after the reading of the data in the first storage block is completed, sending a data reading message to the target user equipment according to the state corresponding to the first storage block, the data reading message being used to indicate a reading result of the first storage block.

2. The method of claim 1, wherein, The sending of the data reading message to the target user equipment according to the state corresponding to the first storage block comprises: detecting that the state corresponding to the first storage block is the first state, and then sending a first data reading message to the target user equipment, the first data reading message comprising the data in the first storage block; or, detecting that the state corresponding to the first storage block is a second state, and then sending a second data reading message to the target user equipment, the second data reading message being used to indicate that reading of the data in the first storage block fails; wherein the second state is used to indicate that the first storage block is writing data.

3. The method of claim 2, wherein, Before the writing of the target data into the target storage block, the method further comprises: setting a state corresponding to the target storage block to a second state; after the writing of the target data into the target storage block, the method further comprises: setting the state corresponding to the target storage block to the first state.

4. The method of claim 3, wherein, After the setting of the state corresponding to the target storage block to the first state, the method further comprises: updating a storage index value in the shared memory, the updated storage index value being greater than the storage index value by 1.

5. The method of claim 4, wherein, After the sending of the first data reading message to the target user equipment, the method further comprises: sending an update message of the read index value to the target user equipment, the update message being used to instruct the target user equipment to update the read index value, the updated read index value being greater than the read index value by 1.

6. The method of claim 1, wherein, The method further comprises: The data read message is used to instruct the target user equipment to read data from the shared memory.

7. The method of claim 1, wherein, The writing of the target data into the target storage block comprises: If the target storage block is the first storage block in the shared memory and the first storage block has stored data, the target data is stored into the first storage block to replace the data.

8. A data processing apparatus sharing memory, characterized by, The device comprises: The receiving module is configured to receive a write operation request of target data, the write operation request being used to request writing of the target data into a shared memory. The obtaining module is configured to obtain a write index value in the shared memory and update the write index value, the updated write index value being greater than the previous write index value by 1, the write index value being used to lock a storage block of to-be-written data. The determining module is configured to determine that a storage block corresponding to the updated write index value is a target storage block. The writing module is configured to write the target data into the target storage block. The device further comprises: The receiving module is configured to receive a read operation request of a target user equipment, the read operation request being used to request reading of data of a first storage block in the shared memory. The obtaining module is configured to obtain a read index value corresponding to the target user equipment, the read index value being used to indicate a storage block of the shared memory from which the target user equipment has completed reading of data. The determining module is configured to determine that the storage index value is greater than the read index value, the storage index value being used to indicate a storage block of the shared memory in which writing of data has been completed. The reading module is configured to read data in the first storage block if a state corresponding to the first storage block is detected to be a first state, the first state being used to indicate that writing of data in the first storage block has been completed. The sending module is configured to send a data read message to the target user equipment according to the state corresponding to the first storage block after reading of data in the first storage block is completed, the data read message being used to indicate a read result of the first storage block.

9. An electronic device, comprising: The device comprises: One or more processors; A storage device configured to store one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the data processing method of the shared memory according to any one of claims 1 to 7.

10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The program is executed by the processor to implement the data processing method of the shared memory according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Data reading and writing method and device of shared memory

    CN107632945A

  • Buffer management method and buffer management device

    EP1936501A1

  • Data synchronous system for synchronizing updated data in a redundant system

    US20090083393A1

  • Adaptive Multi-Threaded Buffer

    US20130246672A1

  • System for inter-process communication

    US20200301765A1