From: Howard Chu Date: Thu, 6 Oct 2011 23:10:47 +0000 (-0700) Subject: Additional tweaks for double-threaded slapadd X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7592013f59ac99557a4cdd461d8e9b9c24122bb9;p=openldap Additional tweaks for double-threaded slapadd --- diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index b573349d4c..95e640eaa1 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -141,14 +141,16 @@ int bdb_tool_entry_open( if ( bdb->bi_nattrs ) { int i; bdb_tool_threads = slap_tool_thread_max - 1; - bdb_tool_index_threads = ch_malloc( bdb_tool_threads * sizeof( int )); - bdb_tool_index_rec = ch_malloc( bdb->bi_nattrs * sizeof( IndexRec )); - bdb_tool_index_tcount = bdb_tool_threads - 1; - for (i=1; i 1 ) { + bdb_tool_index_threads = ch_malloc( bdb_tool_threads * sizeof( int )); + bdb_tool_index_rec = ch_malloc( bdb->bi_nattrs * sizeof( IndexRec )); + bdb_tool_index_tcount = bdb_tool_threads - 1; + for (i=1; i 1 ) { + ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex ); - /* There might still be some threads starting */ - while ( bdb_tool_index_tcount ) { - ldap_pvt_thread_cond_wait( &bdb_tool_index_cond_main, - &bdb_tool_index_mutex ); - } + /* There might still be some threads starting */ + while ( bdb_tool_index_tcount > 0 ) { + ldap_pvt_thread_cond_wait( &bdb_tool_index_cond_main, + &bdb_tool_index_mutex ); + } - bdb_tool_index_tcount = bdb_tool_threads - 1; - ldap_pvt_thread_cond_broadcast( &bdb_tool_index_cond_work ); + bdb_tool_index_tcount = bdb_tool_threads - 1; + ldap_pvt_thread_cond_broadcast( &bdb_tool_index_cond_work ); - /* Make sure all threads are stopped */ - while ( bdb_tool_index_tcount ) { - ldap_pvt_thread_cond_wait( &bdb_tool_index_cond_main, - &bdb_tool_index_mutex ); - } - ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex ); + /* Make sure all threads are stopped */ + while ( bdb_tool_index_tcount > 0 ) { + ldap_pvt_thread_cond_wait( &bdb_tool_index_cond_main, + &bdb_tool_index_mutex ); + } + ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex ); - bdb_tool_info = NULL; - slapd_shutdown = 0; - ch_free( bdb_tool_index_threads ); - ch_free( bdb_tool_index_rec ); - bdb_tool_index_tcount = bdb_tool_threads - 1; + bdb_tool_info = NULL; + slapd_shutdown = 0; + ch_free( bdb_tool_index_threads ); + ch_free( bdb_tool_index_rec ); + bdb_tool_index_tcount = bdb_tool_threads - 1; + } } if( eh.bv.bv_val ) { @@ -601,7 +605,7 @@ bdb_tool_index_add( bdb_tool_ix_op = op; ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex ); /* Wait for all threads to be ready */ - while ( bdb_tool_index_tcount ) { + while ( bdb_tool_index_tcount > 0 ) { ldap_pvt_thread_cond_wait( &bdb_tool_index_cond_main, &bdb_tool_index_mutex ); } diff --git a/servers/slapd/slapadd.c b/servers/slapd/slapadd.c index 16c9c16d53..5261f409c7 100644 --- a/servers/slapd/slapadd.c +++ b/servers/slapd/slapadd.c @@ -64,9 +64,10 @@ static lutil_meter_t meter; static const char *progname = "slapadd"; static OperationBuffer opbuf; static char *buf; +static int lmax; static ldap_pvt_thread_mutex_t add_mutex; -static ldap_pvt_thread_cond_t add_cond_r, add_cond_w; +static ldap_pvt_thread_cond_t add_cond; static int add_stop; /* returns: @@ -79,7 +80,7 @@ static int getrec0(Erec *erec) { const char *text; - int ldifrc, lmax = 0; + int ldifrc; char textbuf[SLAP_TEXT_BUFLEN] = { '\0' }; size_t textlen = sizeof textbuf; struct berval csn; @@ -291,9 +292,8 @@ getrec_thr(void *ctx) while (!add_stop) { trec.rc = getrec0((Erec *)&trec); trec.ready = 1; - ldap_pvt_thread_cond_signal( &add_cond_w ); while (trec.ready) - ldap_pvt_thread_cond_wait( &add_cond_r, &add_mutex ); + ldap_pvt_thread_cond_wait( &add_cond, &add_mutex ); /* eof or read failure */ if ( trec.rc == 0 || trec.rc == -1 ) break; @@ -309,16 +309,16 @@ getrec(Erec *erec) if ( slap_tool_thread_max < 2 ) return getrec0(erec); - ldap_pvt_thread_mutex_lock( &add_mutex ); while (!trec.ready) - ldap_pvt_thread_cond_wait( &add_cond_w, &add_mutex ); + ldap_pvt_thread_yield(); erec->e = trec.e; erec->lineno = trec.lineno; erec->nextline = trec.nextline; trec.ready = 0; rc = trec.rc; + ldap_pvt_thread_mutex_lock( &add_mutex ); ldap_pvt_thread_mutex_unlock( &add_mutex ); - ldap_pvt_thread_cond_signal( &add_cond_r ); + ldap_pvt_thread_cond_signal( &add_cond ); return rc; } @@ -402,8 +402,7 @@ slapadd( int argc, char **argv ) if ( slap_tool_thread_max > 1 ) { ldap_pvt_thread_mutex_init( &add_mutex ); - ldap_pvt_thread_cond_init( &add_cond_r ); - ldap_pvt_thread_cond_init( &add_cond_w ); + ldap_pvt_thread_cond_init( &add_cond ); ldap_pvt_thread_create( &thr, 0, getrec_thr, NULL ); } @@ -451,7 +450,7 @@ slapadd( int argc, char **argv ) if ( slap_tool_thread_max > 1 ) { add_stop = 1; trec.ready = 0; - ldap_pvt_thread_cond_signal( &add_cond_r ); + ldap_pvt_thread_cond_signal( &add_cond ); ldap_pvt_thread_join( thr, NULL ); }