Software timer implementation method, system and terminal based on signal processing function

By registering SIGALRM signal processing functions and preset timer groups in the process, the problems of complex thread creation and resource occupation in the existing technology are solved, efficient software timer timeout management is realized, and CPU performance is improved.

CN119226026BActive Publication Date: 2025-03-28CORE YUNSHENG (HANGZHOU) ELECTRONIC TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411759251.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-03
Publication Date
2025-03-28
Estimated Expiration
2044-12-03

AI Technical Summary

Technical Problem

Creating threads specifically used for software timers in the prior art causes software timers to be complex in use, occupying and consuming a large amount of system resources, affecting CPU performance.

Method used

By registering the SIGALRM signal processing function when initializing the process and presetting multiple timer groups, the SIGALRM signal and the timing cycle of the timer group determine whether the timer group meets the timeout condition and performs the timeout processing task, avoiding the need for creating new threads.

Benefits of technology

The timeout management of software timers is implemented in the process, without the need for new threads, which reduces the use of system resources and consumption, improves CPU performance, and simplifies the use of software timers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119226026B_ABST
    Figure CN119226026B_ABST
Patent Text Reader

Abstract

The present application provides a method, system and terminal for implementing a software timer based on a signal processing function. The method registers a SIGALRM signal processing function when initializing a process, and presets a plurality of timer groups for adding timers for all business threads in the process. Each time the process receives a SIGALRM signal, when it is judged that each timer group has met the timeout condition based on the timing cycle of each timer group and the timing cycle of the SIGALRM signal, a timeout processing task is performed on each timer in the timer group. Therefore, the present application mainly provides timeout management of software timers for each business thread in the process based on the signal processing function and the preset timer group, which is completed in the process without creating a new thread, thereby effectively solving the problem of complex use of software timers and occupation and consumption of a large amount of system resources caused by creating threads specifically for software timers in the prior art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer communication technology, and in particular to a method, system and terminal for realizing a software timer based on a signal processing function. Background Art

[0002] Software timer is an important functional module in the design and development process of software system. It is usually used to execute tasks after a specific time interval or trigger events after timeout. It can be widely used in periodic statistical and monitoring needs. For example, in network applications, it can periodically obtain network card packet statistics, report system status, maintain heartbeats, and release system resources that have not been used for a long time. Users can choose the appropriate implementation method to design and implement software timers with different precisions according to actual business needs, and can create multiple software timers at the same time, which is simple and flexible to use.

[0003] At present, the common implementation method of software timers is that each business thread creates different software timers according to actual needs, and then creates an independent thread to perform timeout detection and timeout processing tasks of the software timer. However, creating a new thread specifically for timeout detection and timeout processing tasks of software timers, on the one hand, makes the use of software timers more complicated, and it is easy for threads to deadlock, with limited security, and it is more difficult to debug, maintain and expand the code; on the other hand, it increases the occupation and consumption of system resources and memory, affecting CPU performance. Summary of the invention

[0004] In view of the shortcomings of the prior art described above, the purpose of the present application is to provide a software timer implementation method, system and terminal based on a signal processing function, so as to solve the problem of complex use of software timers and occupation and consumption of a large amount of system resources caused by creating threads specifically for software timers in the prior art.

[0005] To achieve the above-mentioned purpose and other related purposes, the first aspect of the present application provides a software timer implementation method based on a signal processing function, and the software timer implementation method based on a signal processing function includes: registering a SIGALRM signal processing function when initializing a process, and presetting multiple timer groups; wherein each timer group is used to add timers created by all business threads in the process, so that each business thread can perform timeout management of the software timer; setting the timing period of the SIGALRM signal and the timing period of each timer group respectively; after the process receives a SIGALRM signal each time, it judges whether each timer group meets the timeout condition according to the timing period of each timer group, and when a timer group meets the timeout condition, performs a timeout processing task on each timer in the timer group to meet the timing task requirements of each business thread in the thread.

[0006] In some embodiments of the first aspect of the present application, a method for determining whether each timer group meets the timeout condition based on the timing period of each timer group includes: sorting each timer group according to the timing period of each timer group, and setting the counting period and the counted number of each timer group in turn; wherein the timing period of each timer group is an integer multiple of the timing period of the SIGALRM signal, and is an integer multiple of the timing period of the previous timer group; the timing period of each timer is an integer multiple of the timing period of the timer group to which it belongs; after receiving the SIGALRM signal, determining whether each timer group meets the counting condition in turn; if a timer group meets the counting condition, adding one to the counted number of the timer group, and determining whether the counted number of the timer group is equal to its counting period; if the counted number of the timer group is equal to its counting period, determining that the timer group meets the timeout condition, and executing the timeout processing task for each timer in the timer group, and clearing the counted number of the timer group at the same time.

[0007] In some embodiments of the first aspect of the present application, the method of setting the counting period and the number of counts of each timer group includes: setting the counting period of the first-ranked timer group to an integer multiple value between the timing period of the timer group and the timing period of the SIGALRM signal; setting the counting period of other timer groups to an integer multiple value between the timing period of the timer group and the timing period of the previous timer group; initializing the number of counts of each timer group to zero.

[0008] In some embodiments of the first aspect of the present application, the method of performing timeout processing tasks on each timer in a timer group includes: traversing each timer in the timer group, and performing timeout judgment on the timer in each motion state according to the timing cycle of each timer; obtaining one or more timers that meet the timeout judgment conditions, and calling the callback function set when each timer is created to perform timeout processing on each timer; updating the state of each timer to a sleep state or a motion state.

[0009] In some embodiments of the first aspect of the present application, the way in which the business thread performs timeout management of software timers based on each timer group includes: after the business thread creates a timer, it adds it to the corresponding timer group according to the timing period set for the timer, and sets the state of the timer to a motion state; wherein the timing period of the timer is an integer multiple of the timing period of the timer group to which it belongs; when the timer group meets the timeout condition, the timer is timed out by executing a timeout processing task on each timer in the timer group.

[0010] In some embodiments of the first aspect of the present application, the way in which the business thread performs timeout management of software timers based on each timer group includes: after the business thread resets the timer, the timer is removed from the timer group to which it originally belongs, and is re-added to the corresponding timer group according to the updated timing period of the timer, and the state of the timer is updated to a motion state; wherein the timing period of the timer is an integer multiple of the timing period of the timer group to which it belongs; when the timer group meets the timeout condition, the timer is timed out by executing a timeout processing task on each timer in the timer group.

[0011] In some embodiments of the first aspect of the present application, the way in which the business thread performs timeout management of software timers based on each timer group includes: after the business thread cancels the timer, the state of the timer is updated to a sleep state; when the timer group to which the timer belongs meets the timeout condition, when the timer group executes the timeout processing task for each timer in the timer group, the timer will be skipped and the timeout processing of the timer will be suspended.

[0012] In some embodiments of the first aspect of the present application, the manner in which the service thread performs timeout management of the software timer based on each timer group includes: after the service thread deletes the timer, the timer is removed from the timer group to which it belongs.

[0013] To achieve the above-mentioned purpose and other related purposes, the second aspect of the present application provides a software timer implementation system based on a signal processing function, and the software timer implementation system based on a signal processing function includes: an initialization module, which is used to register a SIGALRM signal processing function when initializing a process, and preset multiple timer groups for all business threads in the process to perform software timer timeout management; respectively set the timing period of the SIGALRM signal and the timing period of each timer group; wherein each timer group is respectively used to add the timer created by each business thread in the process, and the timing period of each timer is an integer multiple of the timing period of the timer group to which it belongs; a timeout management module, connected to the initialization module, used for the process to determine whether each timer group meets the timeout condition according to the timing period of each timer group each time it receives a SIGALRM signal, and when a timer group meets the timeout condition, perform a timeout processing task on each timer in the timer group to meet the timing task requirements of each business thread in the thread.

[0014] To achieve the above-mentioned purpose and other related purposes, the third aspect of the present application provides a software timer implementation terminal based on a signal processing function, and the software timer implementation terminal based on a signal processing function includes: a processor and a memory; the memory is used to store a computer program; the processor is used to execute the computer program stored in the memory, so that the terminal executes the software timer implementation method based on a signal processing function described in any one of the above-mentioned embodiments.

[0015] As described above, the present application has the following beneficial effects: the present application provides a software timer implementation method, system and terminal based on a signal processing function, by registering a SIGALRM signal processing function when initializing a process, and presetting a plurality of timer groups for adding timers for all business threads in the process; each time the process receives a SIGALRM signal, based on the timing cycle of each timer group and the timing cycle of the SIGALRM signal, when it is judged that each timer group has met the timeout condition, a timer in the timer group executes a timeout processing task; therefore, the present application mainly provides timeout management of software timers for each business thread in the process based on the signal processing function and the preset timer group, which is completed in the process without the need to create a new thread, thereby effectively solving the problem of complex use of software timers and occupation and consumption of a large amount of system resources caused by creating threads specifically for software timers in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 Shown is a schematic diagram of an existing software timer implementation method based on a timer thread in an embodiment of the present application.

[0017] Figure 2 Shown is a flowchart of a method for implementing a software timer based on a signal processing function in one embodiment of the present application.

[0018] Figure 3 Shown is a schematic diagram of the organizational structure of a timer group in one embodiment of the present application.

[0019] Figure 4 Shown is a schematic diagram of a business thread creating a timer in one embodiment of the present application.

[0020] Figure 5 Shown is a schematic diagram of timer group timeout management in a specific embodiment of the present application.

[0021] Figure 6 Shown is a structural diagram of a software timer implementation system based on a signal processing function in one embodiment of the present application.

[0022] Figure 7 Shown is a schematic diagram of the structure of a software timer implementing a terminal based on a signal processing function in one embodiment of the present application. DETAILED DESCRIPTION

[0023] The following describes the embodiments of the present application through specific examples, and those skilled in the art can easily understand other advantages and effects of the present application from the contents disclosed in this specification. The present application can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.

[0024] At present, the common implementation method of software timers is that each business thread creates different software timers according to actual needs, and then creates an independent thread to perform timeout detection and timeout processing tasks of the software timer.

[0025] Specifically, Figure 1 As shown, each business thread can create, reset, cancel and delete timer elem_n as needed, and when creating timer elem_n, set the relevant parameters of timer elem_n, such as the timing period of timer elem_n, the callback function of timeout processing, etc., so as to divide timer elem_n into the specified timer group group object according to these parameters, so that the created timer timer thread can perform timeout detection and reset timer and other operations on each timer elem_n in each timer group group object. The main function of the timer timer thread is to perform the judgment operation of timer elem_n, and call its callback function to perform timeout processing for the timer that has timed out; for periodic timers, after the timeout processing, the relevant parameters of the timer need to be reset.

[0026] It should be noted that in the existing software timer implementation method, since a new thread needs to be created, the use of the software timer will be more complicated, and deadlocks are likely to occur between threads, which has limited security and makes code debugging, maintenance and expansion more difficult. At the same time, the new thread will also increase the occupancy and consumption of system resources and memory, affecting CPU performance.

[0027] Therefore, in order to solve the above technical problems, the present invention provides a software timer implementation method, system and terminal based on signal processing function, aiming to solve the problem of complex use of software timers and occupation and consumption of a large amount of system resources caused by creating threads specifically for software timers in the prior art.

[0028] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the technical solution in the embodiments of the present invention is further described in detail through the following embodiments and in combination with the accompanying drawings. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the invention.

[0029] like Figure 2 As shown, a flow chart of a method for implementing a software timer based on a signal processing function in an embodiment of the present invention is shown. The method for implementing a software timer based on a signal processing function in this embodiment mainly includes the following steps.

[0030] Step S1: Register the SIGALRM signal processing function when initializing the process, and preset multiple timer groups.

[0031] It should be understood that in the Linux system, the SIGALRM signal can be used to implement the timing function. When a process needs to perform an operation after a specific time, it can use the alarm system call to set a timer. When the timer expires, the kernel will send a SIGALRM signal to the process, thereby timing the timers of each service thread in the process.

[0032] Each timer group is used to add timers created by all service threads in the process, so that each service thread can perform timeout management of software timers.

[0033] In one embodiment, if Figure 3 As shown, the timer organization structure that can be set in the process includes multiple timer groups, namely Figure 3 Each timer group (group object) is added with the timers created by each business thread (such as Figure 3 elem_1, elem_2, and elem_n shown in ).

[0034] Step S2: respectively set the timing period of the SIGALRM signal and the timing period of each timer group.

[0035] In one embodiment, the timing cycle of each timer group is an integer multiple of the timing cycle of the SIGALRM signal, and the timing cycle of each timer is an integer multiple of the timing cycle of the timer group to which it belongs. After the timer groups are sorted, the timing cycle of each timer group is an integer multiple of the timing cycle of the previous timer group.

[0036] Step S3: Each time the process receives a SIGALRM signal, it determines whether each timer group meets the timeout condition according to the timing cycle of each timer group. If a timer group meets the timeout condition, it executes the timeout processing task for each timer in the timer group to meet the timing task requirements of each business thread in the thread.

[0037] In one embodiment, a method of determining whether each timer group meets a timeout condition according to a timing period of each timer group includes the following steps.

[0038] ① Sort the timer groups according to their timing periods, and set the counting periods and counted times of each timer group in sequence.

[0039] Specifically, the order of each timer group is from small to large timing period. In addition, in one embodiment, the method of setting the counting period and the counted number of each timer group includes: setting the counting period of the first-ranked timer group to an integer multiple value between the timing period of the timer group and the timing period of the SIGALRM signal; setting the counting period of other timer groups to an integer multiple value between the timing period of the timer group and the timing period of the previous timer group; initializing the counted number of each timer group to zero.

[0040] For example, the timer groups are sorted in order from small to large according to the timing period, and are defined as the first timer group, the second timer group, and the Nth timer group, etc.

[0041] It should be noted that the timing period of each timer group is an integer multiple of the timing period of the SIGALRM signal, and is an integer multiple of the timing period of the previous timer group. That is, the timing periods of the first timer group, the second timer group, and the Nth timer group are all integer multiples of the timing period of the SIGALRM signal, the timing period of the second timer group is an integer multiple of the timing period of the first timer group, and the timing period of the Nth timer group is an integer multiple of the timing period of the (N-1)th timer group.

[0042] Therefore, the counting period of the first timer group is initialized to: ; The counting period of the second timer group is: ; The counting period of the Nth timer group is: .in, is the counting period of the first timer group, is the counting period of the second timer group, is the counting period of the Nth timer group; It is the timing cycle of the SIGALRM signal; is the timing period of the first timer group, is the timing period of the second timer group, is the timing period of the (N-1)th timer group, It is the timing period of the Nth timer group.

[0043] At the same time, initialize and set the counted times of each timer group .

[0044] ②After receiving the SIGALRM signal, determine whether each timer group meets the counting conditions in turn.

[0045] In one embodiment, the counting condition of the first timer group includes: counting once every time a SIGALRM signal is received; the counting condition of other timer groups includes: counting once for each timeout processing task executed for the previous timer group. Specifically, the counting condition of the second timer group includes: counting once for each timeout processing task executed for the first timer group; the counting condition of the Nth timer group includes: counting once for each timeout processing task executed for the (N-1)th timer group.

[0046] ③ If a timer group meets the counting condition, the counted number of the timer group is increased by one, and it is determined whether the counted number of the timer group is equal to its counting period.

[0047] ④ If the counted times of the timer group are equal to its counting period, the timer group is determined to meet the timeout condition, and the timeout processing task is executed for each timer in the timer group, and the counted times of the timer group are cleared.

[0048] In one embodiment, the method of executing the timeout processing task for each timer in the timer group includes: traversing each timer in the timer group, and performing timeout judgment on the timer of each motion state according to the timing cycle of each timer; obtaining one or more timers that meet the timeout judgment conditions, and calling the callback function set when each timer is created to perform timeout processing on each timer; updating the state of each timer to a sleep state or a motion state.

[0049] It should be understood that when a timer is activated and starts timing, its state is called a moving state; when a timer is paused or stops timing, its state is called a dormant state. In this embodiment, if the timer is a periodic timer, after completing the timeout process, its state needs to be updated to a moving state; if the timer is a non-periodic timer, after completing the timeout process, its state is updated to a dormant state and no longer counts.

[0050] The software timer implementation method provided in the present application is mainly based on signal processing functions and preset timer groups for each business thread within the process to perform software timer timeout management. It is mainly completed in the process and does not require the creation of a new thread. Therefore, it occupies and consumes less memory and system resources, and executing timeout processing tasks is also simpler and more convenient.

[0051] In one embodiment, the manner in which the service thread performs timeout management of the software timer based on each timer group includes: creating a timer, resetting a timer, canceling a timer, and deleting a timer.

[0052] like Figure 4 As shown, after the business thread creates a timer, it adds it to the corresponding timer group according to the timing period set by the timer, and sets the state of the timer to the motion state; when the timer group meets the timeout condition, the timer is timed out by executing the timeout processing task on each timer in the timer group.

[0053] In addition, if Figure 4 As shown, after the service thread creates a timer, it calculates the timer group to which the timer belongs, and also allocates memory to the timer and performs initialization settings. Initializing the timer includes: setting the timer's timing period and callback function parameters.

[0054] After the business thread resets the timer, it removes the timer from the timer group to which it originally belongs, and adds it back to the corresponding timer group according to the updated timing period of the timer, and updates the state of the timer to the motion state; when the timer group meets the timeout condition, the timer is timed out by executing the timeout processing task on each timer in the timer group.

[0055] After the business thread cancels the timer, the state of the timer is updated to the dormant state; when the timer group to which the timer belongs meets the timeout condition, when executing the timeout processing task for each timer in the timer group, the timer will be skipped and the timeout processing of the timer will be suspended.

[0056] After the service thread deletes the timer, the timer is removed from the timer group to which it belongs.

[0057] It should be noted that the timing period of each timer is an integer multiple of the timing period of the timer group to which it belongs. For example, the timing period of the first timer group is 10ms, and the timing period of the second timer group is 100ms. Then the timers with timing periods of 10ms, 20ms, and 30ms belong to the first timer group, and the timers with timing periods of 100ms, 200ms, and 300ms belong to the second timer group.

[0058] In order to better illustrate and describe the software timer implementation method based on the signal processing function, the present application provides a specific embodiment for further detailed description.

[0059] Embodiment 1: A method for realizing a software timer based on a signal processing function.

[0060] ① Register the SIGALRM signal processing function when initializing the process and set the timing period of the SIGALRM signal to 10ms.

[0061] ② Preset four timer groups: the first timer group, the second timer group, the third timer group and the fourth timer group. Set the timing period of the first timer group to 10ms, the timing period of the second timer group to 100ms, the timing period of the third timer group to 1s, and the timing period of the fourth timer group to 1min.

[0062] ③ Initialize the counting cycle circle and counted times tick of each timer group: the counting cycle circle of the first timer group is 1, the counting cycle circle of the second timer group is 10, the counting cycle circle of the third timer group is 10, and the counting cycle circle of the fourth timer group is 60; the counted times tick of each timer group is 0.

[0063] ④When the SIGALRM signal is received for the first time, the timing time is 10ms. Figure 5 As shown, it is determined whether each timer group meets the timeout condition. Specifically, starting from the first timer group, the counted times tick+1 of the first timer group is equal to 1, and it is determined whether the first timer group meets the timeout condition: since its counted times tick is equal to the counting cycle circle, it is determined that the first timer group meets the timeout condition, that is, all timers in the first timer group are traversed, and the timeout processing task is performed on each of its timers respectively, and then the counted times tick is cleared; at this time, after the timeout processing task is completed for the first timer group, the counted times tick+1 of the second timer group is equal to 1. Since its counted times tick is not equal to the counting cycle circle, the timeout processing task is temporarily not performed on the second timer group. Similarly, there is no need to perform timeout processing tasks on the third timer group and the fourth timer group.

[0064] It should be noted that when executing the timeout processing task for each timer in the first timer group, it is determined whether each timer meets the timeout judgment condition. That is, if the timing period of the timer is 10ms, it is determined that it meets the timeout judgment condition, and then the callback function of the timer is called to perform timeout processing on the timer; if the timing period of the timer is 20ms, the timeout judgment condition is not met and no timeout processing is required.

[0065] ⑤ When the SIGALRM signal is received for the second time, the timing time is 20ms. Starting from the first timer group, the counted times tick+1 of the first timer group is equal to 1. Since the counted times tick is equal to the counting cycle circle, it is determined that the first timer group meets the timeout condition again, that is, all timers in the first timer group are traversed, and the timeout processing task is performed on each timer respectively, and then the counted times tick is cleared; at this time, after the timeout processing task is completed for the first timer group, the counted times tick+1 of the second timer group is equal to 1+1==2. Since the counted times tick is still not equal to the counting cycle circle, the timeout processing task is not performed on the second timer group temporarily. Similarly, there is no need to perform timeout processing tasks on the third timer group and the fourth timer group.

[0066] It should be noted that when executing the timeout processing task for each timer in the first timer group, if the timing period of the timer is 20ms, the timer has met the timeout judgment condition, and the callback function of the timer is called to perform timeout processing on the timer.

[0067] ⑥ Repeat this process. When the SIGALRM signal is received for the tenth time, the timing time is 100ms. The first timer group has executed the timeout processing task 9 times, and this time it will be the 10th time; at this time, the counted times tick+1 of the second timer group is equal to 10. Since the counted times tick is equal to the counting cycle circle, it is determined that the second timer group has met the timeout condition, that is, all timers in the second timer group are traversed, and the timeout processing task is executed for each timer respectively, and then the counted times tick is cleared; but at this time, the third timer group and the fourth timer group do not meet the timeout condition, and there is no need to execute the timeout processing task.

[0068] ⑦ Similarly, it can be inferred that when the SIGALRM signal is received for the 100th time, the timing time is 1s, the third timer group meets the timeout condition, and a timeout processing task is executed for the third timer group; when the SIGALRM signal is received for the 6000th time, the timing time is 1min, the fourth timer group meets the timeout condition, and a timeout processing task is executed for the fourth timer group.

[0069] In the embodiments of the present application, words such as "first" and "second" are used to distinguish the same or similar items with substantially the same functions and effects. For example, the first timer group and the second timer group are only used to distinguish different timer groups, and do not limit their order. Those skilled in the art can understand that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit them to be different.

[0070] It should be noted that in the embodiments of the present application, words such as "exemplary" or "for example" represent examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0071] In the embodiments of the present application, "at least one" refers to one or more, and "plurality" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can represent: a, b, c, ab, ac, bc or abc, where a, b, c can be single or multiple.

[0072] like Figure 6 , which shows a schematic diagram of the structure of a software timer implementation system 600 based on a signal processing function in an embodiment of the present invention. The software timer implementation system 600 based on a signal processing function includes: an initialization module 601 and a timeout management module 602.

[0073] The initialization module 601 is used to register the SIGALRM signal processing function when initializing the process, and preset multiple timer groups for all business threads in the process to perform software timer timeout management; set the timing period of the SIGALRM signal and the timing period of each timer group respectively; wherein each timer group is used to add the timer created by each business thread in the process, and the timing period of each timer is an integer multiple of the timing period of the timer group to which it belongs.

[0074] The timeout management module 602 is connected to the initialization module 601, and is used to determine whether each timer group meets the timeout condition according to the timing cycle of each timer group each time the process receives a SIGALRM signal, and when a timer group meets the timeout condition, perform a timeout processing task on each timer in the timer group to meet the timing task requirements of each business thread in the thread.

[0075] It should be understood that the specific process of each module executing the above corresponding steps has been described in detail in the above method embodiment, and for the sake of brevity, it will not be repeated here.

[0076] It should also be understood that the division of modules in the embodiments of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. In addition, each functional module in each embodiment of the present application may be integrated into a processor, or may exist physically separately, or two or more modules may be integrated into one module. The above-mentioned integrated modules may be implemented in the form of hardware or in the form of software functional modules.

[0077] Figure 7 1 is a schematic diagram of a structure of a software timer implementing a terminal 700 based on a signal processing function provided in an embodiment of the present application. Figure 7 As shown, the software timer implementation terminal 700 based on the signal processing function includes: at least one processor 701, a memory 702, at least one network interface 704 and a user interface 706. The various components in the terminal are coupled together through a bus system 705. It can be understood that the bus system 705 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 705 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, Figure 7 In the specification, various buses are labeled as bus systems.

[0078] The user interface 706 may include a display, a keyboard, a mouse, a trackball, a click gun, keys, buttons, a touch pad or a touch screen.

[0079] It is understood that the memory 702 can be a volatile memory or a non-volatile memory, and can also include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), which is used as an external cache. By way of exemplary but not limiting explanation, many forms of RAM are available, such as static random access memory (SRAM), synchronous static random access memory (SSRAM). The memory described in the embodiments of the present invention is intended to include but is not limited to these and any other suitable categories of memory.

[0080] The memory 702 in the embodiment of the present invention is used to store various categories of data to support the operation of the software timer implementation terminal 700 based on the signal processing function. Examples of these data include: any executable program used to operate on the software timer implementation terminal 700 based on the signal processing function, such as an operating system 7021 and an application 7022; the operating system 7021 includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and processing hardware-based tasks. The application 7022 can include various applications, such as a media player (Media Player), a browser (Browser), etc., for implementing various application services. The software timer implementation method based on the signal processing function provided in the embodiment of the present invention can be included in the application 7022.

[0081] The software timer implementation method based on the signal processing function disclosed in the above embodiment of the present invention can be applied to the processor 701, or implemented by the processor 701. The processor 701 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 701 or the instruction in the form of software. The above processor 701 may be a general processor, a digital signal processor (DSP, Digital Signal Processor), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The processor 701 can implement or execute the methods, steps and logic block diagrams disclosed in the embodiment of the present invention. The general processor 701 may be a microprocessor or any conventional processor, etc. The steps of the software timer implementation method based on the signal processing function provided in combination with the embodiment of the present invention can be directly embodied as a hardware decoding processor to perform, or a combination of hardware and software modules in the decoding processor to perform. The software module can be located in a storage medium, which is located in a memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.

[0082] In an exemplary embodiment, the signal processing function-based software timer implementation terminal 700 can be implemented by one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), and complex programmable logic devices (CPLDs) to execute the aforementioned method.

[0083] In the several embodiments provided in the present application, it should be understood that the disclosed methods, systems and terminals can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of modules is only a logical function division. There may be other division methods in actual implementation. For example, multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of modules can be electrical, mechanical or other forms.

[0084] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0085] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0086] In the above embodiments, the functions of each functional unit can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions (programs). When the computer program instructions (programs) are loaded and executed on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated. Available media may be magnetic media (e.g., floppy disks, hard disks, tapes), optical media (e.g., high-density digital video discs (DVDs), or semiconductor media (e.g., solid state disks (SSDs)).

[0087] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, and other media that can store program codes.

[0088] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0089] In summary, the present application provides a software timer implementation method, system and terminal based on signal processing function, by registering the SIGALRM signal processing function when initializing the process, and presetting multiple timer groups for adding timers of all business threads in the process; each time the process receives a SIGALRM signal, according to the timing cycle of each timer group and the timing cycle of the SIGALRM signal, when it is judged that each timer group has met the timeout condition, a timer in the timer group executes a timeout processing task; therefore, the present application is mainly based on the signal processing function and the preset timer group for each business thread in the process to perform software timer timeout management, which is completed in the process and does not require a new thread, thereby effectively solving the problem of complex use of software timers and occupation and consumption of a large amount of system resources caused by creating threads specifically for software timers in the prior art.

[0090] Therefore, the present application effectively overcomes various shortcomings in the prior art and has high industrial utilization value.

[0091] The above embodiments are merely illustrative of the principles and effects of the present application and are not intended to limit the present application. Anyone familiar with the technology may modify or change the above embodiments without violating the spirit and scope of the present application. Therefore, all equivalent modifications or changes made by a person of ordinary skill in the art without departing from the spirit and technical ideas disclosed in the present application shall still be covered by the claims of the present application.

Claims

1. A method for implementing a software timer based on a signal processing function, characterized in that: include: When initializing the process, register the SIGALRM signal processing function and preset multiple timer groups; each timer group is used to add the timers created by all business threads in the process, so that each business thread can perform timeout management of the software timer; Set the timing period of the SIGALRM signal and the timing period of each timer group respectively; Each time the process receives a SIGALRM signal, it determines whether each timer group meets the timeout condition according to the timing cycle of each timer group. If a timer group meets the timeout condition, it executes the timeout processing task for each timer in the timer group to meet the timing task requirements of each business thread in the thread. Among them, according to the timing cycle of each timer group, the method of judging whether each timer group meets the timeout condition includes: sorting each timer group according to the timing cycle of each timer group, and sequentially setting the counting cycle and the counted number of each timer group; after receiving the SIGALRM signal, judging in sequence whether each timer group meets the counting condition; if a timer group meets the counting condition, adding one to the counted number of the timer group, and judging whether the counted number of the timer group is equal to its counting cycle; if the counted number of the timer group is equal to its counting cycle, judging that the timer group meets the timeout condition, and executing the timeout processing task for each timer in the timer group, and clearing the counted number of the timer group at the same time; Among them, the timing period of each timer group is an integer multiple of the timing period of the SIGALRM signal, and is an integer multiple of the timing period of the previous timer group; the timing period of each timer is an integer multiple of the timing period of the timer group to which it belongs; the method of setting the counting period of each timer group and the number of counts includes: setting the counting period of the first-ranked timer group to an integer multiple value between the timing period of the timer group and the timing period of the SIGALRM signal; setting the counting period of other timer groups to an integer multiple value between the timing period of the timer group and the timing period of the previous timer group; initializing the number of counts of each timer group to zero.

2. The method for realizing a software timer based on a signal processing function according to claim 1, characterized in that: The methods for executing timeout processing tasks for each timer in the timer group include: Traverse each timer in the timer group, and determine the timeout of the timer in each motion state according to the timing cycle of each timer; Get one or more timers that meet the timeout judgment conditions, and call the callback function set when each timer is created to handle the timeout of each timer; Update the state of each timer to sleep state or motion state.

3. The method for realizing a software timer based on a signal processing function according to claim 1, characterized in that: The business thread performs software timer timeout management based on each timer group in the following ways: After the business thread creates a timer, it adds it to the corresponding timer group according to the timing period set for the timer, and sets the state of the timer to the motion state; wherein the timing period of the timer is an integer multiple of the timing period of the timer group to which it belongs; When the timer group meets the timeout condition, the timer is timed out by executing the timeout processing task on each timer in the timer group.

4. The method for realizing a software timer based on a signal processing function according to claim 1, characterized in that: The business thread performs software timer timeout management based on each timer group in the following ways: After the service thread resets the timer, the timer is removed from the original timer group, and is added back to the corresponding timer group according to the updated timing period of the timer, and the state of the timer is updated to the motion state; wherein the timing period of the timer is an integer multiple of the timing period of the timer group to which it belongs; When the timer group meets the timeout condition, the timer is timed out by executing the timeout processing task on each timer in the timer group.

5. The method for realizing a software timer based on a signal processing function according to claim 1, characterized in that: The business thread performs software timer timeout management based on each timer group in the following ways: After the business thread cancels the timer, the state of the timer is updated to the dormant state; When the timer group to which the timer belongs meets the timeout condition, when executing the timeout processing task for each timer in the timer group, the timer will be skipped and the timeout processing for the timer will be suspended.

6. The method for realizing a software timer based on a signal processing function according to claim 1, characterized in that: The business thread performs software timer timeout management based on each timer group in the following ways: After the service thread deletes the timer, the timer is removed from the timer group to which it belongs.

7. A software timer implementation system based on a signal processing function, characterized in that: include: An initialization module is used to register a SIGALRM signal processing function when initializing a process, and preset multiple timer groups for all service threads in the process to perform timeout management of software timers; respectively set the timing period of the SIGALRM signal and the timing period of each timer group; wherein each timer group is used to add the timer created by each service thread in the process, and the timing period of each timer is an integer multiple of the timing period of the timer group to which it belongs; A timeout management module, connected to the initialization module, is used for determining whether each timer group meets the timeout condition in turn according to the timing cycle of each timer group after the process receives a SIGALRM signal each time, and when a timer group meets the timeout condition, executing a timeout processing task for each timer in the timer group to meet the timing task requirements of each business thread in the thread; Among them, according to the timing cycle of each timer group, the method of judging whether each timer group meets the timeout condition includes: sorting each timer group according to the timing cycle of each timer group, and sequentially setting the counting cycle and the counted number of each timer group; after receiving the SIGALRM signal, judging in sequence whether each timer group meets the counting condition; if a timer group meets the counting condition, adding one to the counted number of the timer group, and judging whether the counted number of the timer group is equal to its counting cycle; if the counted number of the timer group is equal to its counting cycle, judging that the timer group meets the timeout condition, and executing the timeout processing task for each timer in the timer group, and clearing the counted number of the timer group at the same time; Among them, the timing period of each timer group is an integer multiple of the timing period of the SIGALRM signal, and is an integer multiple of the timing period of the previous timer group; the timing period of each timer is an integer multiple of the timing period of the timer group to which it belongs; the method of setting the counting period of each timer group and the number of counts includes: setting the counting period of the first-ranked timer group to an integer multiple value between the timing period of the timer group and the timing period of the SIGALRM signal; setting the counting period of other timer groups to an integer multiple value between the timing period of the timer group and the timing period of the previous timer group; initializing the number of counts of each timer group to zero.

8. A software timer implementation terminal based on a signal processing function, characterized in that: include: Processor and memory; The memory is used to store computer programs; The processor is used to execute the computer program stored in the memory, so that the terminal executes the software timer implementation method based on the signal processing function as claimed in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Software timing method of dynamic overload timing length

    CN102937893A

  • In-process timer management method and system based on dynamic timing periods

    CN105528246A