CN108874375A - A kind of implementation method and device of timer - Google Patents
A kind of implementation method and device of timer Download PDFInfo
- Publication number
- CN108874375A CN108874375A CN201810558752.8A CN201810558752A CN108874375A CN 108874375 A CN108874375 A CN 108874375A CN 201810558752 A CN201810558752 A CN 201810558752A CN 108874375 A CN108874375 A CN 108874375A
- Authority
- CN
- China
- Prior art keywords
- time
- timing node
- timing
- value
- index
- 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
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
- Accessory Devices And Overall Control Thereof (AREA)
Abstract
The implementation method and device of a kind of timer provided by the invention,In advance with the absolute time definition circulation moment stepper of system starting,Initialize the circulation moment stepper,Corresponding index position is distributed for each timing node,For storing the timing node,The timing node includes timer ID and timing length,And the event of the timing node is registered in the index chained list of the circulation moment stepper and the event is corresponding recalls to function,The present invention realizes the insertion and deletion of timing node by circulation moment stepper,The time scale being lost is judged using current system time by way of user thread active poll,Simplify the node book for needing to compare,Improve the efficiency that time-out determines,Simultaneously,The timing of time confirmation next time is executed according to time-out,To not executed the image of time by time-out,Guarantee that being fixed time-out time every time is called and does not generate overtime cumulative effect.
Description
Technical field
The present invention relates to timer technique fields, more particularly to the implementation method and device of a kind of timer.
Background technique
The timing tool that the mankind use earliest is hourglass or water leakage, but after clock and watch birth mature, people start
It attempts to improve timer using this completely new timing tool, achievees the purpose that accurately control the time.Timer is as software
A kind of common and necessary technology in exploitation, timer is a series of aggregate of functions, the method energy provided by using it
Enough make software is interior at a fixed time to complete specified function, its object is to make software is interior at a fixed time to execute certain automatically
Kind operation or task.
Common, high-precision timer borrows hardware timer and provides what the mode interrupted was realized, this is also software system
The system highest benchmark timer of precision.In the C programmer of actual computer, it is to compare that a module, which executes multiple operations,
It is common, still, if multiple operations carry out simultaneously, it may appear that program efficiency lowly, computer CPU (Central
Processing Unit, central processing unit) occupancy it is excessively high situations such as, at this moment just need sequence is executed to all operations
Make reasonable arrangement, therefore, relates to the use of timer.
In timer use process, timer in the prior art needs first to create timer node, timer node
Comprising time-out time, timeout callback function and other information, then by the timer node join of creation to timer manager
In chained list, the periodic scan chained list of separated in time is carried out by the thread in timer manager, and by the time of loss
It uniformly subtracts, when then passive triggering readjustment executes some node time-out.But this timer is when in use, new determines when having
When node when needing to be inserted into, then by the time complexity of timing Knots inserting chained list be according to time sequence O (m), and sweeping every time
It retouches and requires to subtract the time of loss for all timing nodes, time complexity is equally also O (m).
Summary of the invention
In view of the above problems, it proposes on the present invention overcomes the above problem or at least be partially solved in order to provide one kind
The implementation method and device of the timer of problem are stated, to realize the time for reducing timer timing Knots inserting in use
Complexity.
Specific technical solution is as follows:
A kind of implementation method of timer, in advance with the absolute time definition circulation moment stepper of system starting, initially
Change the circulation moment stepper, corresponding index position is distributed for each timing node, for storing the timing node, institute
Stating timing node includes timer ID and timing length, and in the index chained list of the circulation moment stepper described in registration
The event of the timing node and event is corresponding recalls to function, this method includes:
It is determined according to the absolute time and corresponding index value and is inserted into circulation moment stepping described in timing Knots inserting
The index position of device;
According to the index position by the timing Knots inserting that is inserted into the circulation moment stepper, according to described
Timer ID inquires corresponding event from the index chained list, and executes that the event is corresponding to recall to function;
The timing node that single thread poll detection time-out is carried out to the circulation moment stepper, the result having timed out is led to
The mode for crossing chained list is fed back, and determines that time-out executes the time as timing next time.
Further, described to be inserted into described in timing Knots inserting according to the absolute time and the determination of corresponding index value
The step of recycling the index position of moment stepper, including:
Time offset value when insertion is inserted into timing node is calculated according to the absolute time and corresponding index value;
The stepping of timing node is inserted into according to the time scale value of default stepping and time offset value determination
Sum;
It is determined according to the stepping sum, the index value, stepping maximum value and the quantity maximum value of each round stepping
The stepping index value for being inserted into timing node and step cycle wheel number;
The index position of timing node is inserted into according to the stepping index value and step cycle wheel number determination.
Further, the timing node that single thread poll detection time-out is carried out to the circulation moment stepper, will
The result having timed out is fed back by way of chained list, and determines the step of time-out execution time is timing next time, packet
It includes:
Calculate the detection time of timing node to be polled and the time difference of the absolute time;
The step of the timing node to be polled is calculated according to the time scale value of the time difference and each stepping
Into value;
When the step value of the timing node to be polled is greater than zero, the current index of the timing node to be polled is obtained
Value;
Judge in the scale numerical value passed through with the presence or absence of the timing node of time-out;
If so, marking corresponding timing node as time-out, and export;
If it is not, being then updated to the index value and step value of the timing node to be polled.
Further, further include:
The index value of the timing node to be deleted is obtained according to stepper mark at the time of the timing node of incoming parameter;
The chained list head that the timing node to be deleted is determined according to the index value, will be described from the index chained list
Timing node deletion to be deleted.
A kind of realization device of timer, including:
First processing units, for being inserted into timing Knots inserting according to the absolute time and the determination of corresponding index value
The index position of the circulation moment stepper;
The second processing unit, for according to the index position by it is described be inserted into timing Knots inserting to the circulation when
Stepper is carved, corresponding event is inquired from the index chained list according to the timer ID, and it is corresponding to execute the event
Recall to function;
Third processing unit, for carrying out the timing knot of single thread poll detection time-out to the circulation moment stepper
Point feeds back the result having timed out by way of chained list, and determines that time-out executes the time as timing next time.
Further, first processing units are used for:
Time offset value when insertion is inserted into timing node is calculated according to the absolute time and corresponding index value;
The stepping of timing node is inserted into according to the time scale value of default stepping and time offset value determination
Sum;
It is determined according to the stepping sum, the index value, stepping maximum value and the quantity maximum value of each round stepping
The stepping index value for being inserted into timing node and step cycle wheel number;
The index position of timing node is inserted into according to the stepping index value and step cycle wheel number determination.
Further, the third processing unit is used for:
Calculate the detection time of timing node to be polled and the time difference of the absolute time;
The step of the timing node to be polled is calculated according to the time scale value of the time difference and each stepping
Into value;
When the step value of the timing node to be polled is greater than zero, the current index of the timing node to be polled is obtained
Value;
Judge in the scale numerical value passed through with the presence or absence of the timing node of time-out;
If so, marking corresponding timing node as time-out, and export;
If it is not, being then updated to the index value and step value of the timing node to be polled.
Further, further include:Fourth processing unit is used for:
The index value of the timing node to be deleted is obtained according to stepper mark at the time of the timing node of incoming parameter;
The chained list head that the timing node to be deleted is determined according to the index value, will be described from the index chained list
Timing node deletion to be deleted.
A kind of storage medium, the storage medium include the program of storage,
Wherein, the equipment where the storage medium is controlled when described program is run executes as described in any one of the above embodiments
The implementation method of timer.
A kind of processor, the processor are used to run program,
Wherein, the implementation method of timer described in any of the above embodiments is executed when described program is run.
By above-mentioned technical proposal, a kind of implementation method and device of timer provided by the invention are opened in advance with system
Dynamic absolute time definition circulation moment stepper, loop initialization moment stepper distribute corresponding for each timing node
Index position, for storing timing node, timing node includes timer ID and timing length, and in circulation moment stepper
Index chained list in register the event of timing node and event is corresponding recalls to function, this method includes:According to absolute time
The index position for being inserted into timing Knots inserting circulation moment stepper is determined with corresponding index value;It will be to according to index position
Timing Knots inserting is inserted into circulation moment stepper, corresponding event is inquired from index chained list according to timer ID, and
Execution event is corresponding to recall to function;The timing node that single thread poll detection time-out is carried out to circulation moment stepper, will
The result of time-out is fed back by way of chained list, and determines that time-out executes the time as timing next time.
The present invention realizes the insertion and deletion of timing node by circulation moment stepper, passes through user thread active poll
Mode the time scale being lost is judged using current system time, simplify the node book for needing to compare, improve time-out and sentence
Fixed efficiency, meanwhile, the timing of time confirmation next time is executed according to time-out, to not executed the shadow of time by time-out
Picture guarantees that being fixed time-out time every time is called and does not generate overtime cumulative effect.
The above description is only an overview of the technical scheme of the present invention, in order to better understand the technical means of the present invention,
And it can be implemented in accordance with the contents of the specification, and in order to allow above and other objects of the present invention, feature and advantage can
It is clearer and more comprehensible, the followings are specific embodiments of the present invention.
Detailed description of the invention
By reading the following detailed description of the preferred embodiment, various other advantages and benefits are common for this field
Technical staff will become clear.The drawings are only for the purpose of illustrating a preferred embodiment, and is not considered as to the present invention
Limitation.And throughout the drawings, the same reference numbers will be used to refer to the same parts.In the accompanying drawings:
Fig. 1 shows a kind of implementation method flow chart of timer provided in an embodiment of the present invention;
Fig. 2 shows a kind of flow charts of specific implementation of S101 provided in an embodiment of the present invention;
Fig. 3 shows a kind of flow chart of specific implementation of S103 provided in an embodiment of the present invention;
Fig. 4 shows a kind of realization device structure chart of timer provided in an embodiment of the present invention.
Specific embodiment
Exemplary embodiments of the present disclosure are described in more detail below with reference to accompanying drawings.Although showing the disclosure in attached drawing
Exemplary embodiment, it being understood, however, that may be realized in various forms the disclosure without should be by embodiments set forth here
It is limited.On the contrary, these embodiments are provided to facilitate a more thoroughly understanding of the present invention, and can be by the scope of the present disclosure
It is fully disclosed to those skilled in the art.
Referring to Fig. 1, specifically including following steps present embodiment discloses a kind of implementation method of timer:
S101, determine that being inserted into timing Knots inserting recycles moment stepper according to absolute time and corresponding index value
Index position.
In the embodiment of the present invention, in advance with the absolute time definition circulation moment stepper of system starting, loop initialization
Moment stepper distributes corresponding index position for each timing node, and for storing timing node, timing node includes timing
Device mark and timing length, and the event and event of registration timing node are corresponding in the index chained list of circulation moment stepper
Recall to function.
Firstly, obtain system starting absolute time, i.e., since system starting at the moment timing, not by system time
The influence being changed by the user, waiting time-out time is also an absolute time.
Then, the absolute time that system is passed through is made into the stepper at a cycle labeling moment, is later referred to as recycled
Moment stepper, each stepping time are 128ms, represent a time precision for supporting timing.It as shown in Table 1, is stepper
Bound maximum value and minimum value correspond to table,
Table one
Stepper bound | Stepping time |
Maximum value N-1 | 128ms |
N-2 | 128ms |
N-3 | 128ms |
Minimum value 0 | 128ms |
The quantity of stepping is defined as 512 grades, then showing that the duration when total from smallest limit to maximum upper limit is:
Stepping scale time * step number=128ms*512=65536ms ≈ 1minute
I.e.:The maximum timing duration of each round is then to recycle within 1 minute or so, and return to smallest limit from maximum upper limit and continue
Start circulation of retiming, stepper at the time of forming a circulation.Increase the number counter of a circulation herein
A timer to clock infinitely is formed, it, then can timing using signless 32 integer per more wheels plus 1
More than 8000 years, meet actual demand enough.Specifically, the time scale value of each stepping is defined as STEP_TIMER, value definition
It can be 128;The quantity maximum value of each round stepping is defined as MAX_TIMER, and value definition can be 1024.
The node for realizing clocked flip for needing to be added to timer is called timing node in the embodiment of the present invention,
The included timing mark of timing node and timing length, timing identifier be in order to distinguish different nodes unique value, and
Timing length is an absolute time value.
Moment stepper, one unique ID value of scale attribute of each stepping are recycled defined in the embodiment of the present invention
Mark, is denoted as T_id, in order to avoid this value is 0, therefore directly adds 1 to be assigned to it the index value of stepper, later use this
Value can quickly navigate to the graduation position of stepping, be a fixed value.One timing length of label is needed by how many wheels
A number be denoted as T_remains.
Table two
Circulation moment stepper has global administration's device, is first a double linked list initial under each stepper index
Head node node double-strand more than one is then formed when the time node of identical stepping scale is multiple for storing timing node
Table, and record the sum of all timing nodes.
That minimum grade, that is, index value is named timing bottom for 0 when initializing for the first time, and time scale is to be denoted as the first time
System time when calling is denoted as T_btm (bottom time), its index value is denoted as T_bidx (bottom index).When being
After system operation when poll, it is an opposite bottom that the two values can all change therewith, can be calculated with the calling of poll
The time change of loss.
Each poll can all update T_btm time and T_bidx index value when calling, according to the current system system of poll
The time difference of system and T_btm gradually steps to upper limit maximum value, is then returned to lower limit minimum value, forms a circulation moment step
Into device.
In the embodiment of the present invention, for a timing node join to circulation moment stepper, it is first right to need from the description above
Its timing is calculated, which stepper index position confirmation falls on, and the wheel number for being needed to recycle is recorded,
Timing node is all recorded on the index chained list of circulation moment stepper.
As shown in Fig. 2, a kind of specific implementation of S101 provided in an embodiment of the present invention, specifically, according to absolute time
Between and corresponding index value determine be inserted into timing Knots inserting circulation moment stepper index position the step of, including:
S201, time offset value when insertion is inserted into timing node is calculated according to absolute time and corresponding index value.
It should be noted that being inserted into the time offset value T_duration=Tsys_tm-T_btm+T_ of timing node
Out, wherein Tsys_tm indicates system time value when being currently inserted into node, must be from bottom the when being inserted into node for the first time
One index value starts, then T_btm is equal to Tsys_tm value, and T_bidx is equal to 0, shows that insertion time node is certain for the first time
It is to be subject to stepper index value 0;When n-th is inserted into, each poll of T_btm is updated after calling, value range be [0~
MAX_TIMER], so current system time and T_btm difference is greater than 0.
S202, determine that the stepping for being inserted into timing node is total according to the time scale value and time offset value of presetting stepping
Number.
It should be noted that being inserted into the stepping sum T_off=(T_duration+ (STEP_TIMER-of timing node
1))/STEP_TIMER, i.e.,:"/" expression takes quotient.
S203, determined according to stepping sum, index value, stepping maximum value and the quantity maximum value of each round stepping it is to be inserted
Enter the stepping index value and step cycle wheel number of timing node.
It should be noted that being inserted into stepping index value T_index=(T_off+T_bidx) %MAX_ of timing node
TMR, i.e.,:" % " indicates remainder.It is inserted into the step cycle wheel number T_remains=T_off/MAX_TIMER of timing node.
S204, the index position for being inserted into timing node is determined according to stepping index value and step cycle wheel number.
S102, timing Knots inserting will be inserted into according to index position to circulation moment stepper, according to timer ID
Corresponding event is inquired from index chained list, and executes that event is corresponding to recall to function.
In the embodiment of the present invention, since moment stepper is the type of data structure of an array, so directly according to number
The index value T_index of group can be obtained the chained list head of storage time node, by time node join to chained list head
It completes, while T_remains and T_id value being stored on timing node to, being facilitated the deletion of following time node.
By above analysis, insertion for timing node is only merely that simple complementation several times, modulus and insertion are double
The simple computation on the head of chained list, its complexity are unrelated with timed node number existing in moment stepper, time complexity
For the algorithm of (1) O.
S103, the timing node that single thread poll detection time-out is carried out to circulation moment stepper, the result that will be had timed out
It is fed back by way of chained list, and determines that time-out executes the time as timing next time.
Poll detection is called by user thread, and the same moment stepper example only allows a single thread to call, mainly
It is that can be created more in order to avoid the lock of multithreading influences efficiency and safety if needing to create timer in different threads
A moment stepper example.And when poll calls every time, it is passed to current system time, the result that will be had timed out after the completion of detection
It is returned by way of chained list, while returning to the time T_left (millisecond) for checking next time and needing to wait, -1 indicates may not be used
The overtime node of waiting.
As shown in figure 3, a kind of specific implementation of S103 provided in an embodiment of the present invention, specifically, to the circulation moment
Stepper carries out the timing node of single thread poll detection time-out, and the result having timed out is fed back by way of chained list, and really
The step of fixed time-out execution time is timing next time, including:
The time difference of S301, the detection time for calculating timing node to be polled and absolute time.
It should be noted that the detection time of timing node to be polled and the time difference T_on=Tsys_ of absolute time
tm-T_btm。
S302, the step value that timing node to be polled is calculated according to the time scale value of time difference and each stepping.
It should be noted that the step value T_n=T_on/STEP_TIMER of timing node to be polled;T_left=STEP_
TIMER-T_off%STEP_TIMER.
S303, judge whether the step value of timing node to be polled is greater than zero, if so, S304 is thened follow the steps, if it is not, then
Exit poll.
S304, the current index value for obtaining timing node to be polled.
With the presence or absence of the timing node of time-out in the scale numerical value that S305, judgement are passed through, if so, thening follow the steps S306;
If it is not, thening follow the steps S307.
It should be noted that determining the node for whether having time-out in the scale numerical value passed through, has, be added to overtime chained list
In.Specific poll scanning process is described in detail:
If the time of poll detection passes through a scale, when being exactly equal to 128ms, positions and obtain from bottom T_bidx value
The header addresses of chained list are scanned for the node in chained list, and take-off time node checks whether T_remains is greater than 0,
It is that T_remains value is subtracted 1, otherwise then indicates that time-out time is added in overtime chained list to from deletion in chained list.
If the time of poll detection passes through multiple scales, then execution above procedure is recycled, the number specifically recycled is by passing through
The number of division crossed and the stepping index value chosen are whether chained list has timed node related.
S306, the corresponding timing node of mark are time-out, and export;
S307, the index value and step value of timing node to be polled are updated.
It should be noted that there are several values to need assignment again after poll is disposed, show that stepper is one opposite
Bottom design method is also that relatively following parameter calculates new value when calculating timed node insertion every time:
T_btm=T_btm+T_n*STEP_TIMER
T_bidx=(T_bidx+T_n) %MAX_TMR
It the time that thread loops can also be called according to T_left delay time as poll next time, can reduce in this way
The idle period of user thread needs to recalculate delay time when there is new timed node insertion, and this method is using minimum
Precision Time 128ms calls interval as timing.If the timed node under T_n stepping scale has m, then the time scanned is multiple
Miscellaneous degree is O (m).
In embodiments of the present invention, the time Knots inserting of default is primary, then can then be called one when timing node time-out
It is secondary, make repetition timer if necessary, then it is then again that time Knots inserting is primary after being finished.Here one is had
Advantage, i.e., every time after executed timing time-out time.Traditional repetition timer is adjusted at regular intervals
With, first is that certain to execute allocating time too long, then cross and (T- executes the time) called every very short time occur, two come when implemented
Between the too long multiple more than T time when, it is possible that call number accumulation is performed simultaneously repeatedly, therefore, traditional timing
Device was triggered by the set time, will not be executed the time according to readjustment and is adjusted execution interval.Compared to traditional repetition timing
Device, the timer provided in an embodiment of the present invention that repeats is to rejoin timing node according to the time point after having executed every time, is protected
Card waits the identical time called every time, can voluntarily call according to executing the time point reclocking completed, can not be by
Time-out executes the influence of time, guarantees that being fixed time-out time every time is called and does not generate overtime cumulative effect.
Specifically, the implementation method of the timer can also include:Deletion to timing node.
The index value of timing node to be deleted is obtained according to stepper mark at the time of the timing node of incoming parameter;
Timing node to be deleted is deleted from index chained list in the chained list head that timing node to be deleted is determined according to index value
It removes.
It should be noted that directly obtaining stepping according to stepper mark T_id value at the time of the timing node of incoming parameter
The array indexing value of device, easily takes location to obtain the head of chained list, can delete timing nodal value further according to incoming parameter, directly from
Deletion of node element in double linked list.Positioning and node deletion all with have in moment stepper press when number of network nodes without
It closes, time complexity is the algorithm of O (1).
A kind of implementation method of timer provided in an embodiment of the present invention is followed in advance with the absolute time definition of system starting
Ring moment stepper, loop initialization moment stepper distribute corresponding index position for each timing node, fixed for storing
When node, timing node includes timer ID and timing length, and registration is fixed in the index chained list of circulation moment stepper
When node event and event is corresponding recalls to function, this method includes:It is determined according to absolute time and corresponding index value
It is inserted into the index position of timing Knots inserting circulation moment stepper;Timing Knots inserting will be inserted into according to index position to arrive
Moment stepper is recycled, corresponding event is inquired from index chained list according to timer ID, and execute that event is corresponding to recall to
Function;The timing node that single thread poll detection time-out is carried out to circulation moment stepper, passes through chained list for the result having timed out
Mode feed back, and determining that time-out executes the time is timing next time.The present invention is realized by circulation moment stepper
The insertion and deletion of timing node have been lost by way of user thread active poll using current system time judgement
Time scale simplifies the node book for needing to compare, and improves the efficiency that time-out determines, meanwhile, it is executed under time confirmation according to time-out
Primary timing, to not executed the image of time by time-out, guarantee to be fixed every time time-out time it is called and
Overtime cumulative effect is not generated.
Referring to Fig. 4, a kind of disclosed implementation method of timer, the present embodiment correspondence disclose based on the above embodiment
A kind of realization device of timer, specifically includes:First processing units 401, the second processing unit 402 and third processing unit
403, wherein:
First processing units 401, for being inserted into timing Knots inserting according to absolute time and the determination of corresponding index value
Recycle the index position of moment stepper;
The second processing unit 402, for according to index position will be inserted into timing Knots inserting to circulation moment stepper,
Corresponding event is inquired from index chained list according to timer ID, and executes that event is corresponding to recall to function;
Third processing unit 403, for carrying out the timing node of single thread poll detection time-out to circulation moment stepper,
The result having timed out is fed back by way of chained list, and determines that time-out executes the time as timing next time.
Further, first processing units 401 are used for:
Time offset value when insertion is inserted into timing node is calculated according to absolute time and corresponding index value;
The stepping sum for being inserted into timing node is determined according to the time scale value and time offset value of default stepping;
It is determined to be inserted into according to stepping sum, index value, stepping maximum value and the quantity maximum value of each round stepping and be determined
When node stepping index value and step cycle wheel number;
The index position for being inserted into timing node is determined according to stepping index value and step cycle wheel number.
Further, third processing unit 403 is used for:
Calculate the detection time of timing node to be polled and the time difference of absolute time;
The step value of timing node to be polled is calculated according to the time scale value of time difference and each stepping;
When the step value of timing node to be polled is greater than zero, the current index value of timing node to be polled is obtained;
Judge in the scale numerical value passed through with the presence or absence of the timing node of time-out;
If so, marking corresponding timing node as time-out, and export;
If it is not, being then updated to the index value and step value of timing node to be polled.
Further, further include:Fourth processing unit, the fourth processing unit are used for:
The index value of timing node to be deleted is obtained according to stepper mark at the time of the timing node of incoming parameter;
Timing node to be deleted is deleted from index chained list in the chained list head that timing node to be deleted is determined according to index value
It removes.
Data monitoring device based on browser includes processor and memory, above-mentioned first processing units, second processing
Unit, third processing unit and fourth processing unit etc. store in memory as program unit, are deposited by processor execution
Above procedure unit in memory is stored up to realize corresponding function.
Include kernel in processor, is gone in memory to transfer corresponding program unit by kernel.Kernel can be set one
Or more, come by adjusting kernel parameter to realize that the time for reducing timer timing Knots inserting in use is complicated
Degree.
Memory may include the non-volatile memory in computer-readable medium, random access memory (RAM) and/
Or the forms such as Nonvolatile memory, if read-only memory (ROM) or flash memory (flash RAM), memory include that at least one is deposited
Store up chip.
The embodiment of the invention provides a kind of storage mediums, are stored thereon with program, which is executed by processor described
The implementation method of timer.
The embodiment of the invention provides a kind of processor, processor is for running program, wherein the program executes when running
The implementation method of the timer.
The embodiment of the invention provides a kind of equipment, equipment include processor, memory and storage on a memory and can
The program run on a processor, processor realize following steps when executing program:
The index for being inserted into timing Knots inserting circulation moment stepper is determined according to absolute time and corresponding index value
Position;
Timing Knots inserting will be inserted into circulation moment stepper, according to timer ID from index according to index position
Corresponding event is inquired in chained list, and executes that event is corresponding to recall to function;
The timing node that single thread poll detection time-out is carried out to circulation moment stepper, passes through chain for the result having timed out
The mode of table is fed back, and determines that time-out executes the time as timing next time.
Further, it is determined according to absolute time and corresponding index value and is inserted into the circulation moment stepping of timing Knots inserting
The step of index position of device, including:
Time offset value when insertion is inserted into timing node is calculated according to absolute time and corresponding index value;
The stepping sum for being inserted into timing node is determined according to the time scale value and time offset value of default stepping;
It is determined to be inserted into according to stepping sum, index value, stepping maximum value and the quantity maximum value of each round stepping and be determined
When node stepping index value and step cycle wheel number;
The index position for being inserted into timing node is determined according to stepping index value and step cycle wheel number.
Further, the timing node that single thread poll detection time-out is carried out to circulation moment stepper, by what is had timed out
As a result it is fed back by way of chained list, and determines the step of time-out execution time is timing next time, including:
Calculate the detection time of timing node to be polled and the time difference of absolute time;
The step value of timing node to be polled is calculated according to the time scale value of time difference and each stepping;
When the step value of timing node to be polled is greater than zero, the current index value of timing node to be polled is obtained;
Judge in the scale numerical value passed through with the presence or absence of the timing node of time-out;
If so, marking corresponding timing node as time-out, and export;
If it is not, being then updated to the index value and step value of timing node to be polled.
Further, further include:
The index value of timing node to be deleted is obtained according to stepper mark at the time of the timing node of incoming parameter;
Timing node to be deleted is deleted from index chained list in the chained list head that timing node to be deleted is determined according to index value
It removes.
Equipment herein can be server, PC, PAD, mobile phone etc..
Present invention also provides a kind of computer program products, when executing on data processing equipment, are adapted for carrying out just
The program of beginningization there are as below methods step:
The index for being inserted into timing Knots inserting circulation moment stepper is determined according to absolute time and corresponding index value
Position;
Timing Knots inserting will be inserted into circulation moment stepper, according to timer ID from index according to index position
Corresponding event is inquired in chained list, and executes that event is corresponding to recall to function;
The timing node that single thread poll detection time-out is carried out to circulation moment stepper, passes through chain for the result having timed out
The mode of table is fed back, and determines that time-out executes the time as timing next time.
Further, it is determined according to absolute time and corresponding index value and is inserted into the circulation moment stepping of timing Knots inserting
The step of index position of device, including:
Time offset value when insertion is inserted into timing node is calculated according to absolute time and corresponding index value;
The stepping sum for being inserted into timing node is determined according to the time scale value and time offset value of default stepping;
It is determined to be inserted into according to stepping sum, index value, stepping maximum value and the quantity maximum value of each round stepping and be determined
When node stepping index value and step cycle wheel number;
The index position for being inserted into timing node is determined according to stepping index value and step cycle wheel number.
Further, the timing node that single thread poll detection time-out is carried out to circulation moment stepper, by what is had timed out
As a result it is fed back by way of chained list, and determines the step of time-out execution time is timing next time, including:
Calculate the detection time of timing node to be polled and the time difference of absolute time;
The step value of timing node to be polled is calculated according to the time scale value of time difference and each stepping;
When the step value of timing node to be polled is greater than zero, the current index value of timing node to be polled is obtained;
Judge in the scale numerical value passed through with the presence or absence of the timing node of time-out;
If so, marking corresponding timing node as time-out, and export;
If it is not, being then updated to the index value and step value of timing node to be polled.
Further, further include:
The index value of timing node to be deleted is obtained according to stepper mark at the time of the timing node of incoming parameter;
Timing node to be deleted is deleted from index chained list in the chained list head that timing node to be deleted is determined according to index value
It removes.
It should be understood by those skilled in the art that, embodiments herein can provide as method, system or computer program
Product.Therefore, complete hardware embodiment, complete software embodiment or reality combining software and hardware aspects can be used in the application
Apply the form of example.Moreover, it wherein includes the computer of computer usable program code that the application, which can be used in one or more,
The computer program implemented in usable storage medium (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.) produces
The form of product.
The application is referring to method, the process of equipment (system) and computer program product according to the embodiment of the present application
Figure and/or block diagram describe.It should be understood that every one stream in flowchart and/or the block diagram can be realized by computer program instructions
The combination of process and/or box in journey and/or box and flowchart and/or the block diagram.It can provide these computer programs
Instruct the processor of general purpose computer, special purpose computer, Embedded Processor or other programmable data processing devices to produce
A raw machine, so that being generated by the instruction that computer or the processor of other programmable data processing devices execute for real
The device for the function of being specified in present one or more flows of the flowchart and/or one or more blocks of the block diagram.
These computer program instructions, which may also be stored in, is able to guide computer or other programmable data processing devices with spy
Determine in the computer-readable memory that mode works, so that it includes referring to that instruction stored in the computer readable memory, which generates,
Enable the manufacture of device, the command device realize in one box of one or more flows of the flowchart and/or block diagram or
The function of being specified in multiple boxes.
These computer program instructions also can be loaded onto a computer or other programmable data processing device, so that counting
Series of operation steps are executed on calculation machine or other programmable devices to generate computer implemented processing, thus in computer or
The instruction executed on other programmable devices is provided for realizing in one or more flows of the flowchart and/or block diagram one
The step of function of being specified in a box or multiple boxes.
In a typical configuration, calculating equipment includes one or more processors (CPU), input/output interface, net
Network interface and memory.
Memory may include the non-volatile memory in computer-readable medium, random access memory (RAM) and/
Or the forms such as Nonvolatile memory, such as read-only memory (ROM) or flash memory (flash RAM).Memory is computer-readable Jie
The example of matter.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by any method
Or technology come realize information store.Information can be computer readable instructions, data structure, the module of program or other data.
The example of the storage medium of computer includes, but are not limited to phase change memory (PRAM), static random access memory (SRAM), moves
State random access memory (DRAM), other kinds of random access memory (RAM), read-only memory (ROM), electric erasable
Programmable read only memory (EEPROM), flash memory or other memory techniques, read-only disc read only memory (CD-ROM) (CD-ROM),
Digital versatile disc (DVD) or other optical storage, magnetic cassettes, tape magnetic disk storage or other magnetic storage devices
Or any other non-transmission medium, can be used for storage can be accessed by a computing device information.As defined in this article, it calculates
Machine readable medium does not include temporary computer readable media (transitory media), such as the data-signal and carrier wave of modulation.
It should also be noted that, the terms "include", "comprise" or its any other variant are intended to nonexcludability
It include so that the process, method, commodity or the equipment that include a series of elements not only include those elements, but also to wrap
Include other elements that are not explicitly listed, or further include for this process, method, commodity or equipment intrinsic want
Element.In the absence of more restrictions, the element limited by sentence "including a ...", it is not excluded that including element
There is also other identical elements in process, method, commodity or equipment.
It will be understood by those skilled in the art that embodiments herein can provide as method, system or computer program product.
Therefore, complete hardware embodiment, complete software embodiment or embodiment combining software and hardware aspects can be used in the application
Form.It is deposited moreover, the application can be used to can be used in the computer that one or more wherein includes computer usable program code
The shape for the computer program product implemented on storage media (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.)
Formula.
The above is only embodiments herein, are not intended to limit this application.To those skilled in the art,
Various changes and changes are possible in this application.It is all within the spirit and principles of the present application made by any modification, equivalent replacement,
Improve etc., it should be included within the scope of the claims of this application.
Claims (10)
1. a kind of implementation method of timer, which is characterized in that in advance with the absolute time definition circulation moment step of system starting
Into device, the circulation moment stepper is initialized, distributes corresponding index position for each timing node, it is described fixed for storing
When node, the timing node includes timer ID and timing length, and in the index chained list of the circulation moment stepper
The event of the middle registration timing node and event is corresponding recalls to function, this method includes:
It is determined according to the absolute time and corresponding index value and is inserted into circulation moment stepper described in timing Knots inserting
Index position;
According to the index position by the timing Knots inserting that is inserted into the circulation moment stepper, according to the timing
Device mark inquires corresponding event from the index chained list, and executes that the event is corresponding to recall to function;
The timing node that single thread poll detection time-out is carried out to the circulation moment stepper, passes through chain for the result having timed out
The mode of table is fed back, and determines that time-out executes the time as timing next time.
2. the method according to claim 1, wherein described true according to the absolute time and corresponding index value
Surely the step of being inserted into the index position that moment stepper is recycled described in timing Knots inserting, including:
Time offset value when insertion is inserted into timing node is calculated according to the absolute time and corresponding index value;
The stepping sum of timing node is inserted into according to the time scale value of default stepping and time offset value determination;
Described according to the stepping, total, the described index value, stepping maximum value and the quantity maximum value of each round stepping are determined
It is inserted into the stepping index value and step cycle wheel number of timing node;
The index position of timing node is inserted into according to the stepping index value and step cycle wheel number determination.
3. the method according to claim 1, wherein described carry out single thread wheel to the circulation moment stepper
Under the timing node of inquiry detection time-out, the result having timed out is fed back by way of chained list, and the determining time-out execution time is
The step of primary timing, including:
Calculate the detection time of timing node to be polled and the time difference of the absolute time;
The step value of the timing node to be polled is calculated according to the time scale value of the time difference and each stepping;
When the step value of the timing node to be polled is greater than zero, the current index value of the timing node to be polled is obtained;
Judge in the scale numerical value passed through with the presence or absence of the timing node of time-out;
If so, marking corresponding timing node as time-out, and export;
If it is not, being then updated to the index value and step value of the timing node to be polled.
4. the method according to claim 1, wherein further including:
The index value of the timing node to be deleted is obtained according to stepper mark at the time of the timing node of incoming parameter;
The chained list head that the timing node to be deleted is determined according to the index value, by described wait delete from the index chained list
Except timing node deletion.
5. a kind of realization device of timer, which is characterized in that including:
First processing units, for being inserted into described in timing Knots inserting according to the absolute time and the determination of corresponding index value
Recycle the index position of moment stepper;
The second processing unit, for being inserted into timing Knots inserting by described according to the index position and walking to the circulation moment
Into device, corresponding event is inquired from the index chained list according to the timer ID, and execute the corresponding tune of the event
Letter in reply number;
Third processing unit will for carrying out the timing node of single thread poll detection time-out to the circulation moment stepper
The result having timed out is fed back by way of chained list, and determines that time-out executes the time as timing next time.
6. device according to claim 5, which is characterized in that first processing units are used for:
Time offset value when insertion is inserted into timing node is calculated according to the absolute time and corresponding index value;
The stepping sum of timing node is inserted into according to the time scale value of default stepping and time offset value determination;
Described according to the stepping, total, the described index value, stepping maximum value and the quantity maximum value of each round stepping are determined
It is inserted into the stepping index value and step cycle wheel number of timing node;
The index position of timing node is inserted into according to the stepping index value and step cycle wheel number determination.
7. device according to claim 5, which is characterized in that the third processing unit is used for:
Calculate the detection time of timing node to be polled and the time difference of the absolute time;
The step value of the timing node to be polled is calculated according to the time scale value of the time difference and each stepping;
When the step value of the timing node to be polled is greater than zero, the current index value of the timing node to be polled is obtained;
Judge in the scale numerical value passed through with the presence or absence of the timing node of time-out;
If so, marking corresponding timing node as time-out, and export;
If it is not, being then updated to the index value and step value of the timing node to be polled.
8. device according to claim 5, which is characterized in that further include:Fourth processing unit is used for:
The index value of the timing node to be deleted is obtained according to stepper mark at the time of the timing node of incoming parameter;
The chained list head that the timing node to be deleted is determined according to the index value, by described wait delete from the index chained list
Except timing node deletion.
9. a kind of storage medium, which is characterized in that the storage medium includes the program of storage,
Wherein, the equipment where the storage medium is controlled when described program is run is executed such as any one of claim 1-4
The implementation method of the timer.
10. a kind of processor, which is characterized in that the processor is used to run program,
Wherein, the implementation method such as timer of any of claims 1-4 is executed when described program is run.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810558752.8A CN108874375B (en) | 2018-06-01 | 2018-06-01 | Timer implementation method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810558752.8A CN108874375B (en) | 2018-06-01 | 2018-06-01 | Timer implementation method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN108874375A true CN108874375A (en) | 2018-11-23 |
CN108874375B CN108874375B (en) | 2022-01-04 |
Family
ID=64335169
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810558752.8A Active CN108874375B (en) | 2018-06-01 | 2018-06-01 | Timer implementation method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108874375B (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111932656A (en) * | 2020-07-29 | 2020-11-13 | 交控科技股份有限公司 | Method, device and equipment for indexing information of operation diagram |
CN111934658A (en) * | 2020-06-30 | 2020-11-13 | 深圳点猫科技有限公司 | Delay cycle control method and device |
CN117056059A (en) * | 2023-10-12 | 2023-11-14 | 常州楠菲微电子有限公司 | Timer realizing method and device, storage medium and electronic equipment |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
KR20020087189A (en) * | 2001-05-14 | 2002-11-22 | 엘지전자 주식회사 | Method to embody software timer |
CN104268015A (en) * | 2014-09-05 | 2015-01-07 | 烽火通信科技股份有限公司 | Implementation method of high-availability timer of embedded equipment and timer |
CN104834347A (en) * | 2015-04-29 | 2015-08-12 | 杭州东信捷峻科技有限公司 | Implementation method for dynamic time duration timer in favor of low power consumption and free of accumulated error |
US20180114185A1 (en) * | 2014-10-13 | 2018-04-26 | Avery Dennison Retail Information Services, Llc | Utility timers in a food freshness printer |
-
2018
- 2018-06-01 CN CN201810558752.8A patent/CN108874375B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
KR20020087189A (en) * | 2001-05-14 | 2002-11-22 | 엘지전자 주식회사 | Method to embody software timer |
CN104268015A (en) * | 2014-09-05 | 2015-01-07 | 烽火通信科技股份有限公司 | Implementation method of high-availability timer of embedded equipment and timer |
US20180114185A1 (en) * | 2014-10-13 | 2018-04-26 | Avery Dennison Retail Information Services, Llc | Utility timers in a food freshness printer |
CN104834347A (en) * | 2015-04-29 | 2015-08-12 | 杭州东信捷峻科技有限公司 | Implementation method for dynamic time duration timer in favor of low power consumption and free of accumulated error |
Non-Patent Citations (2)
Title |
---|
HENG ZHANG 等: "A High Efficiency Two-dimensional Index Queue Timer Management Algorithm for Network and Communication Systems", 《2011 THIRD INTERNATIONAL CONFERENCE ON COMPUTATIONAL INTELLIGENCE, COMMUNICATION SYSTEMS AND NETWORKS》 * |
黄骞 等: "Linux下相对定时器池的实现及TD-LTE基站应用", 《微型机与应用》 * |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111934658A (en) * | 2020-06-30 | 2020-11-13 | 深圳点猫科技有限公司 | Delay cycle control method and device |
CN111934658B (en) * | 2020-06-30 | 2024-07-26 | 深圳点猫科技有限公司 | Delay circulation control method and device |
CN111932656A (en) * | 2020-07-29 | 2020-11-13 | 交控科技股份有限公司 | Method, device and equipment for indexing information of operation diagram |
CN117056059A (en) * | 2023-10-12 | 2023-11-14 | 常州楠菲微电子有限公司 | Timer realizing method and device, storage medium and electronic equipment |
CN117056059B (en) * | 2023-10-12 | 2024-02-02 | 常州楠菲微电子有限公司 | Timer realizing method and device, storage medium and electronic equipment |
Also Published As
Publication number | Publication date |
---|---|
CN108874375B (en) | 2022-01-04 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108874375A (en) | A kind of implementation method and device of timer | |
CN109615495A (en) | A kind of account checking method of data, device, equipment and system | |
CN107493314A (en) | Service provider system and method based on multi-tenant | |
CN110096528A (en) | The method, apparatus and system of formation sequence in a kind of distributed system | |
CN109872157A (en) | The method and device of intelligent contract is executed in block chain | |
CN108683692A (en) | A kind of service request processing method and device | |
US20200201844A1 (en) | Cluster-based random walk processing | |
CN109033365A (en) | A kind of data processing method and relevant device | |
CN109739627A (en) | Dispatching method, electronic equipment and the medium of task | |
CN110175900A (en) | A kind of buffering benefit account method and device | |
CN108134812A (en) | Data processing method and device | |
CN110427295A (en) | A kind of monitoring method, equipment and the readable medium of cloud platform resource | |
CN106874079A (en) | A kind of method and device of tasks carrying | |
TWI687820B (en) | Random walk, cluster-based random walk method, device and equipment | |
CN109684381A (en) | Data hot statistics method and device | |
CN110134701A (en) | A kind of buffering benefit account method and device | |
CN109977317A (en) | Data query method and device | |
CN106354841A (en) | Testing method and device of recommendation algorithms | |
CN110019260A (en) | A kind of update method and relevant device of user data | |
CN109118361A (en) | Quota control method, apparatus and system | |
CN110046034A (en) | Task acquisition methods and device | |
CN108829790A (en) | A kind of data batch processing method, apparatus and system | |
CN110083602A (en) | A kind of method and device of data storage and data processing based on hive table | |
CN107688634A (en) | Method for writing data and device, electronic equipment | |
CN110020114A (en) | Processing method, device and the equipment of data query |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |