best way to get a 1-second timer-tick?

Maxim Dounin mdounin at mdounin.ru
Mon Sep 9 11:34:14 UTC 2013


Hello!

On Fri, Sep 06, 2013 at 12:14:34PM -0700, Neil Mckee wrote:

> I finally got back to looking at this again.   Turns out I had 
> been calling ngx_add_timer() too soon -- before the event rbtree 
> was up and running.   I moved it to the callback that comes when 
> an nginx process starts,  and now it works.  I now get my "tick" 
> even if nothing else is happening.
> 
> https://code.google.com/p/nginx-sflow-module/source/browse/trunk/ngx_http_sflow_module.c#172
> 
> Just one question:  I had to declare my ngx_event_t as a static 
> var so I could access it here,  because I couldn't see how to 
> follow the ngx_cycle_t pointer back to the module's 
> heap-allocated data.   Is there a good way,  or should I just be 
> content to use a static var?

The ngx_http_cycle_get_module_main_conf() macro should do the 
trick.  On the other hand, static var should work too.

-- 
Maxim Dounin
http://nginx.org/en/donation.html



More information about the nginx-devel mailing list