From 622c4d388436a03bdfde2975121b1d4b30e09e82 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sat, 29 Dec 2007 18:14:54 +0000 Subject: [PATCH] new ldap_pvt_thread_pool_setkey API --- include/ldap_pvt_thread.h | 9 +++++++-- libraries/libldap_r/tpool.c | 22 ++++++++++++++++++++-- servers/slapd/overlays/memberof.c | 7 ++----- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/include/ldap_pvt_thread.h b/include/ldap_pvt_thread.h index 21b2dc69cd..e8a8b08dbf 100644 --- a/include/ldap_pvt_thread.h +++ b/include/ldap_pvt_thread.h @@ -268,11 +268,16 @@ ldap_pvt_thread_pool_getkey LDAP_P(( ldap_pvt_thread_pool_keyfree_t **kfree )); LDAP_F( int ) -ldap_pvt_thread_pool_setkey LDAP_P(( +ldap_pvt_thread_pool_setkey_x LDAP_P(( void *ctx, void *key, void *data, - ldap_pvt_thread_pool_keyfree_t *kfree )); + ldap_pvt_thread_pool_keyfree_t *kfree, + void **olddatap, + ldap_pvt_thread_pool_keyfree_t **oldkfreep )); + +#define ldap_pvt_thread_pool_setkey( ctx, key, data, kfree ) \ + ldap_pvt_thread_pool_setkey_x( (ctx), (key), (data), (kfree), NULL, NULL ) LDAP_F( void ) ldap_pvt_thread_pool_purgekey LDAP_P(( void *key )); diff --git a/libraries/libldap_r/tpool.c b/libraries/libldap_r/tpool.c index 81ebd92ed6..3b7abee8a7 100644 --- a/libraries/libldap_r/tpool.c +++ b/libraries/libldap_r/tpool.c @@ -756,11 +756,13 @@ clear_key_idx( ldap_int_thread_userctx_t *ctx, int i ) * responsibility to free any existing data with the same key. * kfree() must not call functions taking a tpool argument. */ -int ldap_pvt_thread_pool_setkey( +int ldap_pvt_thread_pool_setkey_x( void *xctx, void *key, void *data, - ldap_pvt_thread_pool_keyfree_t *kfree ) + ldap_pvt_thread_pool_keyfree_t *kfree, + void **olddatap, + ldap_pvt_thread_pool_keyfree_t **oldkfreep ) { ldap_int_thread_userctx_t *ctx = xctx; int i, found; @@ -776,6 +778,22 @@ int ldap_pvt_thread_pool_setkey( } } + if ( olddatap ) { + if ( found ) { + *olddatap = ctx->ltu_key[i].ltk_data; + } else { + *olddatap = NULL; + } + } + + if ( oldkfreep ) { + if ( found ) { + *oldkfreep = ctx->ltu_key[i].ltk_free; + } else { + *oldkfreep = NULL; + } + } + if ( data || kfree ) { if ( i>=MAXKEYS ) return ENOMEM; diff --git a/servers/slapd/overlays/memberof.c b/servers/slapd/overlays/memberof.c index 50d018d0dd..0dec9c86ed 100644 --- a/servers/slapd/overlays/memberof.c +++ b/servers/slapd/overlays/memberof.c @@ -234,14 +234,11 @@ memberof_saved_member_set( Operation *op, void *keyp, BerVarray vals ) } else { BerVarray old_vals = NULL; - ldap_pvt_thread_pool_getkey( op->o_threadctx, - key, (void **)&old_vals, NULL ); + ldap_pvt_thread_pool_setkey_x( op->o_threadctx, key, + saved_vals, memberof_saved_member_free, &old_vals, NULL ); if ( old_vals != NULL ) { ber_bvarray_free( old_vals ); } - - ldap_pvt_thread_pool_setkey( op->o_threadctx, key, - saved_vals, memberof_saved_member_free ); } } -- 2.39.5