Timer management method, device, equipment and storage medium
By maintaining a timer linked list for each task in the embedded system and querying the linked list before entering the waiting period of transaction triggering, the remaining time of the timer is determined as the waiting time, the data access conflict problem during the execution of the timer task is solved, and the timer is triggered on time and efficient management is realized.
Patent Information
- Application Number
- CN202111423621.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-26
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2041-11-26
AI Technical Summary
In embedded systems, data access conflicts may occur due to timer callback functions when the timer task executes the timer callback function.
After processing the transaction of the target task and entering the transaction waiting period, query the timer list of the target task, determine the remaining time of the timer that has not timed out, and use it as the maximum waiting period of the transaction waiting period.
Avoid data access conflicts and ensure that the timer can trigger operation on time, improving the accuracy and efficiency of timer management.
Smart Images

Figure CN114153568B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of embedded systems, and in particular to a timer management method, device, equipment and storage medium. Background Art
[0002] Timing is an essential function in embedded systems. In current embedded systems, a separate timing task is usually set to handle software timers. Other tasks register the timer callback function to the timing task through the system interface to add timers. When the timer timeout is reached, the timer callback function is executed by the timer task.
[0003] Since timers are uniformly executed in scheduled tasks, when a timer task executes a timer callback function to access data of other tasks, other tasks also need to read and write data, which will cause data access conflicts. Summary of the invention
[0004] The present application provides a timer management method, apparatus, device and storage medium to solve the technical problem of data access conflicts existing in timers through separate timer tasks.
[0005] In a first aspect, a timer management method is provided, comprising:
[0006] After processing the transaction of the target task and before entering the transaction waiting period of the target task, query the timer linked list of the target task, the transaction waiting period is the period of waiting for the transaction to be triggered, the timer linked list is used to manage the information of the timer of the target task, the information of the timer includes the transaction corresponding to the timer and the timeout period, and one task corresponds to one timer linked list;
[0007] In the case of finding a timer that has not timed out, determining the remaining timing duration of a target timer, where the target timer is the first timer that has not timed out found out;
[0008] The remaining timing duration is used as the maximum waiting duration of the transaction waiting period.
[0009] In this technical solution, after processing the transaction of the target task, before entering the period of waiting for the transaction to be triggered, by querying the timer chain list of the target task, and in the case of finding a timer that has not timed out in the timer chain list, the remaining timing duration of the fastest timed out timer found is determined, and the remaining timing duration of the fastest timed out timer is used as the maximum waiting duration of the transaction waiting period before entering the task waiting period. One task corresponds to one timer chain list, and each task can determine whether the timer has expired by querying its own timer chain list, and automatically execute the timer callback function when the timer expires. Since the operation of querying the timer is performed after processing the transaction and before entering the period of waiting for the transaction to be triggered, no data access conflict will be caused; in addition, when the fastest timed out timer is queried, the remaining timing duration of the fastest timed out timer is used as the maximum waiting duration of the period of waiting for the transaction to be triggered, so that the task can wake up from the period of waiting for the transaction to be triggered before the timer times out after entering the period of waiting for the transaction to be triggered, so as to process the timer in time and ensure that the timer in the timer chain list can be triggered and run on time.
[0010] In combination with the first aspect, in a possible implementation, the timers are arranged in ascending order according to the timeout time in the timer chain list; the querying of the timer chain list of the target task includes: starting from i=1, taking the i-th timer in the timer chain list as the current timer, and judging whether the current timer has timed out; the determining of the remaining timing duration of the target timer when a timer that has not timed out is queried includes: if the current timer has not timed out, determining the current timer as the target timer, and determining the remaining timing duration of the target timer; the executing of the transaction corresponding to the timed out timer when a timed out timer is queried includes: if the current timer has timed out, executing the transaction corresponding to the current timer, and taking the (i+1)th timer as the current timer, and executing the step of judging whether the current timer has timed out, until all the transactions corresponding to the timers in the timer chain list that have timed out are executed. By sequentially querying the timer chain list and executing the transactions corresponding to the timers, it can be ensured that each timer of the target task can run accurately.
[0011] In combination with the first aspect, in a possible implementation, the information of the timer also includes whether it is a periodically running timer; after the transaction corresponding to the current timer is executed, it also includes: if the current timer is a periodically running timer, determining the timeout time of the next timeout of the current timer, and inserting the current timer into the timer linked list according to the timeout time of the next timeout of the current timer. By adding the periodically running timer to the timer linked list, it can be ensured that the timer can run accurately according to the cycle.
[0012] In combination with the first aspect, in a possible implementation method, determining whether the current timer has timed out includes: if the timeout time of the current timer is less than or equal to the current time of the system, determining that the current timer has timed out; if the timeout time of the current timer is greater than the current time of the system, determining that the current timer has not timed out.
[0013] In combination with the first aspect, in a possible implementation manner, the method further includes: when there is no timer in the timer linked list, entering the transaction waiting period.
[0014] In combination with the first aspect, in a possible implementation manner, the method further includes: if the current timer times out and the current timer is a non-periodic timer, removing information of the current timer from the timer linked list.
[0015] In combination with the first aspect, in a possible implementation method, after entering the transaction waiting period, it also includes: when the pending transactions of the target task are obtained, the pending transactions are processed, and after the processing is completed, the step of querying the timer linked list of the target task is executed.
[0016] In a second aspect, a timer management device is provided, comprising:
[0017] A query module is used to query the timer linked list of the target task before entering the transaction waiting period of the target task after processing the transaction of the target task. The transaction waiting period is a period of waiting for the transaction to be triggered. The timer linked list is used to manage the information of the timer of the target task. The information of the timer includes the transaction corresponding to the timer and the timeout period. One task corresponds to one timer linked list;
[0018] An execution module, configured to execute a transaction corresponding to a timed-out timer when a timed-out timer is found;
[0019] A timeout duration determination module, used to determine the remaining timing duration of a target timer when a timer that has not timed out is found, wherein the target timer is the fastest timer found to have timed out;
[0020] A waiting time determination module is used to use the remaining timing time as the maximum waiting time of the transaction waiting period, enter the transaction waiting period, and when the time length of entering the transaction waiting period is greater than or equal to the maximum waiting time, wake up the query module to execute the step of querying the timer linked list of the target task.
[0021] In a third aspect, a computer device is provided, comprising a memory and one or more processors, wherein the one or more processors are used to execute one or more computer programs stored in the memory, and when the one or more processors execute the one or more computer programs, the computer device implements the timer management method of the first aspect.
[0022] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor executes the timer management method of the first aspect.
[0023] The present application can achieve the following technical effects: one task corresponds to one timer linked list, and each task can determine whether the timer has expired by querying its own timer linked list, and execute the timer callback function by itself when the timer expires. Since the operation of querying the timer is performed after the transaction is processed and before entering the period of waiting for the transaction to be triggered, no data access conflict will be caused. In addition, when the timer with the fastest timeout is queried, the remaining timing length of the timer with the fastest timeout is used as the maximum waiting time length of the period of waiting for the transaction to be triggered, so that the task can be awakened from the period of waiting for the transaction to be triggered before the timer times out after entering the period of waiting for the transaction to be triggered, so that the timer can be processed in time to ensure that the timer in the timer linked list can be triggered and run on time. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 A flowchart of a timer management method provided in an embodiment of the present application;
[0025] Figure 2 It is a structural diagram of a timer management device provided in an embodiment of the present application;
[0026] Figure 3 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0027] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0028] The technical solution of the present application can be applied to embedded systems, and can be specifically used for designing timers for various tasks in embedded systems.
[0029] The implementation principle of the present application is as follows: let each task that needs to create a timer (hereinafter referred to as the target task) manage its own timer, and the target task executes its own timer callback function (i.e., executes the transaction corresponding to the timer), wherein the target task manages its own timer through a timer chain list. After the target task handles its own transaction and before entering the transaction waiting period of the target task, the timer in the timer chain list is managed, and the transaction corresponding to the timer that has timed out in the timer chain list is executed in sequence, and the remaining timing duration of the timer with the fastest timeout in the timer chain list is used as the maximum remaining duration of the transaction waiting period. Since each task executes the callback function of its own timer by itself, and executes the callback function of the timer after handling its own transaction, it will not cause data access conflicts; since when the fastest timeout timer is queried, the remaining timing duration of the fastest timeout timer is used as the maximum waiting duration of the period of waiting for the transaction to be triggered, so that the task can wake up from the transaction waiting period before the timer times out after entering the period of waiting for the transaction to be triggered, so as to process the timer in time and ensure that the timer is triggered and run on time.
[0030] The technical solution of this application is described in detail below.
[0031] See also Figure 1 , Figure 1 A flowchart of a timer management method provided in an embodiment of the present application, which can be applied to embedded systems, such as Figure 1 As shown, the method comprises the following steps:
[0032] S101, after processing the transaction of the target task and before entering the transaction waiting period of the target task, query the timer linked list of the target task.
[0033] Among them, the target task can be any task in the embedded system, and the target task can be used to implement a specific function in the embedded system, such as LED light driving function, key detection function, etc., and is not limited to the description here. The transaction of the target task refers to the operations required to implement the function of the target task, such as processing received events or messages. For example, for an LED light task, the corresponding commands are to light up the n1th LED light, turn off the n2th LED light, make the n3th LED light flash, etc., then the transaction is to process these commands to light up the n1th LED light, turn off the n2th LED light, and make the n3th LED light flash.
[0034] The transaction waiting period of the target task is the period of waiting for the transaction to be triggered, which can be understood as the dormant period that the target task enters after executing a specific transaction. During the transaction waiting period of the target task, the target task can be in a dormant state and does not perform any operation.
[0035] Among them, the timer linked list of the target task is a linked list of information for managing the timer of the target task, wherein the information of the timer includes the transaction corresponding to the timer and the timeout time. In an embodiment of the present application, each task corresponds to a timer linked list, which is used to manage the information of the timer of each task. The timeout time refers to the timeout time of the timer, that is, the time required to execute the transaction corresponding to the timer.
[0036] In a feasible implementation, the timers of the target task are arranged in ascending order according to the timeout time in the timer chain list. By arranging the timers in ascending order according to the timeout time in the timer chain list, it can be ensured that the timers with earlier timeout time are executed first, so that the timers are triggered and run on time. Specifically, the timer chain list of the target task can be queried as follows:
[0037] A1. Starting from i=1, the i-th timer in the timer list of the target task is used as the current timer.
[0038] A2. Determine whether the current timer has timed out.
[0039] Specifically, the timeout time of the current timer can be compared with the current time of the system. If the timeout time of the current timer is less than or equal to the current time of the system, it is determined that the current timer has timed out; if the timeout time of the current timer is greater than the current time of the system, it is determined that the current timer has not timed out. The current time of the system can be the timing time of the embedded system. In a specific implementation, the current time of the system can be converted based on the number of ticks counted by the tick counter in the embedded system.
[0040] If the current timer has not timed out, the following step A3 is executed; if the current timer has timed out, the following step A4 is executed.
[0041] A3. Determine the current timer as the first timer that has not timed out, ie, the target timer, and execute subsequent steps S102 to S103.
[0042] A4. Execute the transaction corresponding to the current timer.
[0043] After the transaction corresponding to the current timer is executed, the information of the current timer may be removed from the timer linked list of the target task.
[0044] Optionally, if the current timer is a periodically running timer, the next timeout time of the current timer can also be determined, and the current timer is inserted into the timer chain list according to the next timeout time of the current timer. The next timeout time of the current timer is equal to the sum of the current timeout time of the current timer and the running cycle of the current timer.
[0045] Specifically, starting from j=1, the next timeout time of the current timer can be compared with the timeout time of the jth timer remaining in the timer chain list. If the next timeout time of the current timer is less than or equal to the timeout time of the jth timer remaining in the timer chain list, the current timer is inserted before the jth timer; if the next timeout time of the current timer is greater than the timeout time of the jth timer remaining in the timer chain list, j+1 is added to perform the step of comparing the next timeout time of the current timer with the timeout time of the jth timer remaining in the timer chain list; if the next timeout time of the current timer is greater than the timeout time of all the timers remaining in the timer chain list of the target task, the current timer is inserted into the end of the timer chain list of the target task. By adding the timer that runs periodically to the timer chain list, it can be ensured that the timer can run accurately according to the cycle.
[0046] A5. Determine whether the current timer is the last timer in the timer list.
[0047] If the current timer is the last timer in the timer list, the query of the timer list for the target task ends; if the current timer is not the last timer in the timer list, the (i+1)th timer is used as the current timer, and the process returns to execute step A2.
[0048] By querying the timer linked list in sequence, it can be ensured that each timer of the target task can be accurately triggered and run.
[0049] Optionally, if there is no timer in the timer linked list of the target task, the transaction waiting period is entered directly. It is understandable that the transaction waiting period is a permanent blocking wait until a message or event arrives to wake up the task. Optionally, if the feedback received when querying the timer linked list of the target task is the system maximum time (for example, the linked list query function returns the system maximum time (0xffffffff)), it means that there is no timer in the timer linked list of the target task, that is, the target task has not created a timer, and then the transaction waiting period is entered.
[0050] S102: When a timer that has not timed out is found, determine the remaining timing duration of a target timer, where the target timer is the fastest timer found to time out.
[0051] Here, the remaining timing duration of the target timer is equal to the difference between the timeout time of the target timer and the current time of the system. For the concepts of the timeout time of the target timer and the current time of the system, please refer to the relevant description of the aforementioned step S101.
[0052] S103: Use the remaining timing duration of the target timer as the maximum waiting duration of the transaction waiting period of the target task.
[0053] S104, entering the transaction waiting period of the target task.
[0054] When the duration of entering the transaction waiting period is greater than or equal to the maximum waiting duration, step S101 is executed.
[0055] For the concept of the transaction waiting period of the target task, please refer to the above description.
[0056] When the maximum waiting time of the transaction waiter of the target task is reached, the timer linked list of the target task is queried to ensure that the target timer determined in step S101 can be processed in time and the timer is triggered and run on time.
[0057] After entering the transaction waiting period of the target task, if the pending transaction of the target task is obtained, the pending transaction is processed, and after the processing is completed, the aforementioned step S101 is executed.
[0058] For ease of understanding, the above solution is explained below through a specific example. Assume that the timer linked list of the target task is as follows Figure 1 As shown, the timer T3 in Table 1 is a periodic timer, the operation period of the timer T3 is 4s, and the current system time is 864111000 (00:00:11.000 1days), which refers to the time from system power-on to the present.
[0059] Timer Timeout T1 86410930(00:00:10.930 1days) T2 86410956(00:00:10.956 1days) T3 86411000(00:00:11.000 1days) T4 86412000(00:00:12.000 1days) T5 86415000(00:00:15.000 1days)
[0060] Table 1
[0061] The timer management method is as follows:
[0062] 1) Start querying from the first timer in Table 1, obtain timer T1, and use timer T1 as the current timer.
[0063] 2) Compare timer T1 with the current system time. Since the timeout period of timer T1 is less than the current system time, it is determined that timer T1 has timed out, and the callback function of timer T1 is executed (that is, the transaction corresponding to timer T1 is executed), and timer T1 is removed from the timer linked list.
[0064] 3) Set timer T2 as the current timer.
[0065] 4) Compare timer T2 with the current system time. Since the timeout period of timer T2 is less than the current system time, it is determined that timer T2 has timed out. The callback function of timer T2 is executed (i.e., the transaction corresponding to timer T2 is executed), and timer T2 is removed from the timer linked list.
[0066] After 1)-4), the timer list of the target task is shown in Table 2:
[0067] Timer Timeout T3 86411000(00:00:11.000 1days) T4 86412000(00:00:12.000 1days) T5 86415000(00:00:15.000 1days)
[0068] Table 2
[0069] 5) Set timer T3 as the current timer.
[0070] 6) Compare timer T3 with the current system time. Since the timeout time of timer T3 is less than the current system time, it is determined that timer T3 has timed out, and the callback function of timer T3 is executed (that is, the transaction corresponding to timer T3 is executed), and timer T3 is removed from the timer linked list; since timer T3 is a periodic timer, the timeout time of the next timeout of timer T3 is calculated according to the operation cycle of timer T3, and the timeout time of the next timeout of timer T3 is 86414000 (00:00:14.000 1days). The timeout time of the next timeout of timer T3 is greater than the timeout time of timer T4 and less than the timeout time of timer T5. Therefore, timer T3 is inserted between timer T4 and timer T5, and the timeout time of timer T3 is reset to 86414000 (00:00:14.000 1days).
[0071] After 3)-4), the timer list of the target task is shown in Table 3:
[0072] Timer Timeout T4 86412000(00:00:12.000 1days) T3 86414000(00:00:14.000 1days) T5 86415000(00:00:15.000 1days)
[0073] Table 3
[0074] 7) Set timer T4 as the current timer.
[0075] 8) Compare timer T4 with the current system time. Since the timeout time of timer T4 is greater than the current system time, it is determined that timer T4 has not timed out. Subtract the timeout time of timer T4 from the current system time to obtain the remaining timing duration of timer T4, which is 1s. Therefore, 1s is used as the maximum waiting duration of the transaction waiting period.
[0076] 9) Entering the transaction waiting period. After 1 second of entering the transaction waiting period, start querying from the first timer in Table 3.
[0077] As can be seen from the above, after the target task's transaction is processed, before entering the period of waiting for the transaction to be triggered, the target task's timer chain list is queried, and when a timer that has not timed out is queried in the timer chain list, the remaining timing duration of the fastest timed out timer queried is determined, and the remaining timing duration of the fastest timed out timer is used as the maximum waiting duration of the transaction waiting period before entering the task waiting period. One task corresponds to one timer chain list, and each task can determine whether the timer has expired by querying its own timer chain list, and execute the timer callback function by itself when the timer expires. Since the timer query operation is performed after the transaction is processed and before entering the period of waiting for the transaction to be triggered, data access conflicts will not be caused; in addition, when the fastest timed out timer is queried, the remaining timing duration of the fastest timed out timer is used as the maximum waiting duration of the period of waiting for the transaction to be triggered, so that the task can wake up from the period of waiting for the transaction to be triggered before the timer times out after entering the period of waiting for the transaction to be triggered, thereby processing the timer in time and ensuring that the timer in the timer chain list can be triggered and run on time.
[0078] The method of the present application is introduced above. In order to better implement the method of the present application, the device of the present application is introduced next.
[0079] See also Figure 2 , Figure 2 is a schematic diagram of the structure of a timer management device provided in an embodiment of the present application. The timer management device may be an embedded system or a part of an embedded system. Figure 2 As shown, the timer management device 20 includes:
[0080] The query module 201 is used to query the timer linked list of the target task before entering the transaction waiting period of the target task after processing the transaction of the target task. The transaction waiting period is the period of waiting for the transaction to be triggered. The timer linked list is used to manage the information of the timer of the target task. The information of the timer includes the transaction corresponding to the timer and the timeout period. One task corresponds to one timer linked list;
[0081] An execution module 202 is used to execute a transaction corresponding to a timed-out timer when a timed-out timer is found;
[0082] The timeout duration determination module 203 is used to determine the remaining timing duration of the target timer when a timer that has not timed out is found. The target timer is the fastest timer found to have timed out.
[0083] The waiting time determination module 204 is used to use the remaining timing time as the maximum waiting time of the transaction waiting period, enter the transaction waiting period, and when the time length entering the transaction waiting period is greater than or equal to the maximum waiting time, wake up the query module to execute the step of querying the timer linked list of the target task.
[0084] In one possible design, the query module 201 is specifically used to: starting from i=1, use the i-th timer in the timer linked list as the current timer to determine whether the current timer has timed out; if the current timer has not timed out, determine the current timer as the target timer, and trigger the timeout duration determination module 203 to execute the step of determining the remaining timing duration of the target timer; if the current timer times out, trigger the execution module 202 to execute the transaction corresponding to the current timer, and use the (i+1)th timer as the current timer to execute the step of determining whether the current timer has timed out, until the transactions corresponding to all timers that have timed out in the timer linked list are executed.
[0085] In one possible design, the timer information also includes whether it is a periodically running timer; the above-mentioned query module 201 is also used to: if the current timer is a periodically running timer, determine the timeout time of the next timeout of the current timer, and insert the current timer into the timer linked list according to the timeout time of the next timeout of the current timer.
[0086] In one possible design, the query module 201 is specifically used to: if the timeout period of the current timer is less than or equal to the current system time, determine that the current timer has timed out; if the timeout period of the current timer is greater than the current system time, determine that the current timer has not timed out.
[0087] In a possible design, the query module 201 is further used to trigger entry into a transaction waiting period when no timer exists in the timer linked list.
[0088] In a possible design, the execution module 202 is also used to: when obtaining pending transactions of the target task, process the pending transactions, and after the processing is completed, trigger the query module 201 to execute the step of querying the timer linked list of the target task.
[0089] It should be noted that Figure 2 For details not mentioned in the corresponding embodiments, please refer to the aforementioned Figure 1 The description of the method embodiment will not be repeated here.
[0090] The above device, after processing the transaction of the target task, before entering the period of waiting for the transaction to be triggered, queries the timer chain list of the target task, and in the case of finding a timer that has not timed out in the timer chain list, determines the remaining timing duration of the fastest timer that has timed out, and uses the remaining timing duration of the fastest timer that has timed out as the maximum waiting duration of the transaction waiting period, and then enters the task waiting period. One task corresponds to one timer chain list, and each task can determine whether the timer has timed out by querying its own timer chain list, and automatically executes the timer callback function when the timer has timed out. Since the operation of querying the timer is executed after processing the transaction and before entering the period of waiting for the transaction to be triggered, no data access conflict will be caused; in addition, when the fastest timer is queried, the remaining timing duration of the fastest timer that has timed out is used as the maximum waiting duration of the period of waiting for the transaction to be triggered, so that the task can wake up from the period of waiting for the transaction to be triggered before the timer times out after entering the period of waiting for the transaction to be triggered, thereby timely processing the timer and ensuring that the timer in the timer chain list can be triggered and run on time.
[0091] See also Figure 3 , Figure 3 30 is a schematic diagram of a computer device provided in an embodiment of the present application, wherein the computer device 30 includes a processor 301 and a memory 302. The processor 301 is connected to the memory 302, for example, the processor 301 may be connected to the memory 302 via a bus.
[0092] The processor 301 is configured to support the computer device 30 to perform the corresponding functions in the method in the above method embodiment. The processor 301 can be a central processing unit (CPU), a network processor (NP), a hardware chip or any combination thereof. The above hardware chip can be an application specific integrated circuit (ASIC), a programmable logic device (PLD) or a combination thereof. The above PLD can be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof.
[0093] The memory 302 is used to store program codes, etc. The memory 302 may include a volatile memory (VM), such as a random access memory (RAM); the memory 302 may also include a non-volatile memory (NVM), such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD); the memory 302 may also include a combination of the above-mentioned types of memories.
[0094] The processor 301 may call the program code to perform the following operations:
[0095] After processing the transaction of the target task and before entering the transaction waiting period of the target task, query the timer linked list of the target task, the transaction waiting period is the period of waiting for the transaction to be triggered, the timer linked list is used to manage the information of the timer of the target task, the information of the timer includes the transaction corresponding to the timer and the timeout period, and one task corresponds to one timer linked list;
[0096] When a timer that has timed out is found, executing the transaction corresponding to the timer that has timed out;
[0097] In the case of finding a timer that has not timed out, determining the remaining timing duration of a target timer, the target timer being the timer that has timed out the fastest found out, taking the remaining timing duration as the maximum waiting duration of the transaction waiting period, and entering the transaction waiting period;
[0098] When the duration of entering the transaction waiting period is greater than or equal to the maximum waiting duration, the step of querying the timer linked list of the target task is awakened and executed.
[0099] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a computer, the computer executes the method described in the above embodiment.
[0100] A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0101] The above disclosure is only the preferred embodiment of the present application, which certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A timer management method, characterized in that: include: After processing the transaction of the target task and before entering the transaction waiting period of the target task, query the timer linked list of the target task, the transaction waiting period is the period of waiting for the transaction to be triggered, the timer linked list is used to manage the information of the timer of the target task, the information of the timer includes the transaction corresponding to the timer and the timeout period, and one task corresponds to one timer linked list; When a timer that has timed out is found, executing the transaction corresponding to the timer that has timed out; In the case of finding a timer that has not timed out, determining the remaining timing duration of a target timer, the target timer being the timer that has timed out the fastest found out, taking the remaining timing duration as the maximum waiting duration of the transaction waiting period, and entering the transaction waiting period; When the duration of entering the transaction waiting period is greater than or equal to the maximum waiting duration, the step of querying the timer linked list of the target task is awakened and executed.
2. The method according to claim 1, characterized in that The timers are arranged in ascending order according to the timeout time in the timer chain list; The querying of the timer linked list of the target task includes: Starting from i=1, the i-th timer in the timer chain list is used as the current timer to determine whether the current timer has timed out; The determining the remaining timing duration of the target timer when a timer that has not timed out is found includes: If the current timer has not timed out, determining the current timer as the target timer, and determining the remaining timing duration of the target timer; In the case where a timed-out timer is found, executing a transaction corresponding to the timed-out timer includes: If the current timer times out, execute the transaction corresponding to the current timer, and use the (i+1)th timer as the current timer to execute the step of determining whether the current timer has timed out, until all transactions corresponding to timers in the timer linked list that have timed out are executed.
3. The method according to claim 2, characterized in that The information of the timer also includes whether it is a periodically running timer; after executing the transaction corresponding to the current timer, it also includes: If the current timer is a periodically running timer, determine the next timeout time of the current timer, and insert the current timer into the timer linked list according to the next timeout time of the current timer.
4. The method according to claim 2, characterized in that: The determining whether the current timer has timed out includes: If the timeout period of the current timer is less than or equal to the current system time, determining that the current timer has timed out; If the timeout period of the current timer is greater than the current system time, it is determined that the current timer has not timed out.
5. The method according to claim 3, characterized in that: The method further comprises: If the current timer times out and the current timer is a non-periodic timer, information of the current timer is removed from the timer linked list.
6. The method according to claim 1, characterized in that The method further comprises: When there is no timer in the timer linked list, the transaction waiting period is entered.
7. The method according to any one of claims 1 to 5, characterized in that: After entering the transaction waiting period, the method further includes: In the case of obtaining the pending transaction of the target task, the pending transaction is processed, and after the processing is completed, the step of querying the timer linked list of the target task is performed.
8. A timer management device, characterized in that: include: A query module is used to query the timer linked list of the target task before entering the transaction waiting period of the target task after processing the transaction of the target task. The transaction waiting period is a period of waiting for the transaction to be triggered. The timer linked list is used to manage the information of the timer of the target task. The information of the timer includes the transaction corresponding to the timer and the timeout period. One task corresponds to one timer linked list; An execution module, configured to execute a transaction corresponding to a timed-out timer when a timed-out timer is found; A timeout duration determination module, used to determine the remaining timing duration of a target timer when a timer that has not timed out is found, wherein the target timer is the fastest timer found to have timed out; A waiting time determination module is used to use the remaining timing time as the maximum waiting time of the transaction waiting period, enter the transaction waiting period, and when the time length of entering the transaction waiting period is greater than or equal to the maximum waiting time, wake up the query module to execute the step of querying the timer linked list of the target task.
9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the processor is used to execute one or more computer programs stored in the memory, and when the processor executes the one or more computer programs, the computer device implements the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Timer management device and management method for operating system
CN101859260A
Universal timed task management realization method
CN102129393A