+static int
+bdb_tool_index_add(
+ Operation *op,
+ DB_TXN *txn,
+ Entry *e )
+{
+ struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
+
+ if ( !bdb->bi_nattrs )
+ return 0;
+
+ if ( slapMode & SLAP_TOOL_QUICK ) {
+ IndexRec *ir;
+ int i, rc;
+ Attribute *a;
+
+ ir = bdb_tool_index_rec;
+ memset(ir, 0, bdb->bi_nattrs * sizeof( IndexRec ));
+
+ for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
+ rc = bdb_index_recset( bdb, a, a->a_desc->ad_type,
+ &a->a_desc->ad_tags, ir );
+ if ( rc )
+ return rc;
+ }
+ bdb_tool_ix_id = e->e_id;
+ 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 ) {
+ ldap_pvt_thread_cond_wait( &bdb_tool_index_cond_main,
+ &bdb_tool_index_mutex );
+ }
+ for ( i=1; i<slap_tool_thread_max; i++ )
+ bdb_tool_index_threads[i] = LDAP_BUSY;
+ bdb_tool_index_tcount = slap_tool_thread_max - 1;
+ ldap_pvt_thread_cond_broadcast( &bdb_tool_index_cond_work );
+ ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex );
+ rc = bdb_index_recrun( op, bdb, ir, e->e_id, 0 );
+ if ( rc )
+ return rc;
+ ldap_pvt_thread_mutex_lock( &bdb_tool_index_mutex );
+ for ( i=1; i<slap_tool_thread_max; i++ ) {
+ if ( bdb_tool_index_threads[i] == LDAP_BUSY ) {
+ ldap_pvt_thread_cond_wait( &bdb_tool_index_cond_main,
+ &bdb_tool_index_mutex );
+ i--;
+ continue;
+ }
+ if ( bdb_tool_index_threads[i] ) {
+ rc = bdb_tool_index_threads[i];
+ break;
+ }
+ }
+ ldap_pvt_thread_mutex_unlock( &bdb_tool_index_mutex );
+ return rc;
+ } else {
+ return bdb_index_entry_add( op, txn, e );
+ }
+}
+