[email protected] wrote: > Author: sf > Date: Fri May 9 20:14:01 2014 > New Revision: 1593614 > > URL: http://svn.apache.org/r1593614 > Log: > Option to detect concurrent accesses to pools > > Enabled by new configure option --enable-pool-concurrency-check. > > Compared to pool-owner-debugging, this only detects cases where there is > actual > contention between accesses. The advantage is that runtime costs should be > relatively low. > > The diagnostic messages could still use some improvement. > > > Modified: > apr/apr/trunk/CHANGES > apr/apr/trunk/configure.in > apr/apr/trunk/memory/unix/apr_pools.c >
> Modified: apr/apr/trunk/memory/unix/apr_pools.c > URL: > http://svn.apache.org/viewvc/apr/apr/trunk/memory/unix/apr_pools.c?rev=1593614&r1=1593613&r2=1593614&view=diff > ============================================================================== > --- apr/apr/trunk/memory/unix/apr_pools.c (original) > +++ apr/apr/trunk/memory/unix/apr_pools.c Fri May 9 20:14:01 2014 > @@ -673,6 +682,65 @@ APR_DECLARE(void) apr_pool_terminate(voi > #define node_free_space(node_) ((apr_size_t)(node_->endp - > node_->first_avail)) > > /* > + * Helpers to mark pool as in-use/free. Used for finding thread-unsafe > + * concurrent accesses from different threads. > + */ > +#if APR_POOL_CONCURRENCY_CHECK > +static void pool_concurrency_abort(apr_pool_t *pool, const char *func, > apr_uint32_t old) > +{ > + fprintf(stderr, "%s: previous state %d in_use_by/cur %lx/%lx pool > %p(%s)\n", > + func, old, > + (unsigned long)pool->in_use_by, > + (unsigned long)apr_os_thread_current(), > + pool, pool->tag); > + abort(); > +} > + > +static APR_INLINE void pool_concurrency_set_used(apr_pool_t *pool) > +{ > + apr_uint32_t old; > + > + old = apr_atomic_cas32(&pool->in_use, 1, 0); > + > + if (old == 2 && pool->in_use_by == apr_os_thread_current()) { How can old ever be 2? > + /* cleanups may use the pool */ > + return; > + } > + > + if (old != 0) > + pool_concurrency_abort(pool, __func__, old); Isn't __func__ C99? Regards RĂ¼diger
