Commit 7592013f authored by Howard Chu's avatar Howard Chu
Browse files

Additional tweaks for double-threaded slapadd

parent 50723871
......@@ -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<bdb_tool_threads; i++) {
int *ptr = ch_malloc( sizeof( int ));
*ptr = i;
ldap_pvt_thread_pool_submit( &connection_pool,
bdb_tool_index_task, ptr );
if ( bdb_tool_threads > 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<bdb_tool_threads; i++) {
int *ptr = ch_malloc( sizeof( int ));
*ptr = i;
ldap_pvt_thread_pool_submit( &connection_pool,
bdb_tool_index_task, ptr );
}
}
}
bdb_tool_info = bdb;
......@@ -177,29 +179,31 @@ int bdb_tool_entry_close(
&bdb_tool_trickle_mutex );
ldap_pvt_thread_mutex_unlock( &bdb_tool_trickle_mutex );
#endif
ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex );
if ( bdb_tool_threads > 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 );
}
......
......@@ -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 );
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment