Message processing method, electronic device, and storage medium

By employing an event mechanism and counters for message processing in home energy storage devices, the problem of inefficient inter-thread communication is solved, achieving efficient inter-thread communication and ensuring the normal operation of the device and the accuracy of communication.

CN116820810BActive Publication Date: 2026-11-20ECOFLOW INC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310927603.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-25
Publication Date
2026-11-20
Estimated Expiration
2043-07-25

AI Technical Summary

Technical Problem

Existing inter-thread communication mechanisms are inefficient in home energy storage devices due to limited IPC resources, which affects the normal operation of the devices.

Method used

Message processing is handled using an event mechanism, and inter-thread communication is achieved through a counter, avoiding data copying between the kernel and user space, and eliminating the need for serialization and deserialization operations.

Benefits of technology

This improves the efficiency of inter-thread communication, ensuring the normal operation of home energy storage devices and the accuracy of communication.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116820810B_ABST
    Figure CN116820810B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a message processing method, an electronic device and a storage medium. The message processing method comprises: in response to a message write instruction of a target event by a production thread, obtaining a counter value in a counter corresponding to the target event; after an updated value corresponding to the target event is written in the counter, updating the counter value based on the updated value; in response to a message read instruction of the counter by a consumption thread, reading the counter value corresponding to the counter to the consumption thread, so that the consumption thread determines occurrence of the target event according to the counter value corresponding to the counter. The above method can improve communication efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of computer technology, and in particular relates to a message processing method, electronic device and storage medium. Background Technology

[0002] Applications can use inter-thread communication mechanisms to achieve data sharing and exchange between multiple threads. For example, when one thread needs to send a message to another thread, a communication mechanism can be used to achieve inter-thread communication.

[0003] In relevant message processing schemes, electronic devices process messages using communication mechanisms such as message queues, pipes, sockets, semaphores, and shared memory. Since these communication mechanisms require a large amount of IPC (Inter-Process Communication) resources, if the number of IPC resources reaches its limit, it will lead to low communication efficiency. Summary of the Invention

[0004] This application provides a message processing method, an electronic device, and a storage medium to solve the problem of low communication efficiency between threads within a device.

[0005] The first aspect of this application provides a message processing method, including: in response to a message write instruction from a production thread for a target event, obtaining a counter value in a counter corresponding to the target event; after writing an update value corresponding to the target event into the counter, updating the counter value based on the update value; and in response to a message read instruction from a consumer thread for the counter, reading the counter value corresponding to the counter into the consumer thread, so that the consumer thread determines that a target event has occurred based on the counter value corresponding to the counter.

[0006] In the message processing method provided in this application embodiment, in response to the message write instruction of the production thread for the target event, the counter value in the counter corresponding to the target event is obtained. After writing the updated value corresponding to the target event into the counter, the counter value is updated based on the updated value. In response to the message read instruction of the consumer thread for the counter, the counter value corresponding to the counter is read into the consumer thread, so that the consumer thread determines that the target event has occurred based on the counter value corresponding to the counter. This application embodiment uses an event mechanism for message processing, which eliminates the need for data copying between the kernel and user space as required by message queues. Furthermore, the data transmission of the event mechanism is based on a counter, eliminating the need for message serialization and deserialization operations, thus improving communication efficiency.

[0007] A second aspect of this application also provides a message processing apparatus, comprising: an instruction response module, configured to, in response to a message write instruction from a production thread for a target event, obtain a counter value from a counter corresponding to the target event; a value update module, configured to, after writing an update value corresponding to the target event into the counter, update the counter value based on the update value; and an event determination module, configured to, in response to a message read instruction from a consumer thread for the counter, read the counter value corresponding to the counter into the consumer thread, so that the consumer thread determines that a target event has occurred based on the counter value corresponding to the counter.

[0008] A third aspect of this application also provides an electronic device, which includes a processor that executes a computer program stored in a memory to implement the above-described message processing method.

[0009] A fourth aspect of this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the above-described message processing method. Attached Figure Description

[0010] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0011] Figure 1 This is an application scenario diagram of a message processing method provided in an embodiment of this application;

[0012] Figure 2 This is a flowchart of a message processing method provided in an embodiment of this application;

[0013] Figure 3 This is a flowchart illustrating the reading of a counter value according to an embodiment of this application;

[0014] Figure 4 This is a flowchart illustrating the determination of the target event provided in an embodiment of this application;

[0015] Figure 5 This is a flowchart illustrating the establishment of mapping relationships provided in the embodiments of this application;

[0016] Figure 6 This is a schematic diagram of the structure of the message processing device provided in the embodiments of this application;

[0017] Figure 7 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0018] To better understand the above-mentioned objectives, features, and advantages of this application, the application will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.

[0019] Numerous specific details are set forth in the following description in order to provide a full understanding of this application. The described embodiments are only some, not all, of the embodiments of this application.

[0020] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application.

[0021] In home energy storage projects, home energy storage devices (e.g., grid-connected energy storage, wind power energy storage, and photovoltaic energy storage) are connected to smart home devices (e.g., air conditioners, lights, televisions, and refrigerators). Remote control of the home energy storage devices enables power management of the smart home, thereby reducing electricity costs and improving energy efficiency. When developing applications for these home energy storage devices or smart home systems, inter-thread communication mechanisms are needed to achieve data sharing and exchange between multiple threads. For example, a home energy storage device may contain multiple functional modules (e.g., battery module, communication module, monitoring module, and display module), each with its own thread. Taking the battery module, communication module, and monitoring module as examples, the battery module has its own battery thread, the communication module has its own communication thread, and the monitoring module has its own monitoring thread. The battery thread determines energy storage information such as the remaining power, charging temperature, and charging speed of the home energy storage device, and then sends this energy storage information to the communication thread. The communication thread receives the energy storage information sent by the battery thread and sends it to the monitoring thread. The monitoring thread receives the energy storage information and monitors the current energy storage status of the home energy storage device based on the energy storage information, so that each smart home device can plan its own electricity consumption plan in a timely manner according to the current energy storage status, thereby improving energy utilization and reducing electricity costs.

[0022] The message processing method provided in this application has a wide range of applications. In addition to the above-mentioned home energy storage application scenario, it can also include mobile live streaming, vehicle networking, financial payment, smart catering, and instant messaging application scenarios, and there are no limitations on these.

[0023] However, in relevant message processing schemes, electronic devices handle messages using communication mechanisms such as message queues, pipes, sockets, semaphores, and shared memory. Taking a home energy storage project as an example, since a home energy storage device consists of multiple modules, each corresponding to a different thread, after an operation is completed in one thread, it needs to notify another thread to perform the next operation. If communication mechanisms such as message queues, pipes, sockets, semaphores, and shared memory are used, the IPC (Inter-Process Communication) resources in a home energy storage project are limited, while the aforementioned communication mechanisms require a large amount of IPC resources. Therefore, if the number of IPC resources reaches its limit, the home energy storage device will not be able to operate normally, resulting in low communication efficiency.

[0024] To address the aforementioned issues, this application provides a message processing method that uses an event mechanism for message processing, thereby improving communication efficiency.

[0025] Combination Figure 1 This application illustrates an application scenario diagram of the message processing method provided in the embodiments of this application. For example... Figure 1 As shown, a third-party thread communicates with both the production thread and the consumer thread. On one hand, the third-party thread receives message write instructions for a target event from the production thread and updates the counter value corresponding to the target event according to the message write instructions, obtaining the updated counter value. On the other hand, the third-party thread also receives message read instructions for the counter from the consumer thread and reads the corresponding counter value from the counter to the consumer thread, enabling the consumer thread to determine the target event based on the counter value. The third-party thread implements the message processing method through communication with the production and consumer threads. In one embodiment, the third-party thread, production thread, and consumer thread all run in the electronic device. The electronic device calls the third-party thread to respond to relevant instructions issued by the production and consumer threads and implements the message processing method by processing these instructions. The production thread writes event-related messages, and the consumer thread reads the relevant events written by the production thread. The third-party thread can be a control flow established within the electronic device, distinct from the production and consumer threads. The event can be a behavior occurring in the operating system of the electronic device, such as user input, network connection, or hardware failure. Events can be triggered and then processed by the operating system or applications. Events can be used to manage various aspects of the operating system, such as process scheduling, memory management, and file systems.

[0026] Figure 2This is a flowchart illustrating a message processing method provided in an embodiment of this application. The message processing method can be applied to electronic devices, and further, it can be applied to a third-party thread within the electronic device. Figure 2 As shown, the message processing method may include the following steps. Depending on different requirements, the order of the steps in this flowchart may be changed, and some may be omitted.

[0027] S11, in response to the message write instruction of the production thread for the target event, retrieves the counter value in the counter corresponding to the target event.

[0028] In some embodiments, to address the problem of low communication efficiency caused by communication mechanisms using IPC resources, this application introduces an event communication mechanism to achieve communication between threads. Events support operations such as reading, writing, closing, and opening. Since events are not files in nature, the opening, closing, reading, and writing efficiency of the event communication mechanism is relatively high. In one embodiment, a corresponding counter exists for each event. The counter can be 64-bit, where a bit is the smallest unit of storage, and each bit can store one binary code. In other embodiments, the counter can also be 32-bit or 128-bit; no limitation is made here.

[0029] In some embodiments, taking a home energy storage project as an example, the home energy storage project also includes an IoT (Internet of Things) application. The IoT application is used to process the communication connection between the home energy storage device and the smart home. In one embodiment, the IoT application may include a Wi-Fi communication module, an authentication module, and an MQTT (Message Queuing Telemetry Transport) module. The Wi-Fi communication module is used to connect the home energy storage device and the smart home; the authentication module is used to verify the identity and permissions of the smart home to ensure that only authorized devices can access the home energy storage device; the MQTT module is used to transmit messages between the home energy storage device and the smart home. The MQTT protocol is a lightweight protocol that can work in low-bandwidth and unstable network environments and has high scalability. Accordingly, the thread number for the Wi-Fi communication module is 1, and the preset event is WiFi_eventfd (Wi-Fi event); the thread number for the authentication module is 2, and the preset event is auth_eventfd (authentication event); the thread number for the MQTT module is 3, and the preset event is mqtt_eventfd (MQTT event). Here, preset events refer to events pre-set according to the various modules of the IoT application.

[0030] In one embodiment, for each preset event, there are also multiple sub-events. The number of sub-events can be set according to actual needs and is not limited here. For example, if the preset event is WiFi_eventfd, the corresponding sub-events may include WiFi_CONNECT_EVENT (Wi-Fi connection event), WiFi_RECONNECT_EVENT (Wi-Fi reconnection event), and WiFi_DISCONNECT_EVENT (Wi-Fi disconnection event). If the preset event is auth_eventfd, the corresponding sub-events may include AUTH_EVENT (authentication event), REAUTH_EVENT (re-authentication event), and AUTH_STOP_EVENT (stop authentication event). If the preset event is mqtt_eventfd, the corresponding sub-events may include MQTT_CONNECT_EVENT (connection event), MQTT_RECONNECT_EVENT (reconnection event), and MQTT_DISCONNECT_EVENT (disconnection event).

[0031] In some embodiments, the production thread can be used to perform write operations, selecting a target event from the aforementioned multiple subclass events and performing a message write operation on that target event. For example, if the production thread sends ten notifications of the WiFi_CONNECT_EVENT event to a third-party thread, it indicates that the production thread has selected the Wi-Fi connection event as the target event and is performing ten message write operations on that target event. When performing the message write operation, the production thread can send a message write instruction to the third-party thread. The message write instruction may include information such as the name of the target event, the write time corresponding to the target event, and the write code. Subsequently, the third-party thread obtains the counter corresponding to the target event and the counter value by parsing the message write instruction. In one embodiment, there is an association between the target event and the write code; the production thread can obtain the write code associated with the target event and fill the write code into the message write instruction.

[0032] S12: After writing the updated value corresponding to the target event into the counter, update the counter value based on the updated value.

[0033] In some embodiments, for each preset event, there is a corresponding write code. The counter value is updated based on the write code to obtain a new counter value. In one embodiment, the write code can be encoded with a granularity of 0xff. For example, in some scenarios, the write code corresponding to a Wi-Fi connection event can be 0x0000000000000001, and the write code corresponding to a Wi-Fi reconnection event can be 0x0000000000000100. Continuing with the above embodiments, if the production thread sends ten WiFi_CONNECT_EVENT event notifications to the electronic device, the update value corresponding to the target event is 0x0000000000000001*10, which is 0x0000000000000000A. Then, the counter value is updated based on 0x0000000000000000A. In other scenarios, if the production thread sends ten WiFi_CONNECT_EVENT event notifications to the electronic device, the counter value can also be updated ten times using 0x0000000000000001.

[0034] S13, in response to the message read instruction of the consumer thread for the counter, read the counter value corresponding to the counter to the consumer thread so that the consumer thread can determine the occurrence of the target event based on the counter value corresponding to the counter.

[0035] In some embodiments, the consumer thread reads events written by the producer thread. The consumer thread sends a message read instruction to a third-party thread, which is a pre-set instruction to read the counter values ​​corresponding to all counters or a specified counter within the third-party thread. In one embodiment, if the message read instruction is used to read the counter value corresponding to a specified counter, the message read instruction includes the number or name of the specified counter; if the message read instruction is used to read the counter values ​​corresponding to all counters, the message read instruction does not include the number or name of any counter. If the third-party thread receives the message read instruction, it determines whether the consumer thread is reading the counter values ​​corresponding to all counters or a specified counter by parsing whether the message read instruction contains the counter number or name. In one embodiment, if the message read instruction does not contain the number or name of any counter, the counter value corresponding to each counter is read to the consumer thread so that the consumer thread can determine the target event based on the counter value corresponding to the counter; if the message read instruction contains the counter number or name, the counter value corresponding to the specified counter, determined based on the counter number or name, is read to the consumer thread so that the consumer thread can determine the target event based on the counter value corresponding to the counter.

[0036] In the message processing method provided in this application embodiment, in response to the message write instruction of the production thread for the target event, the counter value in the counter corresponding to the target event is obtained. After writing the updated value corresponding to the target event into the counter, the counter value is updated based on the updated value. In response to the message read instruction of the consumer thread for the counter, the counter value corresponding to the counter is read into the consumer thread, so that the consumer thread determines that the target event has occurred based on the counter value corresponding to the counter. This application embodiment uses an event mechanism for message processing, which eliminates the need for data copying between the kernel and user space as required by message queues. Furthermore, the data transmission of the event mechanism is based on a counter, eliminating the need for message serialization and deserialization operations, thus improving communication efficiency.

[0037] In some embodiments, a corresponding counter exists within the electronic device for each event. A first mapping relationship is pre-established between events and counters. By querying this first mapping relationship, the counter corresponding to the target event can be determined. By establishing the mapping relationship between events and counters, this embodiment of the application can quickly determine the counter corresponding to the target event when a message write instruction is received from the production thread for the target event, thereby improving communication efficiency.

[0038] In some embodiments, the producer thread may send message write instructions to a third-party thread multiple times for the same event (e.g., the producer thread sends two message write instructions to a third-party thread for a Wi-Fi connection event). If the consumer thread does not process this in a timely manner, it will cause the consumer thread to repeatedly read multiple message write instructions for the same event, affecting communication efficiency. In one embodiment, if an event with a SEMAPHOR flag is set, each time the producer thread sends a message write instruction to a third-party thread for a target event, the third-party thread records the write code carried in the message write instruction as 1 and increments the counter corresponding to the target event by 1. When the consumer thread sends a message read instruction to the third-party thread, the third-party thread will return 1 each time and decrement the counter value by 1. The above embodiment will cause the consumer thread to repeatedly operate on multiple message write instructions for the same event, affecting communication efficiency. To avoid the above problem, deduplication processing needs to be performed on multiple message write instructions for the same event. In one embodiment, the SEMAPHOR flag is not introduced when initializing the event, that is, an event without setting the SEMAPHOR flag is created. If the SEMAPHOR flag is not included in the event, each time the producer thread sends a message write instruction to the third-party thread for the target event, the third-party thread updates the write code carried in the message write instruction to the counter corresponding to the target event. When the consumer thread sends a message read instruction to the third-party thread, the third-party thread returns the counter value corresponding to the current time and sets the counter to 0. Through the above embodiment, the consumer thread will only receive a write notification for the target event once, which can avoid the problem of the consumer thread repeatedly reading multiple message write instructions for the same event, thus improving communication efficiency.

[0039] As described in the above embodiments, the initial value of each counter is 0. The third-party thread parses the message write instruction sent by the production thread to the target event to obtain the updated value corresponding to the target event, and updates the initial value of 0 in the counter corresponding to the target event to obtain a new counter value. Subsequently, if the third-party thread continues to receive message write instructions for the target event, it continues to parse the message write instructions to obtain the updated value corresponding to the target event, and updates the new counter value corresponding to the target event to the new counter value. By setting the initial value of the counter to 0, this embodiment of the application can ensure that the counter value read by the consumer thread is consistent with the message write instruction sent by the production thread, thereby improving the accuracy of communication.

[0040] In some embodiments, the counter can be 32-bit, 64-bit, or 128-bit, and there is no limitation here. This application embodiment takes a 64-bit counter as an example, meaning there are 64 binary bits. In one embodiment, 8 bits are used as a byte space, with one byte space representing one event; in this case, one counter is equivalent to 8 bytes of space. In other embodiments, 4 bits can also be used as a byte space; in this case, one counter is equivalent to 16 bytes of space, and there is no limitation here. This application embodiment takes 8 bits representing one event as an example. The write code corresponding to a Wi-Fi connection event can be 0x0000000000000001, and the write code corresponding to a Wi-Fi reconnection event can be 0x00000000000000100. If the production thread continuously sends 256 message write commands for the Wi-Fi connection event, the counter value will be 0x00000000000000100, and only then will the counter value be the same as the write code corresponding to the Wi-Fi reconnection event. In practical applications, threads do not block for such a long time, meaning the acquired counter value and the write code will not be the same. This embodiment of the application uses 8 bits to represent each event, thus avoiding data confusion caused by the acquired counter value and the write code being the same (for example, if the write code corresponding to a Wi-Fi connection event is 1, and the write code corresponding to a Wi-Fi reconnection event is 2, and the production thread sends two message write commands for the Wi-Fi connection event, the counter value will be 2, the same as the write code corresponding to the Wi-Fi reconnection event, easily causing data confusion). This improves the accuracy of target event determination, thereby improving the accuracy of communication.

[0041] In some embodiments, updating the counter value based on the updated value includes: when both the updated value and the counter value are binary bits, calculating the updated counter value according to the binary bit calculation method. Continuing with the above embodiments, the write code corresponding to the Wi-Fi connection event can be 0x0000000000000001, and the counter value of the counter corresponding to the Wi-Fi connection event is 0. If the production thread sends 10 message write instructions to the electronic device for this event, the updated value corresponding to the event is obtained as 0x0000000000000001*10, which is 0x0000000000000000A. Then, the counter value 0 is added to 0x000000000000000A to obtain the updated counter value 0x0000000000000000A. This application embodiment represents events using binary bits, and then calculates the counter value according to the binary bit calculation method. This avoids the problem of data confusion caused by the same acquired counter value as the written code, improves the accuracy of target event determination, and thus improves the accuracy of communication.

[0042] In some embodiments, after the consumer thread reads the counter value corresponding to the counter to the consumer thread in response to the consumer thread's message read instruction for the counter, the consumer thread determines the corresponding target event based on the counter value and performs corresponding operations on the target event. Thus, after the consumer thread has processed the target event written into the counter by the producer thread at the current moment, the third-party thread sets the counter corresponding to the target event to 0. This application improves the accuracy of the consumer thread's processing of target events by setting the counter to 0 after reading the counter value corresponding to the counter to the consumer thread, thus indicating that the consumer thread has completed processing the target event written into the counter by the producer thread at the current moment; subsequently, when a message write instruction from the producer thread is received, the updated value corresponding to the message write instruction is added to the initial value of 0, thereby improving the accuracy of communication.

[0043] Figure 3 This is a schematic diagram of the counter value reading process provided in an embodiment of this application. In one embodiment, the counter value reading method can be applied to a third-party thread; in other embodiments, the counter value reading method can be applied to a consumer thread. This embodiment of the application only takes the application of the counter value reading method to a third-party thread as an example. Figure 3 As shown, the method for reading the counter value may include the following steps. Depending on different needs, the order of the steps in this flowchart may be changed, and some may be omitted.

[0044] S21, obtain the preset mask information corresponding to each preset event.

[0045] In some embodiments, preset mask information is used to identify events corresponding to a certain numerical range. For example, Wi-Fi events include Wi-Fi connection events, Wi-Fi reconnection events, Wi-Fi disconnection events, Wi-Fi scanning events, etc. The preset mask information corresponding to a Wi-Fi connection event can be 0x00000000000000FF, in which case the maximum value of the counter corresponding to the Wi-Fi connection event is less than or equal to 0x00000000000000FF; the preset mask information corresponding to a Wi-Fi reconnection event can be 0x000000000000FF00, in which case the maximum value of the counter corresponding to the Wi-Fi reconnection event is less than or equal to 0x0000000000000FF00, and so on. For each preset event, there exists corresponding preset mask information. In one embodiment, the preset mask information associated with each preset event is directly obtained. In other embodiments, a mapping relationship between preset events and preset mask information is pre-set, and the preset mask information corresponding to the preset event can be obtained by querying this mapping relationship. The embodiments of this application can expand an event into multiple sub-events by using a masking mechanism, which can save system resources.

[0046] S22, perform logical AND processing on each preset mask information and the corresponding counter value to obtain the logical result corresponding to each preset mask information.

[0047] In some embodiments, after performing a logical AND operation between each preset mask information and the counter value corresponding to the counter, the resulting logical result may include 0 and non-zero.

[0048] S23, send the logical result to the consumer thread so that the consumer thread can determine the occurrence of the target event based on the logical result.

[0049] In some embodiments, a logical result of 0 or non-zero is sent to the consumer thread so that the consumer thread can determine that the target event has occurred based on the logical result. For example, if the logical result is 0, it indicates that there is no event corresponding to the counter; if the logical result is non-zero, it indicates that there is an event corresponding to the counter.

[0050] For example, the preset mask information corresponding to the Wi-Fi connection event is 0x00000000000000FF, the write code corresponding to the Wi-Fi connection event is 0x0000000000000001, and the counter value corresponding to the Wi-Fi connection event is 0. If the production thread sends 10 message write commands to a third-party thread for this event, the updated value corresponding to the event is 0x0000000000000001*10, which is 0x000000000000000A. Then, the counter value 0 is added to 0x0000000000000000A to obtain the updated counter value 0x0000000000000000A. If a logical AND operation is performed between 0x0000000000000FF and 0x000000000000000A, and the result is non-zero, then a Wi-Fi connection event has occurred.

[0051] This application embodiment obtains preset mask information corresponding to each preset event and performs logical AND processing on each preset mask information and the corresponding counter value. Based on the logical result, the target event can be determined, improving the accuracy of target event determination and thus improving communication accuracy. In other embodiments of this application, the third-party thread can also directly transmit the counter value to the consumer thread. The consumer thread performs related processing based on the counter value and mask information to obtain a logical result, and then determines the target event based on the logical result.

[0052] Figure 4 This is a schematic diagram of the target event determination process provided in an embodiment of this application. The target event determination method can be applied to electronic devices, and further, the target event determination method can be applied to the consumption thread of an electronic device. Figure 4 As shown, the method for determining the target event may include the following steps. Depending on different needs, the order of the steps in this flowchart may be changed, and some may be omitted.

[0053] S31, determine the target mask information where the logical result is non-zero.

[0054] In some embodiments, a logical AND operation is performed on each preset mask information and the counter value corresponding to the counter to obtain the logical result corresponding to each preset mask information. A non-zero logical result is selected from multiple logical results, and then the target mask information associated with the non-zero logical result is determined.

[0055] S32, based on the pre-set mapping relationship between mask information and events, determine the event corresponding to the target mask information as the target event.

[0056] This application embodiment performs logical AND processing on each preset mask information and the corresponding counter value, which can determine the target event based on the logical result, improving the accuracy of target event determination and thus improving communication accuracy. This application embodiment calculates an updated counter value by combining the updated value and the counter value, and then determines the event based on the updated counter value and related mask information. This allows for deduplication of event messages, further improving communication efficiency.

[0057] Figure 5 This is a schematic diagram illustrating the process of establishing a mapping relationship provided in an embodiment of this application. The method for establishing a mapping relationship can be applied to electronic devices, and further, the method for establishing a mapping relationship can be applied to a third-party thread of an electronic device. Figure 5 As shown, the method for establishing mapping relationships may include the following steps. Depending on different needs, the order of the steps in this flowchart may be changed, and some may be omitted.

[0058] S41, get the number of binary bits corresponding to the counter.

[0059] In some embodiments, the number of binary bits corresponding to the counter can be 32 bits, 64 bits, or 128 bits, and there is no limitation here. This application embodiment takes a 64-bit counter as an example, that is, there are 64 binary bits.

[0060] S42 determines the preset number of bytes of space based on the number of binary bits.

[0061] In some embodiments, the preset number can be determined based on the number of events. For example, the preset number can be 8, that is, 8 bits as one byte space, one byte space represents one event, and one counter is equivalent to 8 bytes of space; or, the preset number can be 4, that is, 4 bits as one byte space, one byte space represents one event, and one counter is equivalent to 16 bytes of space; or, the preset number can be 2, that is, 2 bits as one byte space, one byte space represents one event, and one counter is equivalent to 32 bytes of space.

[0062] S43, based on the settings information, establish a mapping relationship between the byte space and the preset events.

[0063] In some embodiments, a mapping relationship is established between the byte space and the preset event according to the setting information of steps S41-S42 above. In this embodiment of the application, an event is represented by 8 bits. The write code corresponding to the WiFi connection event can be 0x0000000000000001, and the write code corresponding to the WiFi reconnection event can be 0x0000000000000100.

[0064] This application embodiment obtains the number of binary bits corresponding to the counter, then determines a preset number of byte spaces based on the number, and establishes a mapping relationship between the byte spaces and preset events to ensure that each preset event has a corresponding byte space. By representing events in binary bits and then calculating the counter value according to the binary bit calculation method, the problem of data confusion caused by the same obtained counter value and written encoding can be avoided, improving the accuracy of target event determination and thus improving the accuracy of communication.

[0065] Please see Figure 6 , Figure 6 This is a schematic diagram of the structure of a message processing apparatus provided in an embodiment of this application. In some embodiments, the message processing apparatus 20 may include multiple functional modules composed of computer program segments. The computer programs of each program segment in the message processing apparatus 20 may be stored in the memory of an electronic device and executed by at least one processor to perform (see details). Figure 2 (Description) The message processing function.

[0066] In this embodiment, the message processing device 20 can be divided into multiple functional modules according to the functions it performs. These functional modules may include: an instruction response module 201, a value update module 202, and an event determination module 203. As used in this application, a module refers to a series of computer program segments that can be executed by at least one processor and perform a fixed function, and which are stored in memory. In this embodiment, the functions of each module will be described in detail in subsequent embodiments.

[0067] The instruction response module 201 is used to respond to the message write instruction of the production thread for the target event and obtain the counter value in the counter corresponding to the target event.

[0068] The value update module 202 is used to update the counter value based on the updated value corresponding to the target event after the updated value is written into the counter;

[0069] The event determination module 203 is used to respond to the message read instruction of the consumer thread to the counter, read the counter value corresponding to the counter to the consumer thread, so that the consumer thread can determine the occurrence of the target event based on the counter value corresponding to the counter.

[0070] It is understood that the message processing device 20 and the message processing method of the above embodiments belong to the same inventive concept. The specific implementation of each module of the message processing device 20 corresponds to each step of the message processing method in the above embodiments, and will not be repeated here.

[0071] The module division described above is a logical functional division, and other division methods may be used in actual implementation. Furthermore, the functional modules in the various embodiments of this application can be integrated into the same processing unit, or each module can exist physically separately, or two or more modules can be integrated into the same unit. The integrated modules described above can be implemented in hardware or in a combination of hardware and software functional modules.

[0072] Figure 7 This is a schematic diagram of the structure of the electronic device provided in an embodiment of this application. For example... Figure 7 As shown, the electronic device 30 includes a memory 31, at least one processor 32, at least one communication bus 33, and a transceiver 34. The processor 32 is used to execute a message processing method implemented when executing a computer program stored in the memory 31.

[0073] Those skilled in the art should understand that Figure 7 The structure of the electronic device shown does not constitute a limitation of the embodiments of this application. It can be a bus structure or a star structure. The electronic device 30 may also include more or fewer other hardware or software than shown, or different component arrangements.

[0074] In some embodiments, electronic device 30 is a device capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions. Its hardware includes, but is not limited to, microprocessors, application-specific integrated circuits, programmable gate arrays, digital processors, and embedded devices. Electronic device 30 can also connect to client devices, which include, but are not limited to, any electronic product that can interact with a client via a keyboard, mouse, remote control, touchpad, or voice control device, such as personal computers, tablet computers, smartphones, and digital cameras.

[0075] It should be noted that electronic device 30 is only an example. Other existing or future electronic products that are suitable for this application should also be included within the scope of protection of this application and are incorporated herein by reference.

[0076] In some embodiments, at least one communication bus 33 is configured to enable communication between the memory 31 and at least one processor 32, etc.

[0077] Although not shown, electronic device 30 may also include a power supply (such as a battery) to power various components. Preferably, the power supply can be logically connected to at least one processor 32 via a power management device, thereby enabling functions such as charging, discharging, and power consumption management through the power management device. The power supply may also include one or more DC or AC power supplies, recharging devices, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components. Electronic device 30 may also include various sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be described in detail here.

[0078] In some embodiments, the memory 31 stores a computer program that, when executed by at least one processor 32, implements all or part of the steps in a message processing method. The memory 31 includes read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, disk storage, magnetic tape storage, or any other computer-readable medium capable of carrying or storing data.

[0079] Furthermore, the computer-readable storage medium may primarily include a program storage area and a data storage area, wherein the program storage area may store the operating system, an application program required for at least one function, etc.; and the data storage area may store data created based on the use of the electronic device 30, etc.

[0080] In some embodiments, at least one processor 32 is the control unit of the electronic device 30, connecting various components of the electronic device 30 via various interfaces and lines. It executes programs or modules stored in the memory 31 and calls data stored in the memory 31 to perform various functions and process data. For example, when at least one processor 32 executes a computer program stored in the memory, it implements all or part of the steps of the message processing method in this embodiment; or it implements all or part of the functions of the message processing device. At least one processor 32 may be composed of integrated circuits, such as a single-packaged integrated circuit or multiple integrated circuits with the same or different functions, including combinations of one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips.

[0081] The integrated unit implemented as a software functional module described above can be stored in a computer-readable storage medium. This software functional module, stored in a storage medium, includes several instructions to cause an electronic device (which may be a personal computer, electronic device, or network device, etc.) or processor to execute portions of the methods of the various embodiments of this application.

[0082] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and other division methods may be used in actual implementation.

[0083] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical units; they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0084] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in the form of hardware plus software functional modules.

[0085] It will be apparent to those skilled in the art that this application is not limited to the details of the exemplary embodiments described above, and that it can be implemented in other specific forms without departing from the spirit or essential characteristics of this application. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of this application is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be embraced within this application. No reference numerals in the claims should be construed as limiting the scope of the claims. Furthermore, it is clear that the word "comprising" does not exclude other elements or, and the singular does not exclude the plural. Multiple elements or devices recited in the specification may also be implemented by a single element or device through software or hardware. The terms "first," "second," etc., are used to indicate names and do not indicate any particular order.

[0086] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application and are not intended to limit it. Although this application has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of this application without departing from the spirit and scope of the technical solutions of this application.

Claims

1. A message processing method applied to a third-party thread, characterized in that, The third-party thread communicates with both the producer thread and the consumer thread, including: In response to the message write instruction for the target event by the production thread, the counter value in the counter corresponding to the target event is obtained; wherein, there is an association between the target event and the write code, the production thread obtains the write code associated with the target event and fills the write code into the message write instruction; the message write instruction includes the name of the target event, the write time corresponding to the target event, and the write code; After the updated value corresponding to the target event is written into the counter, the counter value is updated based on the updated value; In response to the message read instruction from the consumer thread to the counter, the counter value corresponding to the counter is read to the consumer thread so that the consumer thread determines that the target event has occurred based on the counter value corresponding to the counter. This includes: reading the counter value corresponding to the counter to the consumer thread so that the consumer thread obtains preset mask information corresponding to each preset event; performing logical AND processing on each preset mask information and the counter value corresponding to the counter to obtain a logical result corresponding to each preset mask information; and determining that the logical result is a non-zero target mask information; and determining the event corresponding to the target mask information as the target event based on a pre-set mapping relationship between mask information and events.

2. The message processing method as described in claim 1, characterized in that, Before obtaining the counter value in the counter corresponding to the target event, the method further includes: Iterate through the first mapping relationship between pre-set events and counters to determine the counter corresponding to the target event.

3. The message processing method as described in claim 1, characterized in that, The initial value of the counter is 0.

4. The message processing method as described in claim 1, characterized in that, The step of updating the counter value based on the updated value includes: When both the updated value and the counter value are binary, the updated counter value is calculated according to the binary calculation method.

5. The message processing method as described in claim 1, characterized in that, After reading the counter value corresponding to the counter to the consumer thread in response to the message read instruction of the consumer thread for the counter, the method further includes: Set the counter to 0.

6. The message processing method as described in claim 1, characterized in that, The method further includes: Obtain the number of binary bits corresponding to the counter; The preset number of bytes is determined based on the number of binary bits; Based on the settings information, establish a mapping relationship between the byte space and the preset event.

7. An electronic device, characterized in that, The electronic device includes a processor that executes a computer program stored in a memory to implement the message processing method as described in any one of claims 1 to 6.

8. A computer-readable storage medium storing a computer program thereon, characterized in that, When the computer program is executed by a processor, it implements the message processing method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Message processing method and system, computing device and readable storage medium

    CN115840654A

  • Lockless management of immutable objects by multi-threaded processes using multiple counters

    US11561823B1