CN101727352A - Method for realizing timer - Google Patents
Method for realizing timer Download PDFInfo
- Publication number
- CN101727352A CN101727352A CN200910311448A CN200910311448A CN101727352A CN 101727352 A CN101727352 A CN 101727352A CN 200910311448 A CN200910311448 A CN 200910311448A CN 200910311448 A CN200910311448 A CN 200910311448A CN 101727352 A CN101727352 A CN 101727352A
- Authority
- CN
- China
- Prior art keywords
- timer
- user
- thread
- queue
- software
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Landscapes
- Executing Machine-Instructions (AREA)
Abstract
The invention relates to a timer technique, provides a method for realizing a timer, and solves the problem that a software module is inconvenient to wholly transplant in the conventional software timer. The timer adopts the following technical scheme that: firstly, a main thread creates a timer array and initializes the timer array to generate a head node for managing the array; secondly, a user thread creates a software timer and initializes the timer parameters; thirdly, the main thread creates a secondary thread, initializes a software clock through a hardware clock, finishes the registration of the timer in the array, and performs locking operation on an array operation shared lock; and fourthly, the secondary thread orderly inspects all user-defined timer nodes in the array, and judges whether a value of a counter thereof is 0 or not one by one, if so, executes overtime timer event, otherwise, performs reducing 1 operation on the counter and then returns to the step of orderly inspection by the secondary thread. The method has the advantages of convenience and applicability to the timer.
Description
Technical field
The present invention relates to the timer technology, particularly the software timer technology.
Background technology
As everyone knows, timer function is extremely important in software development, also is ubiquitous.No matter be on computers applied software development or the exploitation under the embedded product, an important module all is absolutely necessary, show or the like as the timed power on/off in the televisor, playing progress bar in the player software, all be to be unable to do without timer management, in the software development of present most of products, the management of timer is based on all that the interface function of hardware clock or system function realize, there is very big heterogeneity, the integral transplanting of inconvenient software module is relatively more chaotic at the management aspect to a plurality of timer events in addition.
Summary of the invention
Technical matters to be solved by this invention exactly for the shortcoming of the integral transplanting that overcomes the inconvenient software module of present software timer, provides a kind of implementation method of timer.
The present invention solves its technical matters, and the technical scheme of employing is that a kind of implementation method of timer is characterized in that, may further comprise the steps:
A. main thread is created timer queue, and with the timer queue initialization, generates a node that is used for managing this formation, so that to the various operations of this timer queue;
B. user thread is created software timer, initialization timing device parameter;
C. main thread is created sub-thread according to the software timer that the user creates, by hardware clock initializers clock;
D. main thread is created the operation of software timer according to the user, finishes the registration of this timer in formation, carries out the latching operation that adds of queue operation shared lock in this process, release after finishing;
E. sub-thread is all user-defined timer nodes in the taking turn formation in order, utilize the select function to judge one by one whether the value of its timer_remain_value counter is 0, if then enter the g step, if not then enter the f step;
F. its timer_remain_value counter is subtracted " 1 " operation, get back to the e step;
G. carry out and reach overtime timer event.
Concrete, the described timer parameter of step b comprises timer ID number, timer expiry time, the timer incident from overtime excess time, timer chain meter pointer, timer queue synchrolock mechanism, timer expiry operation.
Further, step g is further comprising the steps of:
G1. select to judge according to the user whether this timer function also will continue to use, if then enter the g2 step, if not then enter g3;
G2. its timer_remain_value counter is made as timer_max_value again;
G3. in timer queue, nullify this timer node.
Concrete, further comprising the steps of:
H. the user can nullify operation by timer ID number at any time in main thread.
The invention has the beneficial effects as follows, timer is unified control by the implementation method of above-mentioned a kind of timer, clear to a plurality of timer managements, make things convenient for the integral transplanting of software module, and adopt the select function can obtain than higher precision.
Embodiment
Below in conjunction with embodiment, describe technical scheme of the present invention in detail.
The invention provides a kind of implementation method of timer, at first main thread is created timer queue, and with the timer queue initialization, generate a node that is used for managing this formation, so that to the various operations of this timer queue, user thread is created software timer then, initialization timing device parameter, main thread is created sub-thread according to the software timer that the user creates again, by hardware clock initializers clock, finish the registration of this timer in formation, in this process, carry out the latching operation that adds of queue operation shared lock, release after finishing, sub-thread is all user-defined timer nodes in the taking turn formation in order, utilize the select function to judge one by one whether the value of its timer_remain_value counter is 0, reach overtime timer event if then carry out, if not then its timer_remain_value counter is subtracted " 1 " operation, get back to sub-thread that step of taking turn in order.
Embodiment
This example adopts the present invention program to carry out the realization of timer.
At first main thread is created timer queue, and with the timer queue initialization, generate a node that is used for managing this formation, so that to the various operations of this timer queue, as adding, deletion, empty or the like, user thread is created software timer then, initialization timing device parameter, timer parameter comprises timer ID number, the timer expiry time, timer is from overtime excess time, the timer chain meter pointer, timer queue synchrolock mechanism, the incident of timer expiry operation, main thread is created sub-thread according to the software timer that the user creates again, by hardware clock initializers clock, finish the registration of this timer in formation, in this process, carry out the latching operation that adds of queue operation shared lock, release after finishing, sub-thread is all user-defined timer nodes in the taking turn formation in order, utilize the select function to judge one by one whether the value of its timer_remain_value counter is 0, if not then its timer_remain_value counter is subtracted " 1 " operation, get back to sub-thread that step of taking turn in order, if then carry out and reach overtime timer event, select to judge according to the user whether this timer function also will continue to use, if then its timer_remain_value counter is made as timer_max_value again, if not then nullify this timer node in timer queue, the user can nullify operation by timer ID number at any time in main thread.
Claims (4)
1. the implementation method of a timer is characterized in that, may further comprise the steps:
A. main thread is created timer queue, and with the timer queue initialization, generates a node that is used for managing this formation, so that to the various operations of this timer queue;
B. user thread is created software timer, initialization timing device parameter;
C. main thread is created sub-thread according to the software timer that the user creates, by hardware clock initializers clock;
D. main thread is created the operation of software timer according to the user, finishes the registration of this timer in formation, carries out the latching operation that adds of queue operation shared lock in this process, release after finishing;
E. sub-thread is all user-defined timer nodes in the taking turn formation in order, utilize the select function to judge one by one whether the value of its timer_remain_value counter is 0, if then enter the g step, if not then enter the f step;
F. its timer_remain_value counter is subtracted " 1 " operation, get back to the e step;
G. carry out and reach overtime timer event.
2. according to the implementation method of the described a kind of timer of claim 1, it is characterized in that the described timer parameter of step b comprises timer ID number, timer expiry time, the timer incident from overtime excess time, timer chain meter pointer, timer queue synchrolock mechanism, timer expiry operation.
3. according to the implementation method of the described a kind of timer of claim 1, it is characterized in that step g is further comprising the steps of:
G1. select to judge according to the user whether this timer function also will continue to use, if then enter the g2 step, if not then enter g3;
G2. its timer_remain_value counter is made as timer_max_value again;
G3. in timer queue, nullify this timer node.
4. according to the implementation method of the described a kind of timer of claim 1, it is characterized in that, further comprising the steps of:
H. the user can nullify operation by timer ID number at any time in main thread.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN200910311448A CN101727352A (en) | 2009-12-15 | 2009-12-15 | Method for realizing timer |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN200910311448A CN101727352A (en) | 2009-12-15 | 2009-12-15 | Method for realizing timer |
Publications (1)
Publication Number | Publication Date |
---|---|
CN101727352A true CN101727352A (en) | 2010-06-09 |
Family
ID=42448281
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN200910311448A Pending CN101727352A (en) | 2009-12-15 | 2009-12-15 | Method for realizing timer |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN101727352A (en) |
Cited By (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102087513A (en) * | 2010-12-14 | 2011-06-08 | 广东雅达电子股份有限公司 | Timing extension method of PLC (programmable logic controller) timer |
CN102185860A (en) * | 2011-05-10 | 2011-09-14 | 清华大学 | Standardized bottom layer control driving system for integrated circuit manufacturing equipment |
CN102207888A (en) * | 2011-05-09 | 2011-10-05 | 大唐移动通信设备有限公司 | Method and device for managing timer |
CN102937893A (en) * | 2012-10-11 | 2013-02-20 | 科立讯通信股份有限公司 | Software timing method of dynamic overload timing length |
CN104391732A (en) * | 2014-11-20 | 2015-03-04 | 中国船舶重工集团公司第七二六研究所 | Software multi-timer dynamic state management method |
CN104951282A (en) * | 2015-05-21 | 2015-09-30 | 中国人民解放军理工大学 | Timer management system and method |
CN105700913A (en) * | 2015-12-30 | 2016-06-22 | 广东工业大学 | Method for creation and parallel operation of lightweight bare chip codes |
CN106681715A (en) * | 2016-12-09 | 2017-05-17 | 北京五八信息技术有限公司 | Timing function implementation method and system |
CN110569977A (en) * | 2019-07-23 | 2019-12-13 | 北京航天自动控制研究所 | reusable timing method for parallel time limit reasoning of real-time expert system |
CN110968147A (en) * | 2018-09-30 | 2020-04-07 | 武汉斗鱼网络科技有限公司 | Timer creating method and device, electronic equipment and medium |
CN111814007A (en) * | 2020-07-31 | 2020-10-23 | 新华三信息安全技术有限公司 | Method, device and equipment for processing data of doubly-linked list and machine-readable storage medium |
CN111813552A (en) * | 2020-07-16 | 2020-10-23 | 济南浪潮数据技术有限公司 | Scheduling execution method, device and medium based on multi-thread task |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101272564A (en) * | 2008-04-17 | 2008-09-24 | 中兴通讯股份有限公司 | Soft real-time timing device module and method for soft real-time timing device scheduling |
-
2009
- 2009-12-15 CN CN200910311448A patent/CN101727352A/en active Pending
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101272564A (en) * | 2008-04-17 | 2008-09-24 | 中兴通讯股份有限公司 | Soft real-time timing device module and method for soft real-time timing device scheduling |
Cited By (19)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102087513A (en) * | 2010-12-14 | 2011-06-08 | 广东雅达电子股份有限公司 | Timing extension method of PLC (programmable logic controller) timer |
CN102207888A (en) * | 2011-05-09 | 2011-10-05 | 大唐移动通信设备有限公司 | Method and device for managing timer |
CN102185860A (en) * | 2011-05-10 | 2011-09-14 | 清华大学 | Standardized bottom layer control driving system for integrated circuit manufacturing equipment |
CN102937893A (en) * | 2012-10-11 | 2013-02-20 | 科立讯通信股份有限公司 | Software timing method of dynamic overload timing length |
CN102937893B (en) * | 2012-10-11 | 2016-07-06 | 科立讯通信股份有限公司 | A kind of software timing method of dynamic heavy duty timed length |
CN104391732B (en) * | 2014-11-20 | 2018-12-11 | 中国船舶重工集团公司第七二六研究所 | The more timer dynamic management approach of software |
CN104391732A (en) * | 2014-11-20 | 2015-03-04 | 中国船舶重工集团公司第七二六研究所 | Software multi-timer dynamic state management method |
CN104951282A (en) * | 2015-05-21 | 2015-09-30 | 中国人民解放军理工大学 | Timer management system and method |
CN105700913A (en) * | 2015-12-30 | 2016-06-22 | 广东工业大学 | Method for creation and parallel operation of lightweight bare chip codes |
CN105700913B (en) * | 2015-12-30 | 2018-10-12 | 广东工业大学 | A kind of parallel operation method of lightweight bare die code |
CN106681715A (en) * | 2016-12-09 | 2017-05-17 | 北京五八信息技术有限公司 | Timing function implementation method and system |
CN110968147A (en) * | 2018-09-30 | 2020-04-07 | 武汉斗鱼网络科技有限公司 | Timer creating method and device, electronic equipment and medium |
CN110968147B (en) * | 2018-09-30 | 2022-04-12 | 武汉斗鱼网络科技有限公司 | Timer creating method and device, electronic equipment and medium |
CN110569977A (en) * | 2019-07-23 | 2019-12-13 | 北京航天自动控制研究所 | reusable timing method for parallel time limit reasoning of real-time expert system |
CN110569977B (en) * | 2019-07-23 | 2022-04-22 | 北京航天自动控制研究所 | Reusable timing method for parallel time limit reasoning of real-time expert system |
CN111813552A (en) * | 2020-07-16 | 2020-10-23 | 济南浪潮数据技术有限公司 | Scheduling execution method, device and medium based on multi-thread task |
CN111813552B (en) * | 2020-07-16 | 2021-12-03 | 济南浪潮数据技术有限公司 | Scheduling execution method, device and medium based on multi-thread task |
CN111814007A (en) * | 2020-07-31 | 2020-10-23 | 新华三信息安全技术有限公司 | Method, device and equipment for processing data of doubly-linked list and machine-readable storage medium |
CN111814007B (en) * | 2020-07-31 | 2023-03-31 | 新华三信息安全技术有限公司 | Method, device and equipment for processing data of doubly-linked list and machine-readable storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN101727352A (en) | Method for realizing timer | |
US8583957B2 (en) | Clock distribution in a distributed system with multiple clock domains over a switched fabric | |
CN105027440B (en) | State machine for the low noise timing of high frequency clock | |
CN104182223B (en) | Clocking method and time set | |
US20100211682A1 (en) | Method and system for exclusive access to shared resources in a database | |
David et al. | Schedulability of herschel-planck revisited using statistical model checking | |
US7890561B2 (en) | Random number generator | |
Valverde et al. | Logarithmic growth dynamics in software networks | |
CN106575961A (en) | Automatic calibration circuits for operational calibration of critical-path time delays in adaptive clock distribution systems, and related methods and systems | |
CN100480950C (en) | Apparatus and method for controlling asynchronous clock domains to perform synchronous operations | |
CN103823810A (en) | Method, device and system for generating unique keys in distributed system | |
TW201015440A (en) | Lock windows for reducing contention | |
TW200844728A (en) | Techniques for generating a trace stream for a data processing apparatus | |
CN109725185A (en) | A kind of oscillograph and its operation method for realizing waveform fast Acquisition | |
CN104035786A (en) | Optimization method and system of software timers | |
CN107247770A (en) | Global sequence's generation method and device based on zookeeper | |
US20020165888A1 (en) | Random number generation method and system | |
CN102937893B (en) | A kind of software timing method of dynamic heavy duty timed length | |
CN108958948A (en) | A kind of timer event processing method, database and timer | |
US20100005332A1 (en) | Method and system for distributing a global timebase within a system-on-chip having multiple clock domains | |
US20090248689A1 (en) | Generation of suggestions to correct data race errors | |
Debreceni et al. | Property-based locking in collaborative modeling | |
Chruślińska | Chemical evolution of the Universe and its consequences for gravitational‐wave astrophysics | |
CN102662632A (en) | Serial number generation method based on semaphore and generator. | |
CN100512263C (en) | Method for triggering related timer |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C02 | Deemed withdrawal of patent application after publication (patent law 2001) | ||
WD01 | Invention patent application deemed withdrawn after publication |
Application publication date: 20100609 |