Follow the linux timer to implement your timer Manager Policy
Source: Internet
Author: User
Follow the linux timer to implement your own timer Manager Policy-Linux Enterprise Application-Linux server application information. The following is a detailed description. I used to see the timer implementation strategy in linux on the Internet. I felt very good. Although I didn't use any good RBTree = algorithms, I just used arrays and linked lists for implementation, however, there is no performance problem. Feeling "simple is beautiful! Recently I needed a timer, so I used it to implement my timer manager, and made further optimization and improvement. I also needed to consider the problem of thread-dependent thread.
Let's talk about our own implementation strategy!
I used two buffers. The primary buffer is a fixed-length array that stores all events that will be triggered within a fixed period of time. The secondary buffer is a linked list, it takes a long time to start the event, and then my main cycle is only trained first-level buffer, each time it processes all events at a fixed position, when it reaches the end of the array, it indicates that all the events have been processed. At this time, you need to find the events to be processed in the next array in the second-level buffer zone and insert them into the first-level buffer zone. The overall logic is very clear, but looking at the current Code, we still compare 2. The key is to process a lot of pointers.
If you have better suggestions and strategies, contact me.
E_mail: guanzhongdake # gmail.com
Blog: guan-zhong-dao-ke.blog.163.com
Guan Zhongdao Ke
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.