[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: per-thread init for overlays?



Aaron Richton wrote:

I'm linking an external library with my overlay that needs per-process
initialization, which I handle in my overlay_init function. I clean that
initialization up in the on_bi.bi_destroy function. (Feel free to yell at
me if that's the wrong place, but it seems to work.)

My question is for thread-specific initialization. The external library
claims thread safety, but in addition to the process init() call, there is
a per-thread thread_init()/thread_end() call. They recommend,
unsurprisingly, placing this near a pthread_create()/pthread_destroy() or
moral equivalent. Is there any appropriate place to do this in the
overlay?


None that I'm aware of. But I suggest you look at ldap_pvt_thread_pool_{get,set}key().
You could write a function like


void *private_cookie;

/* cleanup cookie & thread */
static void
private_cookie_free( void *key, void *data );

void
private_init_thread( Operation *op )
{
       void *cookie;

ldap_pvt_thread_pool_getkey( op->o_threadctx, &private_cookie, &cookie, NULL );
if ( cookie == NULL ) {
/* init cookie & overlay */
ldap_pvt_thread_pool_setkey( op->o_threadctx, &private_cookie,
cookie, private_cookie_free );
}
}


Each function in your overlay could call private_thread_init() to make sure per-thread initialization occurred.

p.


SysNet - via Dossi,8 27100 Pavia Tel: +390382573859 Fax: +390382476497