CN104391732A - Software multi-timer dynamic state management method - Google Patents

Software multi-timer dynamic state management method Download PDF

Info

Publication number
CN104391732A
CN104391732A CN201410668924.9A CN201410668924A CN104391732A CN 104391732 A CN104391732 A CN 104391732A CN 201410668924 A CN201410668924 A CN 201410668924A CN 104391732 A CN104391732 A CN 104391732A
Authority
CN
China
Prior art keywords
timer
queue
node
timerqueue
stored
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.)
Granted
Application number
CN201410668924.9A
Other languages
Chinese (zh)
Other versions
CN104391732B (en
Inventor
姜洪宇
杜啸晓
刘杰
张孝华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
No726 Research Institute Of China Shipbuilding Industry Corp
Original Assignee
No726 Research Institute Of China Shipbuilding Industry Corp
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by No726 Research Institute Of China Shipbuilding Industry Corp filed Critical No726 Research Institute Of China Shipbuilding Industry Corp
Priority to CN201410668924.9A priority Critical patent/CN104391732B/en
Publication of CN104391732A publication Critical patent/CN104391732A/en
Application granted granted Critical
Publication of CN104391732B publication Critical patent/CN104391732B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention provides a software multi-timer dynamic state management method. The software multi-timer dynamic state management method comprises the following steps of firstly, defining a data structure and storing timer marks and timer overtime processing methods; defining a queue, storing multi-timer information and placing the mark and the processing method of the timer into the queue when the timer is opened every time; deleting the mark and the processing method of the timer from the queue when the timer is closed every time; opening the timers and adding the timer information into the queue; extracting a node from the queue, judging whether the timer mark stored inside the node is identical to that of the current overtime timer or not and judging the timer which is corresponding to the node is overtime and processing through the corresponding processing method inside the node if yes; judging whether all nodes are extracted or not if not and ending the operation if yes; extracting nodes to judge again if not. The software multi-timer dynamic state management method has the advantages of reducing unnecessary inquiries of unopened timers when multiple timers are opened and closed, reducing CPU (Central Processing Unit) expenditure and improving the system operation speed.

Description

Software many timers dynamic management approach
Technical field
The present invention relates to computer realm, particularly, relate to a kind of software many timers dynamic management approach.
Background technology
Timer, from literal understanding, be exactly a clock, after setting timing, after the time that experienced by setting, the personnel that timer is set will be notified, time has arrived, and can carry out further work, in daily life, we often can touch timer, such as, in semi-automatic washing machine, just have timer, from laundry, turn timing knob, timer is just opened, and get back to 0 to timing knob, timer time arrives, laundry terminates, and can carry out next step and bleed off the work such as addle.Here the timer that say is when doing computer software programming, a kind of software timer used, and computer software logic also often there will be to be needed to set one or more time, starts to do further work after time is up.Such as automatic washing machine, there is a computer panel the inside, the computer software run in this computer panel just has our said timer, software meeting Lookup protocol timer, start first step work, timer time to after start second step work etc. arranging timer.
In embedded systems; when using Microsoft Visual C++ write software code to carry out communication overtime supervision to multiple communication node simultaneously; often timer can be used; the using method of general timer uses SetTimer (UINTnIDEvent; UINT nElapse; void (CALLBACK EXPORT*lpfnTimer) (HWND; UINT; UINT; DWORD)) function; the mark of the timer of first Parametric Representation setting, does the process of timer expiry in timer response function.Generally needing whether the timer first judging current time-out is wait for needing timer to be processed, if so, then processing, if not then not processing.
As shown in Figure 1, in Microsoft Visual C++, conventional timer scheme is, use SetTimer (UINTnIDEvent, UINT nElapse, void (CALLBACK EXPORT*lpfnTimer) (HWND, UINT, UINT, DWORD)) function setup timer, the mark of general appointment timer, in time response function OnTimer (UINTnIDEvent), judge that whether the timer of current time-out is the timer arranged, namely in OnTimer (UINT nIDEvent), whether nIDEvent equals SetTimer (UINT nIDEvent, UINT nElapse, nIDEvent in void (CALLBACK EXPORT*lpfnTimer).If the same process.If current timer needs to close, then call function KillTimer (int nIDEvent) timeing closing device is designated the timer of nIDEvent, so when timer is opened, the timer ID nIDEvent of unlatching must be recorded, use during timeing closing device below.The shortcoming of this way is: the timer that can establish can not be too many, otherwise, when the timer of a thread is too much, need to do a large amount of judgements in timer processing function, judge which timer expiry current be, the CPU overhead that this judgement brings is considerable in the embedded system of resource-constrained, and this way can only arrange the timer of pre-specified timer ID symbol, quantity is changed at any time, the situation that the opening and closing of each timer also change at any time, this way is just very difficult to realize.
The statement of conventional timer is exemplified below:
SetTimer(101,300,NULL);
Arrange the timer that timer ID is 101, timing is 300 milliseconds.
SetTimer(200,50,NULL);
Arrange the timer that timer ID is 200, timing is 50 milliseconds.
This routine current time opens two timers, but in this routine, supposes to use 100 timers.Then general timer response function is as follows:
In the scheme citing of above-described use timer, there are 100 timers, then need judge in OnTimer (UINTnIDEvent) function that current is which timer time has arrived, and, timer is more, then need judge number of times may be more, if the timer of current time time-out is timer 2 00, then in OnTimer (UINTnIDEvent) function, need judgement just can judge current timer 100 times.And if the shortest current timing is 50ms, then within 50ms, computing machine at least will enter OnTimer (UINT nIDEvent) function once, and do 100 judgements, the expense of CPU is very large.
The present invention will solve and develop software in process at use Microsoft Visual C++, and in many timers situation, timer number is variable, and when each timer open and close state also changes at any time, the timer caused is difficult to management, the problem that CPU overhead is large.
Summary of the invention
For defect of the prior art, the object of this invention is to provide a kind of software many timers dynamic management approach.
According to an aspect of the present invention, a kind of software many timers dynamic management approach is provided, comprises the following steps:
Step 1: definition data structure TimerData, stores timer ID TimerID and timer expiry disposal route TimerFun;
Step 2: definition queue TimerQueue, store many timer informations, the data structure form of the node of this queue is TimerData, and often open a timer, be put in queue by the mark of this timer and disposal route, the nodes of queue adds 1; Often close a timer, just the mark of this timer and disposal route are deleted from queue, the nodes of queue subtracts 1;
Step 3: opening timing device, adds queue by timer information;
Step 4: take out a node from queue, whether the timer ID stored in decision node is identical with the timer ID of current time-out, if identical, performs step 5, otherwise, if different, then perform step 6;
Step 5: the timer ID stored in node is identical with the timer ID of current time-out, the timer expiry that this node is corresponding, according to disposal methods corresponding in node;
Step 6: judge whether to take out all nodes, if so, then end operation; Otherwise, repeat step 4.
Preferably, in step 2, in queue TimerQueue, definition of T imerQueue [n] represents N number of node of TimerQueue; TimerQueue [n] .TimerID represents the timer ID stored in N number of node of TimerQueue; TimerQueue [n] .TimerFun represents the timer expiry disposal route stored in N number of node of TimerQueue.
Preferably, whether step 4 is identical with the timer ID of current time-out by the timer ID stored in timer response function decision node, be specially: in timer response function, find out timer ID TimerQueue [n] .TimerID all in queue successively, compared with the timer ID nID in current timer response function, if identical, then current timer expiry corresponding to TimerQueue [n] .TimerID.
Compared with prior art, the present invention has following beneficial effect: the present invention avoids the mode of traditional Static Inquiry by the timer ID and timer processing method using the current unlatching of queue record, reduce the inessential inquiry when the dynamic open and close of many timers to non-opening timing device, decrease CPU overhead, improve the travelling speed of system.
Accompanying drawing explanation
By reading the detailed description done non-limiting example with reference to the following drawings, other features, objects and advantages of the present invention will become more obvious:
Fig. 1 is conventional many timers responding process figure;
Fig. 2 is software many timers dynamic management approach process principle figure of the present invention.
Embodiment
Below in conjunction with specific embodiment, the present invention is described in detail.Following examples will contribute to those skilled in the art and understand the present invention further, but not limit the present invention in any form.It should be pointed out that to those skilled in the art, without departing from the inventive concept of the premise, some distortion and improvement can also be made.These all belong to protection scope of the present invention.
A kind of software many timers dynamic management approach, comprises the following steps:
Step 1: definition data structure TimerData, stores timer ID TimerID and timer expiry disposal route TimerFun.
Step 2: definition queue TimerQueue, store many timer informations, the data structure form of the node of this queue is TimerData, and often open a timer, be put in queue by the mark of this timer and disposal route, the nodes of queue adds 1; Often close a timer, just the mark of this timer and disposal route are deleted from queue, the nodes of queue subtracts 1.
Should be an empty queue when queue just defines, namely nodes be 0.Further, definition of T imerQueue [n] represents N number of node of TimerQueue, TimerQueue [n] .TimerID represents the timer ID stored in N number of node of TimerQueue, and TimerQueue [n] .TimerFun represents the timer expiry disposal route stored in N number of node of TimerQueue.
Step 3: opening timing device, adds queue by timer information.
Step 4: take out a node from queue, whether the timer ID stored in decision node is identical with the timer ID of current time-out, if identical, performs step 5, otherwise, if different, then perform step 6.
Step 5: the timer ID stored in node is identical with the timer ID of current time-out, the timer expiry that this node is corresponding, according to disposal methods corresponding in node.
Particularly, whether the timer ID by storing in timer response function decision node in step 4 is identical with the timer ID of current time-out, in timer response function, find out timer ID TimerQueue [n] .TimerID all in queue successively, compared with the timer ID nID in current timer response function, if identical, current timer expiry corresponding to TimerQueue [n] .TimerID is then described, then uses corresponding disposal route TimerQueue [n] .Fun process in step 5.
Step 6: judge whether to take out all nodes, if so, then end operation; Otherwise, repeat step 4.
In a preferred embodiment of the present invention, may use at most 64 timers, the timing of each timer has 100ms, 300ms, 500ms tri-kinds, the most of the time of this example only opens a timer, and, the disposal route of each timer is not quite similar, and adopts the solution of the present invention, the most of the time, in timer response function, each need judge once just can complete respective handling, and compare traditional timer processing method, speed improves a lot.
Above specific embodiments of the invention are described.It is to be appreciated that the present invention is not limited to above-mentioned particular implementation, those skilled in the art can make various distortion or amendment within the scope of the claims, and this does not affect flesh and blood of the present invention.

Claims (3)

1. software many timers dynamic management approach, is characterized in that, comprises the following steps:
Step 1: definition data structure TimerData, stores timer ID TimerID and timer expiry disposal route TimerFun;
Step 2: definition queue TimerQueue, store many timer informations, the data structure form of the node of this queue is TimerData, and often open a timer, be put in queue by the mark of this timer and disposal route, the nodes of queue adds 1; Often close a timer, just the mark of this timer and disposal route are deleted from queue, the nodes of queue subtracts 1;
Step 3: opening timing device, adds queue by timer information;
Step 4: take out a node from queue, whether the timer ID stored in decision node is identical with the timer ID of current time-out, if identical, performs step 5, otherwise, if different, then perform step 6;
Step 5: the timer ID stored in node is identical with the timer ID of current time-out, the timer expiry that this node is corresponding, according to disposal methods corresponding in node;
Step 6: judge whether to take out all nodes, if so, then end operation; Otherwise, repeat step 4.
2. software many timers dynamic management approach according to claim 1, is characterized in that, in step 2, in described queue TimerQueue, definition of T imerQueue [n] represents N number of node of TimerQueue;
TimerQueue [n] .TimerID represents the timer ID stored in N number of node of TimerQueue;
TimerQueue [n] .TimerFun represents the timer expiry disposal route stored in N number of node of TimerQueue.
3. software many timers dynamic management approach according to claim 2, it is characterized in that, whether step 4 is identical with the timer ID of current time-out by the timer ID stored in timer response function decision node, be specially: in timer response function, find out timer ID TimerQueue [n] .TimerID all in queue successively, compared with the timer ID nID in current timer response function, if identical, then current timer expiry corresponding to TimerQueue [n] .TimerID.
CN201410668924.9A 2014-11-20 2014-11-20 The more timer dynamic management approach of software Active CN104391732B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410668924.9A CN104391732B (en) 2014-11-20 2014-11-20 The more timer dynamic management approach of software

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410668924.9A CN104391732B (en) 2014-11-20 2014-11-20 The more timer dynamic management approach of software

Publications (2)

Publication Number Publication Date
CN104391732A true CN104391732A (en) 2015-03-04
CN104391732B CN104391732B (en) 2018-12-11

Family

ID=52609640

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410668924.9A Active CN104391732B (en) 2014-11-20 2014-11-20 The more timer dynamic management approach of software

Country Status (1)

Country Link
CN (1) CN104391732B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105573841A (en) * 2015-12-10 2016-05-11 北京京东尚科信息技术有限公司 Method for controlling worker execution based on non-relational database
CN106549879A (en) * 2015-09-22 2017-03-29 同方威视技术股份有限公司 Can the processing method of auto-associating gathered data, processing meanss and its detecting system
CN107870812A (en) * 2017-11-17 2018-04-03 南京国电南自轨道交通工程有限公司 One kind is based on single thread concurrently more timer application management methods

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101014049A (en) * 2007-02-14 2007-08-08 中兴通讯股份有限公司 Method for managing timer of terminal wireless communication protocol stack sofeware
CN101727352A (en) * 2009-12-15 2010-06-09 四川长虹电器股份有限公司 Method for realizing timer
CN102207888A (en) * 2011-05-09 2011-10-05 大唐移动通信设备有限公司 Method and device for managing timer
CN104093199A (en) * 2014-07-29 2014-10-08 中国联合网络通信集团有限公司 Timer setting method and terminal

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101014049A (en) * 2007-02-14 2007-08-08 中兴通讯股份有限公司 Method for managing timer of terminal wireless communication protocol stack sofeware
CN101727352A (en) * 2009-12-15 2010-06-09 四川长虹电器股份有限公司 Method for realizing timer
CN102207888A (en) * 2011-05-09 2011-10-05 大唐移动通信设备有限公司 Method and device for managing timer
CN104093199A (en) * 2014-07-29 2014-10-08 中国联合网络通信集团有限公司 Timer setting method and terminal

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106549879A (en) * 2015-09-22 2017-03-29 同方威视技术股份有限公司 Can the processing method of auto-associating gathered data, processing meanss and its detecting system
CN106549879B (en) * 2015-09-22 2021-07-27 同方威视技术股份有限公司 Processing method and processing device capable of automatically associating acquired data and detection system thereof
CN105573841A (en) * 2015-12-10 2016-05-11 北京京东尚科信息技术有限公司 Method for controlling worker execution based on non-relational database
CN105573841B (en) * 2015-12-10 2019-06-04 北京京东尚科信息技术有限公司 A method of the control timer based on non-relational database executes
CN107870812A (en) * 2017-11-17 2018-04-03 南京国电南自轨道交通工程有限公司 One kind is based on single thread concurrently more timer application management methods
CN107870812B (en) * 2017-11-17 2021-06-15 南京国电南自轨道交通工程有限公司 Application management method based on single thread concurrent multi-timer

Also Published As

Publication number Publication date
CN104391732B (en) 2018-12-11

Similar Documents

Publication Publication Date Title
CN107526645B (en) A kind of communication optimization method and system
CN106790599B (en) A kind of symbiosis virtual machine communication method based on multicore without lock buffer circle
CN106407430A (en) Complex and intelligent contract state synchronization method based on phase buckets
CN104035786B (en) The optimization method and system of a kind of software timer
CN104391732A (en) Software multi-timer dynamic state management method
CN106445617A (en) Android-based application program cold-start optimization method and Android-based application program cold-start optimization system
CN104331315B (en) A kind of parsing of arbitrary levels json objects and generation method and system
CN106485141A (en) The detection of abnormal traffic thread and processing method under JAVA environment
CN102253860A (en) Asynchronous operation method and asynchronous operation management device
CN107589990B (en) Data communication method and system based on thread pool
CN108021449A (en) One kind association journey implementation method, terminal device and storage medium
CN101727423B (en) System capable of preempting multiple hardware tasks on reconfigurable FPGA and implementing method thereof
CN106886450A (en) Method for scheduling task and system
CN108073688A (en) A kind of method and device of Data Migration
CN106250429A (en) A kind of data pick-up method based on sqoop
CN103885376A (en) Programmable logic controller and event-driven programming method thereof
CN108572594A (en) Generation method, device and the terminal device of smart machine control instruction
CN103927244B (en) A kind of method of the plug-in unit scheduling process monitoring realized based on dynamic proxy
CN107506906A (en) A kind of task intelligent scheduling engine design method based on data processing
CN102945264B (en) Method for intelligently starting distributed transaction
CN106775620A (en) A kind of timing method and device
CN103324469A (en) Timer implementation method and device
CN107239210A (en) Terminal control method, device, computer installation and storage medium
US11301792B2 (en) Cross domain integration in product lifecycle management
CN104699607A (en) Automation testing method and system for mobile terminal

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant