From 290137a54f77ef53162a1c3b5ef92ba07cf90ca1 Mon Sep 17 00:00:00 2001 From: Mark Adamson Date: Thu, 11 Oct 2001 18:12:53 +0000 Subject: [PATCH] Serialize access to idl insert/delete key routines (ITS 1359) --- servers/slapd/back-ldbm/back-ldbm.h | 1 + servers/slapd/back-ldbm/dbcache.c | 3 +++ servers/slapd/back-ldbm/dn2id.c | 10 ++++++++-- servers/slapd/back-ldbm/key.c | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/servers/slapd/back-ldbm/back-ldbm.h b/servers/slapd/back-ldbm/back-ldbm.h index ca78ab336a..b166f8f35b 100644 --- a/servers/slapd/back-ldbm/back-ldbm.h +++ b/servers/slapd/back-ldbm/back-ldbm.h @@ -117,6 +117,7 @@ typedef struct ldbm_dbcache { long dbc_blksize; char *dbc_name; LDBM dbc_db; + ldap_pvt_thread_mutex_t dbc_write_mutex; } DBCache; #define MAXDBCACHE 128 diff --git a/servers/slapd/back-ldbm/dbcache.c b/servers/slapd/back-ldbm/dbcache.c index 3876bbb521..36e19e9771 100644 --- a/servers/slapd/back-ldbm/dbcache.c +++ b/servers/slapd/back-ldbm/dbcache.c @@ -207,6 +207,8 @@ ldbm_cache_open( Debug( LDAP_DEBUG_TRACE, "<= ldbm_cache_open (opened %d)\n", i, 0, 0 ); #endif + ldap_pvt_thread_mutex_init( &li->li_dbcache[i].dbc_write_mutex ); + ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex ); return( &li->li_dbcache[i] ); } @@ -241,6 +243,7 @@ ldbm_cache_really_close( Backend *be, DBCache *db ) ldbm_close( db->dbc_db ); free( db->dbc_name ); db->dbc_name = NULL; + ldap_pvt_thread_mutex_destroy( &db->dbc_write_mutex ); } ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex ); } diff --git a/servers/slapd/back-ldbm/dn2id.c b/servers/slapd/back-ldbm/dn2id.c index 57340fd9a6..55c016b85c 100644 --- a/servers/slapd/back-ldbm/dn2id.c +++ b/servers/slapd/back-ldbm/dn2id.c @@ -72,7 +72,9 @@ dn2id_add( key.dsize = strlen( pdn ) + 2; key.dptr = ch_malloc( key.dsize ); sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, pdn ); + ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex ); rc = idl_insert_key( be, db, key, id ); + ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); free( key.dptr ); free( pdn ); } @@ -89,9 +91,9 @@ dn2id_add( key.dptr = ch_malloc( key.dsize ); sprintf( key.dptr, "%c%s", DN_SUBTREE_PREFIX, subtree[i] ); - + ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex ); rc = idl_insert_key( be, db, key, id ); - + ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); free( key.dptr ); if(rc == -1) break; @@ -298,7 +300,9 @@ dn2id_delete( key.dptr = ch_malloc( key.dsize ); sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, pdn ); + ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex ); (void) idl_delete_key( be, db, key, id ); + ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); free( key.dptr ); free( pdn ); @@ -317,7 +321,9 @@ dn2id_delete( sprintf( key.dptr, "%c%s", DN_SUBTREE_PREFIX, subtree[i] ); + ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex ); (void) idl_delete_key( be, db, key, id ); + ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); free( key.dptr ); } diff --git a/servers/slapd/back-ldbm/key.c b/servers/slapd/back-ldbm/key.c index de8b90565e..69d80075f6 100644 --- a/servers/slapd/back-ldbm/key.c +++ b/servers/slapd/back-ldbm/key.c @@ -82,6 +82,7 @@ key_change( key.dptr = k->bv_val; key.dsize = k->bv_len; + ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex ); if (op == SLAP_INDEX_ADD_OP) { /* Add values */ rc = idl_insert_key( be, db, key, id ); @@ -90,6 +91,7 @@ key_change( /* Delete values */ rc = idl_delete_key( be, db, key, id ); } + ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); #ifdef NEW_LOGGING -- 2.39.5