THTTPD's Timer

Source: Internet
Author: User

using the static function to implement file encapsulationA keyword register that increases the efficiency of variable access, which implies that the variable may be accessed frequently, and if possible, store the value in a register in memory-centrally managed, and each node does not immediately release memory after cancellation. Instead of calling cleanup when the hash function of the unified release timer is different or results for the rest of the life into keystatic unsigned int
Hash (timer* t)
{
/* We can hash on the trigger time, even though it can
* * The life of a timer via either the periodic bit or the Tmr_reset ()
* * call. This was because both of those guys call L_resort (), which
* * Recomputes the hash and moves the timer to the appropriate list.
*/
Return (
(unsigned int) t->time.tv_sec ^
(unsigned int) t->time.tv_usec)% Hash_size;
   } Timer's hash structure of the timer data structure is a chain-addressable hash table, the second and microsecond hash of the timer through the corresponding key, and then traverse the key under the doubly linked list to find, insert, delete. Timer insertion: The earlier the Timer node position, the newly inserted node can be appended to the front, middle, and possibly final. Timer deletion: If it is the first node of the HashKey, the first node of the hash table key points to the next node. Timer reordering: The specified timer can be sorted, delete the node after the calculation of the hash value and insert the initialization of the hash table timer: Hash table key first node reset, Free_timers, Alloc_count, Active_count, Free_ The creation of the Count reset timer: Creates a timer node, specifies the timer's callback function and the parameters of the callback function, and the time of the timer, and obtains a timeout for initializing the timer pointer timer: Pass in a time, if there is no timer to trigger, return a null pointer If a timer is triggered within the time, then a time pointer of 0 is returned, and if there is a timer, but there is no time to trigger, the time pointer of the remaining trigger time is searched for the first timeout, and the timeout node below the hash table key is sorted from morning to night. Therefore, the lookup timeout only needs to determine if the first node under the hash table key is timed out, and the smallest node is found from the first node of all timeouts. Timer operation: All the lists of the hash table are ordered, so traverse each list to find the timer that has timed out and invoke the timer callback function, and then find the non-triggered timer in the list to continue searching for the next list. If the timer that has been triggered is a periodic timer, then the timer is reordered after a certain amount of time is added, and if the timer that has been triggered is a non-periodic timer, the timer is canceled after triggering. Timer Reset: Resets the timer time to an already existing timer node and invokes the cancellation of the timer sort timer: Calls the hash node's Delete method, removes the timer and activates the number of timers-1. Timer Cleanup: Call cancellation method to cancel the timer node cleanup memory, each canceled timer will be removed from the hash table and saved in a free_timers queue, but not on the spot to clean up the memory, but in the call cleanup method Unified cleanup, can improve program efficiency. Timer destruction: Thoroughly clean up the timer queue, traverse the hash node and the linked list, cancel all the timers after the call cleanup method to delete the status of the requested memory Timer report: The status of the print timer hash, the effective, idle, total number of timers, if effective + idle! = Total number of timers, and an error message is printed.

THTTPD's Timer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.