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;
&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 ) {
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 );
}
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:
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;
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;
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;
}
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 );
}
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 );
}