Task processing method, device, equipment and medium
By establishing a linked list of delayed tasks and non-delay tasks in the IoT metering device and performing linked list task processing operations when the task expires, the problem of coupling between functional modules is solved, and decoupling and debugging between functional modules is achieved.
Patent Information
- Application Number
- CN202411675758.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-04-08
AI Technical Summary
In chips that have not been introduced into the operating system, when multiple functions are implemented through programming, it will lead to serious coupling between functional modules on the software, which will lead to very complex function implementation and debugging.
By establishing a linked list for delayed tasks and non-delay tasks, the delayed tasks are arranged in the order of delayed expiration time from short to long, and performing linked list task processing operations when the task expires, decoupling between different functional modules is achieved.
The callback function of the task is executed by traversing the linked list, which realizes decoupling between different functional modules, simplifies the function implementation and debugging process, and reduces the workload.
Smart Images

Figure CN119781911A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and more specifically, to a task processing method, device, equipment and medium. Background Art
[0002] IoT metering devices such as water meters and gas meters are relatively complex precision metering devices, usually including flow measurement, LCD display, wireless communication (such as 4G / NB), RTC, tariff statistics, valve control, software upgrade and other functions. When the above functions are implemented by programming in a chip without an operating system, it usually leads to serious coupling between functional modules in the software, which in turn makes the function implementation and debugging very complicated. A small change in requirements will trigger other changes, resulting in a lot of workload. Summary of the invention
[0003] One object of the present application is to provide a new technical solution for task processing.
[0004] According to a first aspect of the present application, a task processing method is provided, comprising:
[0005] Establishing a first linked list and a second linked list respectively, wherein the first linked list is used to add delayed tasks arranged in order from short to long according to the delayed expiration time, and the second linked list is used to add non-delayed tasks;
[0006] Determine whether the first linked list is empty;
[0007] When the first linked list is not empty, determining whether the delayed task on the first node of the first linked list is expired;
[0008] When the delayed task on the first node of the first linked list expires, a linked list task processing operation is performed on the first linked list, and the step of determining whether the first linked list is empty is repeated, wherein the linked list task processing operation includes: extracting a corresponding task from the first node of the linked list, executing a callback function of the task corresponding to the first node to obtain an execution result, and deleting the first node;
[0009] When the first linked list is empty or the delayed task of the first node on the first linked list has not expired, determining whether the second linked list is empty;
[0010] When the second linked list is empty, repeating the step of determining whether the first linked list is empty;
[0011] In the case that the second linked list is not empty, the linked list task processing operation is performed on the second linked list, and the step of determining whether the second linked list is empty is repeated.
[0012] Optionally, the first linked list is used to add first delayed tasks arranged in order of delay expiration time from short to long and whose time base is a timer interrupt. When the first linked list is empty or the delayed task of the first node on the first linked list has not expired, before determining whether the second linked list is empty, the method further includes:
[0013] Establishing a third linked list, the third linked list is used to add second delayed tasks arranged in order from short to long according to the delay expiration time and having a time base of RTC interrupt;
[0014] The determining whether the second linked list is empty when the first linked list is empty or the delayed task of the first node on the first linked list has not expired includes:
[0015] When the first linked list is empty or the delayed task of the first node on the first linked list has not expired, determining whether the third linked list is empty;
[0016] When the third linked list is not empty, determining whether the delayed task on the first node of the third linked list is expired;
[0017] When the delayed task on the first node of the third linked list expires, performing a linked list task processing operation on the third linked list, and repeating the step of determining whether the third linked list is empty;
[0018] When the third linked list is empty or the delayed task of the first node on the third linked list has not expired, it is determined whether the second linked list is empty.
[0019] Optionally, the method further comprises:
[0020] For the target nodes in the first linked list, the second linked list, and the third linked list, establish an observer linked list corresponding to the target node;
[0021] Notify each node in the observer list of the execution result corresponding to the target node.
[0022] Optionally, after determining whether the first linked list is empty, the method further includes:
[0023] When the first linked list is empty, turning off the timer;
[0024] After the timer is turned off and the first delayed task is added to the first linked list, the timer is turned on.
[0025] Optionally, when the second linked list is empty, repeating the step of determining whether the first linked list is empty comprises:
[0026] When the second linked list is empty, determining the current running state of the processor according to the state information; the state information indicates whether there is a pending task holding a wakeup lock;
[0027] When the current running state is the awakening state and the second linked list is empty, repeating the step of determining whether the first linked list is empty;
[0028] When the current running state is a non-awakening state and a set awakening event occurs, the current running state is controlled to be an awakening state.
[0029] Optionally, the establishing the first linked list includes:
[0030] When an interruption triggered by the timer occurs, generating a first delayed task according to the interruption triggered by the timer;
[0031] The first delayed task is added to the first linked list according to the delayed expiration time of the first delayed task.
[0032] Optionally, the establishing the third linked list includes:
[0033] In the case where an interrupt triggered by the RTC occurs, generating a second delayed task according to the interrupt triggered by the RTC;
[0034] According to the delayed expiration time of the second delayed task, the second delayed task is added to the third linked list.
[0035] According to a second aspect of the present application, there is provided a task processing device, comprising:
[0036] An establishment module, used to establish a first linked list and a second linked list respectively, wherein the first linked list is used to add delayed tasks arranged in order from short to long according to the delay expiration time, and the second linked list is used to add non-delayed tasks;
[0037] A first determining module, used to determine whether the first linked list is empty;
[0038] A second determination module, used for determining whether the delayed task on the first node of the first linked list is due when the first linked list is not empty;
[0039] A first execution module, configured to, when the delayed task on the first node of the first linked list expires, execute a linked list task processing operation on the first linked list and repeat the step of determining whether the first linked list is empty, wherein the linked list task processing operation includes: extracting a corresponding task from the first node of the linked list, executing a callback function of the task corresponding to the first node to obtain an execution result, and deleting the first node;
[0040] A third determination module, configured to determine whether the second linked list is empty when the first linked list is empty or the delayed task of the first node on the first linked list has not expired;
[0041] a repeating module, configured to repeat the step of determining whether the first linked list is empty when the second linked list is empty;
[0042] The second execution module is used to execute the linked list task processing operation on the second linked list when the second linked list is not empty, and repeat the step of determining whether the second linked list is empty.
[0043] According to a third aspect of the present application, an electronic device is provided, the electronic device comprising the apparatus according to the second aspect;
[0044] Alternatively, the electronic device includes a memory and a processor, the memory is used to store computer instructions, and the processor is used to call the computer instructions from the memory to execute the method as described in any one of the first aspects.
[0045] According to a fourth aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the method according to any one of the first aspects is implemented.
[0046] The present application provides a task processing method, including: establishing a first linked list and a second linked list respectively, the first linked list is used to add delayed tasks arranged in order from short to long according to the delay expiration time, and the second linked list is used to add non-delayed tasks; determining whether the first linked list is empty; when the first linked list is not empty, determining whether the delayed task on the first node of the first linked list is expired; when the delayed task on the first node of the first linked list is expired, performing a linked list task processing operation on the first linked list, and repeating the step of determining whether the first linked list is empty, the linked list task processing operation includes: extracting the corresponding task from the first node of the linked list, executing the callback function of the corresponding task of the first node to obtain the execution result, and deleting the first node; when the first linked list is empty or the delayed task of the first node on the first linked list has not expired, determining whether the second linked list is empty; when the second linked list is empty, repeating the step of determining whether the first linked list is empty; when the second linked list is not empty, performing a linked list task processing operation on the second linked list, and repeating the step of determining whether the second linked list is empty. The callback function of the corresponding task is executed by traversing the linked list to realize the corresponding function, thus realizing the decoupling between different functional modules.
[0047] Other features and advantages of the present application will become apparent from the following detailed description of exemplary embodiments of the present application with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments of the application and, together with the description, serve to explain the principles of the application.
[0049] Figure 1 A hardware configuration of an electronic device for implementing a task processing method according to an embodiment of the present application is provided. Figure 1 ;
[0050] Figure 2 A flowchart of a task processing method according to an embodiment of the present application is provided. Figure 1 ;
[0051] Figure 3 It is a schematic diagram of the structure of a first linked list and a second linked list provided in an embodiment of the present application;
[0052] Figure 4 It is a structural schematic diagram of a first linked list, a second linked list, a third linked list and an observer linked list provided in an embodiment of the present application;
[0053] Figure 5 A flowchart of a task processing method according to an embodiment of the present application is provided. Figure 2 ;
[0054] Figure 6 It is a structural diagram of a task processing device provided according to an embodiment of the present application;
[0055] Figure 7 A hardware configuration of an electronic device for implementing a task processing method according to an embodiment of the present application is provided. Figure 2 . DETAILED DESCRIPTION
[0056] Various exemplary embodiments of the present application will now be described in detail with reference to the accompanying drawings. It should be noted that unless otherwise specifically stated, the relative arrangement of components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present application.
[0057] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present application, its application, or uses.
[0058] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered as part of the specification.
[0059] In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not limiting. Therefore, other examples of the exemplary embodiments may have different values.
[0060] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0061] Figure 1 A hardware configuration of an electronic device for implementing a task processing method according to an embodiment of the present application is provided. Figure 1 .
[0062] The electronic device 1000 can be an IoT meter device such as a water meter or a gas meter, and uses, for example, a cortex-m0 series chip as the main control MCU. The electronic device 1000 generally includes functions such as flow measurement, LCD display, wireless communication (such as 4G / NB), RTC, tariff statistics, valve control, and software upgrade.
[0063] The electronic device 1000 may include a processor 1100, a memory 1200, an interface device 1300, a communication device 1400, a display device 1500, an input device 1600, a speaker 1700, a microphone 1800, and the like. The processor 1100 may be a central processing unit CPU, a microprocessor MCU, and the like. The memory 1200 may include, for example, a ROM (read-only memory), a RAM (random access memory), a non-volatile memory such as a hard disk, and the like. The interface device 1300 may include, for example, a USB interface, a headphone interface, and the like. The communication device 1400 may, for example, be capable of wired or wireless communication. The display device 1500 may be, for example, a liquid crystal display screen, a touch display screen, and the like. The input device 1600 may include, for example, a touch screen, a button, and the like. The user may input / output voice information through the speaker 1700 and the microphone 1800.
[0064] Despite Figure 1 Multiple devices are shown for the electronic device 1000, but the present application may only involve some of the devices, for example, the electronic device 1000 only involves the memory 1200 and the processor 1100.
[0065] In the embodiment of the present application, the memory 1200 of the electronic device 1000 is used to store instructions, and the instructions are used to control the processor 1100 to execute the task processing method provided in the embodiment of the present application.
[0066] In the above description, the technician can design instructions according to the scheme disclosed in this application. How instructions control the processor to operate is well known in the art, so it will not be described in detail here.
[0067] The present application provides a task processing method, which is applied to Figure 1 The electronic equipment shown. Figure 2As shown, the method includes the following steps S2100 to S2700.
[0068] Step S2100, establishing a first linked list and a second linked list respectively.
[0069] The first linked list is used to add delayed tasks arranged in order from short to long according to the delayed expiration time, and the second linked list is used to add non-delayed tasks.
[0070] Taking the example of an electronic device that measures the flow of water or gas meters and performs flow measurement every 2 seconds, the specific implementation of establishing the first linked list in the above step S2100 is as follows: establish an empty linked list or a linked list with only a sentinel node (in this embodiment, the sentinel node is not recorded as the first node of the linked list) in accordance with the traditional linked list establishment method, recorded as the first linked list; when the event corresponding to the flow metering occurs, establish a task with a delay of 2 seconds, recorded as a delayed task, and add the delayed task to the first node of the first linked list. Similarly, the second task linked list can also be established in the same way. The difference from the first task linked list is that the tasks added to the second task linked list are non-delayed tasks.
[0071] In one example, taking the delayed tasks as delayed task A, delayed task B and delayed task C, if the delay of delayed task A arrives first, followed by delayed task C, and the delay of delayed task B arrives last, then the first node is created on the first linked list and delayed task A is added to the first node, the second node is created on the first linked list and delayed task C is added to the first node, and the third node is created on the first linked list and delayed task B is added to the first node. Furthermore, when a new delayed task D is created, and the delay of delayed task D arrives later than delayed task C but earlier than delayed task B, a third node is created on the first linked list and delayed task D is added to the third node, and the node where delayed task B is located is modified to the fourth node.
[0072] In one example, the first linked list and the second linked list may be as follows Figure 3 As shown, Figure 3 In the example, the first linked list includes n nodes, each node has a corresponding delayed task added, and the second linked list includes n nodes, each node has a corresponding non-delay task added. It can be understood that since the execution order of the tasks on the linked list is executed in sequence from the first node of the linked list, the delayed tasks on the first linked list are executed in sequence: delayed task 1, delayed task 2, ..., delayed task n. And, the non-delay tasks on the second linked list are executed in sequence: non-delay task 1, non-delay task 2, ..., non-delay task n.
[0073] Step S2200, determining whether the first linked list is empty.
[0074] In this embodiment, it is first determined whether the first linked list is empty. If it is not empty, it means that there are delayed tasks to be processed on the first linked list, and the following step S2300 is executed. If it is empty, it means that there are no delayed tasks to be processed on the first linked list, and the following step S2500 is executed.
[0075] Step S2300: If the first linked list is not empty, determine whether the delayed task on the first node of the first linked list has expired. If yes, execute device S00,
[0076] When the first linked list is not empty, it is continued to determine whether the delayed task on the first node of the first linked list has expired. In one embodiment, timing can be performed by a timer inside the electronic device, such as a low-power timer or RTC, and based on the timing, it is determined whether the delayed task on the first node of the first linked list has expired. For example, taking flow metering every 2 seconds as an example, after the delayed task on the first node of the first linked list is established, when the timer reaches 2 seconds, it is determined that the delayed task on the first node of the first linked list has expired. On the contrary, when the timer does not reach 2 seconds, it is determined that the delayed task on the first node of the first linked list has not expired.
[0077] It can be understood that since the delayed tasks added to the first linked list are arranged in order from short to long according to the delay expiration time, when the delayed task on the first node of the first linked list has not expired, the delayed tasks on the non-first nodes of the first linked list have not expired either.
[0078] Step S2400, when the delayed task on the first node of the first linked list expires, the linked list task processor operation is performed on the first linked list, and the step of determining whether the first linked list is empty is repeated.
[0079] The linked list task processing operation includes: extracting the corresponding task from the first node of the linked list, executing the callback function of the task corresponding to the first node to obtain the execution result, and deleting the first node.
[0080] In this embodiment, when the delayed task on the first node of the first linked list expires, it means that the delayed task on the first node of the first linked list needs to be executed at the current moment, and at this time, the linked list task processing operation is performed for the first linked list. Specifically, the corresponding task is extracted from the first node of the first linked list, and the callback function of the task corresponding to the first node is executed to execute the result. Since the task corresponding to the first node has been executed at this time, the first node needs to be deleted at this time. On this basis, the first node of the first linked list is updated. Further, the above step S2200 is repeated to realize the traversal of the nodes on the first linked list and ensure the timely execution of the delayed task on the first linked list.
[0081] by Figure 3For example, when delayed task 1 is the task corresponding to the first node on the first linked list, after delay task 1 is extracted from the first node on the first linked list, the callback function corresponding to delay task 1 is executed to obtain the execution result, and the first node corresponding to delay task 1 is deleted. At this time, the node corresponding to delay task 2 becomes the new first node on the first linked list.
[0082] Step S2500, when the first linked list is empty or the delayed task of the first node on the first linked list has not expired, determine whether the second linked list is empty.
[0083] In this embodiment, when the first linked list is empty or the delayed task of the first node on the first linked list has not expired, it means that there is no delayed task to be executed on the first linked list at the current moment. At this time, it is determined whether the second linked list is empty.
[0084] Step S2600, when the second linked list is empty, repeat the step of checking whether the first linked list is empty.
[0085] In this embodiment, when the second linked list is empty, it means that there is no non-delay task to be executed on the second linked list at the current moment. At this time, the above step S2200 is repeated to perform a new cycle.
[0086] Step S2700, when the second linked list is not empty, performing a linked list task processing operation on the second linked list, and repeating the step of determining whether the second linked list is empty.
[0087] In this embodiment, when the second linked list is not empty, it means that there is a non-delay task to be executed on the second linked list at the current moment. At this time, the linked list task processing operation is performed on the second linked list. Specifically, the corresponding task is extracted from the first node of the second linked list, and the callback function of the task corresponding to the first node is executed to execute the result. Since the task corresponding to the first node has been executed at this time, the first node needs to be deleted at this time. On this basis, the first node of the second linked list is updated. Further, the above step S2500 is repeated to realize the traversal of the nodes on the second linked list and ensure the timely execution of the non-delay tasks on the second linked list.
[0088] by Figure 3 For example, when non-delay task 1 is the task corresponding to the first node on the second linked list, after non-delay task 1 is extracted from the first node on the second linked list, the callback function corresponding to non-delay task 1 is executed to obtain the execution result, and the first node corresponding to non-delay task 1 is deleted. At this time, the node corresponding to non-delay task 2 becomes the new first node on the second linked list.
[0089] Based on the above steps S2100 to S2700, the callback function of the corresponding task is executed by traversing the linked list to realize the corresponding function, thereby realizing the decoupling between different functional modules.
[0090] In summary, the present application provides a task processing method, including: establishing a first linked list and a second linked list respectively, the first linked list is used to add delayed tasks arranged in order from short to long according to the delay expiration time, and the second linked list is used to add non-delay tasks; determining whether the first linked list is empty; when the first linked list is not empty, determining whether the delayed task on the first node of the first linked list is expired; when the delayed task on the first node of the first linked list is expired, performing a linked list task processing operation on the first linked list, and repeating the step of determining whether the first linked list is empty, the linked list task processing operation includes: extracting the corresponding task from the first node of the linked list, executing the callback function of the corresponding task of the first node to obtain the execution result, and deleting the first node; when the first linked list is empty or the delayed task of the first node on the first linked list has not expired, determining whether the second linked list is empty; when the second linked list is empty, repeating the step of determining whether the first linked list is empty; when the second linked list is not empty, performing a linked list task processing operation on the second linked list, and repeating the step of determining whether the second linked list is empty. The callback function of the corresponding task is executed by traversing the linked list to realize the corresponding function, thus realizing the decoupling between different functional modules.
[0091] In one embodiment of the present application, the first linked list is specifically used to add a first delayed task arranged in order from short to long according to the delay expiration time and the time base is a timer interrupt. On this basis, the task processing method provided by the present application further includes the following step S2510 before the above step S2500.
[0092] Step S2510, establishing a third linked list.
[0093] Among them, the third linked list is used to add the second delayed tasks which are arranged in order from short to long according to the delay expiration time and whose time base is the RTC interrupt.
[0094] Based on the above content, in one embodiment of the present application, the establishment of the first linked list in the above step S2100 is specifically implemented through the following steps S2110 and S2111.
[0095] Step S2110: when an interruption triggered by a timer occurs, a first delayed task is generated according to the interruption triggered by the timer.
[0096] Step S2111: adding the first delayed task to the first linked list according to the delayed expiration time of the first delayed task.
[0097] In this embodiment, when a timer interrupt occurs, an interrupt processing function corresponding to the current timer interrupt will be determined. The interrupt processing function is responsible for creating a corresponding first delayed task and adding the first delayed task to the first linked list.
[0098] And, similarly, the above step S2510 is specifically implemented through the following steps S2510-1 and S2510-2.
[0099] Step S2510-1: when an interruption triggered by the RTC occurs, generate a second delayed task according to the interruption triggered by the RTC.
[0100] Step S2510-2: Add the second delayed task to the third linked list according to the delayed expiration time of the second delayed task.
[0101] It should be noted that the process of establishing the third linked list is similar to that of establishing the first linked list, the only difference being that the delay time of the second delayed task on the third linked list is in the order of seconds.
[0102] In one example, the first linked list, the second linked list, and the third linked list are as follows: Figure 4 As shown, Figure 4 In the figure, the first linked list includes n nodes, each node has a corresponding first delayed task added, the third linked list includes n nodes, each node has a corresponding second delayed task added, and the second linked list includes n nodes, each node has a corresponding non-delay task added.
[0103] The time base of the timer interrupt is usually in the millisecond level, and the time base of the RTC interrupt is usually in the second level. Therefore, the delay task with a delay time of milliseconds is recorded as the first delay task and added to the first linked list, and the delay task with a delay time of seconds is recorded as the second delay task and added to the third linked list. In this way, the first linked list can be managed by the timer, and the third linked list can be managed by multiplexing the RTC, thereby saving a timer in the electronic device, which can reduce the hardware cost and power consumption of the electronic device.
[0104] Based on the above step S2510, the above step S2500 is specifically implemented through the following steps S2520 to S2523.
[0105] Step S2520: When the first linked list is empty or the delayed task of the first node on the first linked list has not expired, determine whether the third linked list is empty.
[0106] In this embodiment, since the first linked list is used to add the first delay task which is arranged in order from short to long according to the delay expiration time and whose time base is the timer interrupt, and the third linked list is used to add the second delay task which is arranged in order from short to long according to the delay expiration time and whose time base is the RTC interrupt, the time base of the timer interrupt is usually at the millisecond level, and the time base of the RTC interrupt is usually at the second level, therefore, when the first linked list is empty or the delay task of the first node on the first linked list has not expired, it is determined whether the third linked list is empty.
[0107] Step S2521, when the third linked list is not empty, determine whether the delayed task on the first node of the third linked list has expired.
[0108] The specific implementation of the above step S2521 is similar to that of the above step S2300, and will not be repeated here.
[0109] Step S2522, when the delayed task on the first node of the third linked list expires, perform a linked list task processing operation on the third linked list, and repeat the step of determining whether the third linked list is empty.
[0110] The specific implementation of the above step S2522 is similar to that of the above step S2400, and will not be repeated here.
[0111] Step S2523, when the third linked list is empty or the delayed task of the first node on the third linked list has not expired, determine whether the second linked list is empty.
[0112] When the third linked list is empty or the delayed task of the first node on the third linked list has not expired, it means that there is no delayed task to be executed on the third linked list at the current moment. At this time, it is determined whether the second linked list is empty.
[0113] In combination with the above embodiment, the task processing method provided in the present application further includes the following step S2210 and step S2211 after the above step S2200.
[0114] Step S2210, when the first linked list is empty, turn off the timer.
[0115] In this embodiment, when the first linked list is empty, it means that there is no first delay task timed by the timer interrupt. At this time, the timer is turned off, which can reduce the power consumption of the electronic device.
[0116] Step S2211, after the timer is turned off and the first delayed task is added to the first linked list, the timer is turned on.
[0117] After the timer is turned off, if the first delayed task is added to the first linked list, it means that there is a first delayed task that is timed by the timer interrupt. At this time, the timer is turned on to realize timing.
[0118] In one embodiment of the present application, the task processing method provided by the present application also includes the following steps S2800 and S2900.
[0119] Step S2800, corresponding to the target nodes in the first linked list, the second linked list and the third linked list, establish an observer linked list corresponding to the target node.
[0120] Step S2900, notifying each node in the observer list of the execution result corresponding to the target node.
[0121] In this embodiment, the target node is a node for which the observer needs to obtain the execution result obtained by the callback function of executing the task on the target node.
[0122] In one example, the observer list can be Figure 4 As shown, Figure 4 The following is an example in which the observer list includes n observers.
[0123] In one example, when a module needs to obtain flow data as an observer, such as a communication module obtaining flow data for uploading to the main station server (i.e., remote meter reading), the communication module will be coupled with the flow metering module. Among them, the flow metering module is the callback function of the target node corresponding task. The flow metering module is the core module of the meter (the core function of the meter is metering), which is usually not modified, while other modules may change, such as the communication channel is changed from 4G to MBUS. On this basis, the flow metering module is used as a subject, and the subject provides an interface for monitoring flow data to other modules (such as communication modules) that care about flow data. Other modules that care about flow data only need to register to this interface. When the flow data changes, other modules that care about flow data will receive a notification. In this embodiment, the module that registers the interface for monitoring flow data is added to the observer list of flow metering changes. When the flow metering module updates the flow data, the callback function of the observer in the observer list is called in turn, and the flow data is passed in as a parameter. In this way, both the communication between modules and the decoupling between the flow metering module and other modules are realized. Even if more other modules that need to obtain flow data are added or reduced, the flow metering module does not need to be modified.
[0124] In one embodiment of the present application, the above step S2600 is specifically implemented through the following steps S2610 to S2612.
[0125] Step S2610, when the second linked list is empty, determine the operating state of the processor according to the state information.
[0126] The status information indicates whether there is a pending task holding a wakeup lock.
[0127] In this embodiment, there is no limitation on the linked list where the tasks to be processed are located, and the tasks to be processed can be located on any linked list.
[0128] When the state information indicates that there is a pending task holding a wakeup lock, it is determined that the current running state of the processor is a wakeup state.
[0129] If the state information indicates that there is no pending task holding the wakeup lock, it is determined that the current state of the processor is a non-awakening state, which is any of a light sleep state and a deep sleep state. On this basis, if there is a pending task holding the lightsleep lock or a pending task holding the deepsleep lock, it is determined that there is no pending task holding the wakeup lock.
[0130] In one example, the processor is specifically an MCU.
[0131] Step S2611, when the current running state is the awake state and the second linked list is empty, repeat the step of determining whether the first linked list is empty.
[0132] When the current state is the awake state, it means that the processor has not entered the sleep state. At this time, the processor can be operated to execute the step of repeating the step of determining whether the first linked list is empty when the second linked list is empty.
[0133] Step S2612, when the current running state is a non-awakening state and a set awakening event occurs, controlling the current running state to be an awakening state.
[0134] Corresponding to the above step S2611, when the current state is a non-awakening state, it means that the processor enters a light sleep or deep sleep state. At this time, the processor cannot run to execute the step of repeating the step of determining whether the first linked list is empty when the second linked list is empty. On this basis, when a wake-up event occurs, the current running state is controlled to be a wake-up state. The wake-up event is set to a time that can wake up the processor, such as an RTC interrupt event or a timer interrupt event.
[0135] Based on the above embodiments, Figure 5 As shown, a task processing method provided by the present application includes the following steps S5100 to S5900.
[0136] Step S5100, establishing a first linked list, a second linked list and a third linked list;
[0137] Step S5200, determining whether the first linked list is empty, if yes, executing the following step S5500, if no, executing the following step S5300;
[0138] Step S5300, determining whether the first delayed task corresponding to the first node of the first linked list has expired, if yes, executing the following step S5400, if no, executing the following step S5500;
[0139] Step S5400, executing the linked list task processing operation for the first linked list, and repeating the above step S5200;
[0140] Step S5500, determining whether the third linked list is empty, if yes, executing the following step S5800, if no, executing the following step S5600;
[0141] Step S5600, determining whether the second delayed task corresponding to the first node of the third linked list has expired, if yes, executing the following step S5700, if no, executing the following step S5800;
[0142] Step S5700, performing a linked list task processing operation on the third linked list, and repeating the above step S5500;
[0143] Step S5800, determining whether the second linked list is empty, if so, repeating the above step S5200, if so, executing the following step S5900;
[0144] Step S5900, executing the linked list task processing operation for the second linked list, and repeating the above step S5800.
[0145] The present application also provides a task processing device 600, such as Figure 6 As shown, including:
[0146] Establishing module 610, used to establish a first linked list and a second linked list respectively, the first linked list is used to add delayed tasks arranged in order from short to long according to the delayed expiration time, and the second linked list is used to add non-delayed tasks;
[0147] A first determination module 620, configured to determine whether the first linked list is empty;
[0148] A second determination module 630 is used to determine whether the delayed task on the first node of the first linked list is due when the first linked list is not empty;
[0149] A first execution module 640 is used to, when the delayed task on the first node of the first linked list expires, perform a linked list task processing operation on the first linked list and repeat the step of determining whether the first linked list is empty, wherein the linked list task processing operation includes: extracting a corresponding task from the first node of the linked list, executing a callback function of the task corresponding to the first node to obtain an execution result, and deleting the first node;
[0150] A third determination module 650, configured to determine whether the second linked list is empty when the first linked list is empty or the delayed task of the first node on the first linked list has not expired;
[0151] A repeating module 660, configured to repeat the step of determining whether the first linked list is empty when the second linked list is empty;
[0152] The second execution module 670 is used to execute the linked list task processing operation on the second linked list when the second linked list is not empty, and repeat the step of determining whether the second linked list is empty.
[0153] In one embodiment of the present application, the first linked list is used to add a first delayed task arranged in order from short to long according to the delay expiration time and the time base is a timer interrupt. In this embodiment, the establishment module 610 is also used to: establish a third linked list, the third linked list is used to add a second delayed task arranged in order from short to long according to the delay expiration time and the time base is an RTC interrupt;
[0154] In this embodiment, the third determination module 650 is specifically used to: determine whether the third linked list is empty when the first linked list is empty or the delayed task of the first node on the first linked list has not expired;
[0155] When the third linked list is not empty, determining whether the delayed task on the first node of the third linked list is expired;
[0156] When the delayed task on the first node of the third linked list expires, performing a linked list task processing operation on the third linked list, and repeating the step of determining whether the third linked list is empty;
[0157] When the third linked list is empty or the delayed task of the first node on the third linked list has not expired, it is determined whether the second linked list is empty.
[0158] In one embodiment of the present application, the establishing module 610 is further used to: establish an observer linked list corresponding to the target node in the first linked list, the second linked list, and the third linked list;
[0159] In this embodiment, the task processing device 600 further includes:
[0160] The notification module is used to notify each node in the observer linked list of the execution result corresponding to the target node.
[0161] In one embodiment of the present application, the task processing device 600 further includes:
[0162] A control module, configured to turn off the timer when the first linked list is empty;
[0163] After the timer is turned off and the first delayed task is added to the first linked list, the timer is turned on.
[0164] In one embodiment of the present application, the repeating module 660 is specifically used to determine the current running state of the processor according to the state information when the second linked list is empty; the state information indicates whether there is a pending task holding a wakeup lock;
[0165] When the current running state is the awakening state and the second linked list is empty, repeating the step of determining whether the first linked list is empty;
[0166] When the current running state is a non-awakening state and a set awakening event occurs, the current running state is controlled to be an awakening state.
[0167] In one embodiment of the present application, the establishing module 610 is specifically used for:
[0168] When an interruption triggered by the timer occurs, generating a first delayed task according to the interruption triggered by the timer;
[0169] The first delayed task is added to the first linked list according to the delayed expiration time of the first delayed task.
[0170] In one embodiment of the present application, the establishing module 610 is specifically used for:
[0171] In the case where an interrupt triggered by the RTC occurs, generating a second delayed task according to the interrupt triggered by the RTC;
[0172] According to the delayed expiration time of the second delayed task, the second delayed task is added to the third linked list.
[0173] The present application also provides an electronic device, which includes any one of the task processing devices 600 provided in the above device embodiments;
[0174] Or, if Figure 7As shown, the electronic device 700 includes a memory 710 and a processor 720, wherein the memory 710 is used to store computer instructions, and the processor 720 is used to call the computer instructions from the memory 710 to execute any task processing method provided in the above method embodiments.
[0175] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, it implements any one of the task processing methods provided in the above method embodiments.
[0176] The present application may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present application.
[0177] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.
[0178] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0179] The computer program instructions for performing the operation of the present application can be assembler instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions can be executed completely on a user's computer, partially on a user's computer, executed as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet). In some embodiments, by using the state information of a computer-readable program instruction to personalize an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA) or a programmable logic array (PLA), the electronic circuit can execute a computer-readable program instruction, thereby realizing various aspects of the present application.
[0180] Various aspects of the present application are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present application. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0181] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0182] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0183] The flowchart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a part of a module, program segment or instruction, and the part of the module, program segment or instruction contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart can be implemented by a dedicated hardware-based system that performs the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions. It is well known to those skilled in the art that it is equivalent to implement it by hardware, implement it by software, and implement it by combining software and hardware.
[0184] The embodiments of the present application have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein. The scope of the present application is defined by the appended claims.
Claims
1. A task processing method, characterized in that: include: Establishing a first linked list and a second linked list respectively, wherein the first linked list is used to add delayed tasks arranged in order from short to long according to the delayed expiration time, and the second linked list is used to add non-delayed tasks; Determine whether the first linked list is empty; When the first linked list is not empty, determining whether the delayed task on the first node of the first linked list is expired; When the delayed task on the first node of the first linked list expires, a linked list task processing operation is performed on the first linked list, and the step of determining whether the first linked list is empty is repeated, wherein the linked list task processing operation includes: extracting a corresponding task from the first node of the linked list, executing a callback function of the task corresponding to the first node to obtain an execution result, and deleting the first node; When the first linked list is empty or the delayed task of the first node on the first linked list has not expired, determining whether the second linked list is empty; When the second linked list is empty, repeating the step of determining whether the first linked list is empty; In the case that the second linked list is not empty, the linked list task processing operation is performed on the second linked list, and the step of determining whether the second linked list is empty is repeated.
2. The method according to claim 1, characterized in that The first linked list is used to add first delayed tasks arranged in order of delay expiration time from short to long and whose time base is a timer interrupt. When the first linked list is empty or the delayed task of the first node on the first linked list has not expired, before determining whether the second linked list is empty, the method further includes: Establishing a third linked list, the third linked list is used to add second delayed tasks arranged in order from short to long according to the delay expiration time and having a time base of RTC interrupt; The determining whether the second linked list is empty when the first linked list is empty or the delayed task of the first node on the first linked list has not expired includes: When the first linked list is empty or the delayed task of the first node on the first linked list has not expired, determining whether the third linked list is empty; When the third linked list is not empty, determining whether the delayed task on the first node of the third linked list is expired; When the delayed task on the first node of the third linked list expires, performing a linked list task processing operation on the third linked list, and repeating the step of determining whether the third linked list is empty; When the third linked list is empty or the delayed task of the first node on the third linked list has not expired, it is determined whether the second linked list is empty.
3. The method according to claim 2, characterized in that The method further comprises: For the target nodes in the first linked list, the second linked list, and the third linked list, establish an observer linked list corresponding to the target node; Notify each node in the observer list of the execution result corresponding to the target node.
4. The method according to claim 2, characterized in that: After determining whether the first linked list is empty, the method further includes: When the first linked list is empty, turning off the timer; After the timer is turned off and the first delayed task is added to the first linked list, the timer is turned on.
5. The method according to claim 1, characterized in that When the second linked list is empty, repeating the step of determining whether the first linked list is empty comprises: When the second linked list is empty, determining the current running state of the processor according to the state information; the state information indicates whether there is a pending task holding a wakeup lock; When the current running state is the awakening state and the second linked list is empty, repeating the step of determining whether the first linked list is empty; When the current running state is a non-awakening state and a set awakening event occurs, the current running state is controlled to be an awakening state.
6. The method according to claim 2, characterized in that The step of establishing the first linked list comprises: When an interruption triggered by the timer occurs, generating a first delayed task according to the interruption triggered by the timer; The first delayed task is added to the first linked list according to the delayed expiration time of the first delayed task.
7. The method according to claim 2, characterized in that The step of establishing the third linked list comprises: In the case where an interrupt triggered by the RTC occurs, generating a second delayed task according to the interrupt triggered by the RTC; According to the delayed expiration time of the second delayed task, the second delayed task is added to the third linked list.
8. A task processing device, characterized in that: include: An establishment module, used to establish a first linked list and a second linked list respectively, wherein the first linked list is used to add delayed tasks arranged in order from short to long according to the delay expiration time, and the second linked list is used to add non-delayed tasks; A first determining module, used to determine whether the first linked list is empty; A second determination module, used for determining whether the delayed task on the first node of the first linked list is due when the first linked list is not empty; A first execution module, configured to, when the delayed task on the first node of the first linked list expires, execute a linked list task processing operation on the first linked list and repeat the step of determining whether the first linked list is empty, wherein the linked list task processing operation includes: extracting a corresponding task from the first node of the linked list, executing a callback function of the task corresponding to the first node to obtain an execution result, and deleting the first node; A third determination module, configured to determine whether the second linked list is empty when the first linked list is empty or the delayed task of the first node on the first linked list has not expired; a repeating module, configured to repeat the step of determining whether the first linked list is empty when the second linked list is empty; The second execution module is used to execute the linked list task processing operation on the second linked list when the second linked list is not empty, and repeat the step of determining whether the second linked list is empty.
9. An electronic device, characterized in that: The electronic device comprises the apparatus as claimed in claim 8; Alternatively, the electronic device includes a memory and a processor, the memory is used to store computer instructions, and the processor is used to call the computer instructions from the memory to execute the method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, which implements the method according to any one of claims 1 to 7 when executed by a processor.