CN104391732B - The more timer dynamic management approach of software - Google Patents

The more timer dynamic management approach of software Download PDF

Info

Publication number
CN104391732B
CN104391732B CN201410668924.9A CN201410668924A CN104391732B CN 104391732 B CN104391732 B CN 104391732B CN 201410668924 A CN201410668924 A CN 201410668924A CN 104391732 B CN104391732 B CN 104391732B
Authority
CN
China
Prior art keywords
timer
queue
node
timerqueue
processing method
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.)
Active
Application number
CN201410668924.9A
Other languages
Chinese (zh)
Other versions
CN104391732A (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 present invention provides a kind of more timer dynamic management approach of software, firstly, definition data structure, stores timer ID and timer expiry processing method;Then, queue is defined, stores more timer informations, the mark of this timer and processing method are put into queue by one timer of every opening;As soon as every closing timer, the mark of this timer and processing method are deleted from queue;Queue is added in timer information by opening timing device;A node is taken out from queue, judges whether the timer ID stored in node is identical as the timer ID of current time-out, if they are the same the then corresponding timer expiry of the node, according to processing method corresponding in node processing;Otherwise, it is determined whether all nodes are had been taken out, if so, end operation;Otherwise, node judgement is extracted again.The present invention reduces inessential inquiries when more timer dynamic open and close to non-opening timing device, reduce CPU overhead, improve system operational speed.

Description

The more timer dynamic management approach of software
Technical field
The present invention relates to computer fields, and in particular, to a kind of more timer dynamic management approach of software.
Background technique
Timer is exactly a clock from literal understanding, after setting timing, experienced the time of setting Later, the personnel of setting timer are informed about, the time has arrived, further work can be carried out, in daily life, We can often touch timer, for example, just there is timer in semi-automatic washing machine, from starting to do washing, and turn timing knob, Timer is switched on, and returns to 0 to timing knob, and timer time arrives, and laundry terminates, and can carry out bleeding off the works such as dirty water in next step Make.Here the timer that say is a kind of software timer used when doing computer software programming, and computer is soft Part logic also often will appear needs and set one or more times, start to do further work after time is up.Such as Automatic washing machine, as soon as there is a computer panel in the inside, the computer software run in this computer panel has me Described timer, software timer can be set automatically, start first step work, be arranged in timer time after Timer starts second step work etc..
In embedded systems, using Microsoft Visual C++ write software code simultaneously to multiple communication nodes When carrying out communication timeout monitoring, timer is often used, the application method of general timer is using SetTimer (UINT nIDEvent,UINT nElapse,void(CALLBACK EXPORT*lpfnTimer)(HWND,UINT,UINT,DWORD)) Function, first parameter indicate the mark of the timer of setting, the processing of timer expiry are done in timer response function.One As need to first determine whether the timer of current time-out is to wait timer to be treated, if it is, processing, if not It is not handle.
As shown in Figure 1, common timer scheme is to use SetTimer in Microsoft Visual C++ (UINT nIDEvent,UINT nElapse,void(CALLBACK EXPORT*lpfnTimer)(HWND,UINT,UINT, DWORD)) function setup timer, the mark of general specified timer, in time response function OnTimer (UINT NIDEvent in), judge current time-out timer whether be setting timer, i.e. in OnTimer (UINT nIDEvent) Whether nIDEvent is equal to SetTimer (UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* LpfnTimer the nIDEvent in).If the same it handles.If current timer needs to close, function is called KillTimer (int nIDEvent) Off Timer is identified as the timer of nIDEvent, so when timer is opened, it must The timer ID nIDEvent opened must be recorded, is used when Off Timer below.The shortcomings that this way, is: can set Timer cannot be too many, otherwise, when the timer of a thread is excessive, needs to do in timer processing function and largely sentence Disconnected, which timer expiry judgement is currently, and CPU overhead brought by this judgement is in the limited embedded system of resource It is considerable, and the timer of pre-specified timer ID symbol can only be arranged in this way, at any time for quantity The case where variation, the opening and closing of each timer also change at any time, this way is with regard to very difficult.
The sentence of common timer is exemplified below:
SetTimer(101,300,NULL);
The timer that timer ID is 101 is set, and timing is 300 milliseconds.
SetTimer(200,50,NULL);
The timer that timer ID is 200 is set, and timing is 50 milliseconds.
This routine current time opens two timers, but in this routine, it is assumed that may use 100 timers.Then General timer response function is as follows:
In scheme citing described above using timer, there are 100 timers, then it need to be in OnTimer (UINT NIDEvent) judge it is currently which timer time arrives in function, moreover, timer is more, then need to judge is secondary Number may be more, if the timer of current time time-out is timer 2 00, in OnTimer (UINT nIDEvent) letter In number, need to judge 100 times just judge current timer.Moreover, if current shortest timing is 50ms, Within 50ms, computer is at least primary into OnTimer (UINT nIDEvent) function, does 100 judgements, the expense of CPU It is very big.
The invention solves using Microsoft Visual C++ exploitation software process in, in the case of more timers, Timer number is variable, when each timer open and close state also changes at any time, caused by timer be difficult to manage, CPU is opened Sell big problem.
Summary of the invention
For the defects in the prior art, the object of the present invention is to provide a kind of more timer dynamic management approach of software.
According to an aspect of the present invention, a kind of more timer dynamic management approach of software are provided, comprising the following steps:
Step 1: definition data structure TimerData stores timer ID TimerID and timer expiry processing method TimerFun;
Step 2: defining queue TimerQueue, store more timer informations, the data structure form of the node of the queue For TimerData, the mark of this timer and processing method are put into queue, the node of queue by one timer of every opening Number plus 1,;As soon as every closing timer, the mark of this timer and processing method is deleted from queue, the number of nodes of queue Subtract 1;
Step 3: queue is added in timer information by opening timing device;
Step 4: from queue take out a node, judge the timer ID stored in node whether with it is current time-out Timer ID is identical, thens follow the steps 5 if they are the same, otherwise, if it is different, thening follow the steps 6;
Step 5: the timer ID stored in node is identical as the timer ID of current time-out, and the node is corresponding fixed When device time-out, according to processing method corresponding in node handle;
Step 6: judging whether to have been taken out all nodes, if so, end operation;Otherwise, step 4 is repeated.
Preferably, in step 2, TimerQueue [n] is defined in queue TimerQueue indicates the n-th of TimerQueue Node;The timer ID stored in the n-th node of TimerQueue [n] .TimerID expression TimerQueue; The timer expiry processing method stored in the n-th node of TimerQueue [n] .TimerFun expression TimerQueue.
Preferably, step 4 by timer response function judge the timer ID stored in node whether with currently surpass When timer ID it is identical, specifically: in timer response function, successively find out timer ID all in queue TimerQueue [n] .TimerID, compared with the timer ID nID in current timer receptance function, if identical, It is currently timer expiry corresponding to TimerQueue [n] .TimerID.
Compared with prior art, the present invention is with following the utility model has the advantages that by the present invention in that currently being opened with queue record The timer ID and timer processing method opened avoids the mode of traditional Static Inquiry, reduces and opens in more timers dynamics Inessential inquiry when opening closing to non-opening timing device, reduces CPU overhead, improves the speed of service of system.
Detailed description of the invention
Upon reading the detailed description of non-limiting embodiments with reference to the following drawings, other feature of the invention, Objects and advantages will become more apparent upon:
Fig. 1 is conventional more timer response flow charts;
Fig. 2 is the more timer dynamic management approach process principle figures of invention software.
Specific embodiment
The present invention is described in detail combined with specific embodiments below.Following embodiment will be helpful to the technology of this field Personnel further understand the present invention, but the invention is not limited in any way.It should be pointed out that the ordinary skill of this field For personnel, without departing from the inventive concept of the premise, various modifications and improvements can be made.These belong to the present invention Protection scope.
A kind of more timer dynamic management approach of software, comprising the following steps:
Step 1: definition data structure TimerData stores timer ID TimerID and timer expiry processing method TimerFun。
Step 2: defining queue TimerQueue, store more timer informations, the data structure form of the node of the queue For TimerData, the mark of this timer and processing method are put into queue, the node of queue by one timer of every opening Number plus 1,;As soon as every closing timer, the mark of this timer and processing method is deleted from queue, the number of nodes of queue Subtract 1.
Queue be an empty queue when just defining, i.e., number of nodes is 0.Further, TimerQueue [n] is defined It indicates the n-th node of TimerQueue, is deposited in the n-th node of TimerQueue [n] .TimerID expression TimerQueue The timer ID of storage, TimerQueue [n] .TimerFun indicate the timer that stores in the n-th node of TimerQueue Timeout treatment method.
Step 3: queue is added in timer information by opening timing device.
Step 4: from queue take out a node, judge the timer ID stored in node whether with it is current time-out Timer ID is identical, thens follow the steps 5 if they are the same, otherwise, if it is different, thening follow the steps 6.
Step 5: the timer ID stored in node is identical as the timer ID of current time-out, and the node is corresponding fixed When device time-out, according to processing method corresponding in node handle.
Specifically, in step 4 by timer response function judge the timer ID stored in node whether with currently The timer ID of time-out is identical, in timer response function, successively finds out timer ID all in queue TimerQueue [n] .TimerID, compared with the timer ID nID in current timer receptance function, if identical, Illustrate currently to be timer expiry corresponding to TimerQueue [n] .TimerID, then uses corresponding processing method in step 5 TimerQueue [n] .Fun processing.
Step 6: judging whether to have been taken out all nodes, if so, end operation;Otherwise, step 4 is repeated.
In a preferred embodiment of the present invention, at most may use to 64 timers, the timing of each timer There is 100ms in time, and tri- kinds of 300ms, 500ms, the most of the time of this example only opens a timer, moreover, each timing The processing method of device is all not quite similar, and using the solution of the present invention, the most of the time in timer response function, only needs every time Judgement can once complete respective handling, and compared to traditional timer processing method, speed is improved very much.
Specific embodiments of the present invention are described above.It is to be appreciated that the invention is not limited to above-mentioned Particular implementation, those skilled in the art can make various deformations or amendments within the scope of the claims, this not shadow Ring substantive content of the invention.

Claims (3)

1. a kind of more timer dynamic management approach of software, which comprises the following steps:
Step 1: definition data structure TimerData stores timer ID TimerID and timer expiry processing method TimerFun;
Step 2: defining queue TimerQueue, store more timer informations, the data structure form of the node of the queue is TimerData, one timer of every opening, the mark of this timer and processing method is put into queue, the number of nodes of queue Add 1,;As soon as every closing timer, the mark of this timer and processing method is deleted from queue, the number of nodes of queue subtracts 1;
Step 3: queue is added in timer information by opening timing device;
Step 4: from queue take out a node, judge the timer ID stored in node whether the timing with current time-out Device mark is identical, 5 is thened follow the steps if they are the same, otherwise, if it is different, thening follow the steps 6;
Step 5: the timer ID stored in node is identical as the timer ID of current time-out, the corresponding timer of the node Time-out is handled according to processing method corresponding in node;
Step 6: judging whether to have been taken out all nodes, if so, end operation;Otherwise, step 4 is repeated;
The more timer dynamic management approach of software, most of the time only open a timer, moreover, each timer Processing method is all not quite similar;Most of the time in timer response function, only need to judge once complete corresponding position every time Reason.
2. the more timer dynamic management approach of software according to claim 1, which is characterized in that in step 2, the queue TimerQueue [n] is defined in TimerQueue indicates the n-th node of TimerQueue;
The timer ID stored in the n-th node of TimerQueue [n] .TimerID expression TimerQueue;
The timer expiry processing side stored in the n-th node of TimerQueue [n] .TimerFun expression TimerQueue Method.
3. the more timer dynamic management approach of software according to claim 2, which is characterized in that step 4 passes through timer Receptance function judges whether the timer ID stored in node is identical as the timer ID of current time-out, specifically: fixed When device receptance function in, timer ID TimerQueue [n] .TimerID all in queue is successively found out, with current timing Timer ID nID in device receptance function compares, if identical, is currently
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 CN104391732A (en) 2015-03-04
CN104391732B true 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)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106549879B (en) * 2015-09-22 2021-07-27 同方威视技术股份有限公司 Processing method and processing device capable of automatically associating acquired data and detection system thereof
CN105573841B (en) * 2015-12-10 2019-06-04 北京京东尚科信息技术有限公司 A method of the control timer based on non-relational database executes
CN107870812B (en) * 2017-11-17 2021-06-15 南京国电南自轨道交通工程有限公司 Application management method based on single thread concurrent multi-timer

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

Also Published As

Publication number Publication date
CN104391732A (en) 2015-03-04

Similar Documents

Publication Publication Date Title
CN107526645B (en) A kind of communication optimization method and system
CN104915256B (en) A kind of the Real-Time Scheduling implementation method and its system of task
CN106790599B (en) A kind of symbiosis virtual machine communication method based on multicore without lock buffer circle
CN104050029B (en) A kind of task scheduling system
CN104391732B (en) The more timer dynamic management approach of software
CN107665234A (en) Method for processing business, device, server and storage medium
CN104035786B (en) The optimization method and system of a kind of software timer
CN104298512B (en) A kind of functional unit formula integrated development system based on OSGi standards
CN108156181A (en) A kind of vulnerability detection method and its vulnerability scanning system based on the association asynchronous IO of journey
WO2015139510A1 (en) Method for cluster deployment
CN106886450A (en) Method for scheduling task and system
CN103391325A (en) Network operating system device and method for Internet of Things
CN106485141A (en) The detection of abnormal traffic thread and processing method under JAVA environment
CN104038390A (en) Linux server cluster unified peripheral event monitoring method based on netlink
CN106502770A (en) A kind of HMI state transfer methods based on finite state machine
CN103927244B (en) A kind of method of the plug-in unit scheduling process monitoring realized based on dynamic proxy
US6330527B1 (en) Apparatus and method for modeling frameworks via use of object-oriented analysis information
CN104462322B (en) Character string comparison method and device
CN109508323A (en) A kind of document storage system and file memory method
US20200282561A1 (en) Collaborative task execution by a robotic group using a distributed semantic knowledge base
CN103019849B (en) Virtual machine management method under cloud computing environment
CN107315686A (en) A kind of operation method of automatic test
CN105930100B (en) A kind of implementation method optimizing usim card file read-write speed and frequency
CN106775964A (en) The operating system framework and method for scheduling task of time/event mixing triggering
CN106201692A (en) A kind of timing task processing system and method

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