httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neil McKee <neil.mc...@inmon.com>
Subject per-worker-thread counter question
Date Tue, 28 Jun 2011 02:57:23 GMT
Hi,

Here's an easy question for someone who knows their way around...

I want to maintain a new global counter,  but for performance reasons I am reluctant to use
a mutex or atomic_increment to update it.  I would rather maintain a separate counter for
every worker-thread,  and only accumulate the global counter when required.  (If the per-worker-thread
counter is 32-bit then I shouldn't even need a mutex when accumulating the total across all
the current threads).

Obviously I shouldn't just declare something as "__thread apr_int32_t mycounter;" and mince
it together as a linux-only hack.  I'd like to find the portable apr-library way to do it.
  So I think I need to find the following:

* - a hook that is called whenever a worker thread is started
* - a hook that is called whenever a worker thread is about to die
* - a hook to find_or_create a 32-bit integer that is private to the current worker-thread
* - a fn to iterate (safely) over all the current worker threads

It's the last one that seems particularly elusive.  I could't find an ap_ or apr_ library
call that seemed to do anything like that.

If this has all been done before,   please can you point me to the relevant module sources?
 I think it would save me a lot of time.   Alternatively,  if you think I should just relax
and use an atomic increment instead,  then let me know.

Thanks!

Neil


Mime
View raw message