Ivan Zhakov <i...@visualsvn.com> writes:

> Another way add some kind of svn__shared_pool_t with atomic reference
> counter and destroying attached pool when counter reaches zero.
>
> Something like this:
> [[[
> svn__shared_pool_t * svn__shared_pool_attach(apr_pool_t *pool)
> {
>     svn__shared_pool_t sp = apr_pcalloc(pool);
>    sp->counter = 1;
>    sp->pool = pool;
> }
>
> void svn__shared_pool_addref(svn__shared_pool_t *sp)
> {
>    apr_atomic_increment(sp->counter);
> }
>
> void svn__shared_pool_release(svn__shared_pool_t *sp)
> {
>    if (apr_atomic_decrement(sp->counter) == 0)
>    {
>       svn_pool_destroy(sp->pool);
>    }
> }
>
> Then we do the following:
> connection_pool = svn_pool_create();
> sp = svn__shared_pool_attach(connection_pool);
> svn__shared_pool_addref(sp); // for worker thread
> data->sp = sp;
> apr_threadattr_create(connection_pool);
> apr_thread_create(connection_pool, worker, data);
>
> svn_shared_pool_release(sp);
>
> void worker()
> {
>    /// to the work
>    svn_shared_pool_release(sp);
> }

Yes, that looks promising.

-- 
Certified & Supported Apache Subversion Downloads:
http://www.wandisco.com/subversion/download

Reply via email to