From 029306a5bebdcfec1de9c85c1c5e72b276f3fac7 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 3 Jan 2002 00:12:46 +0000 Subject: [PATCH] Use ldap_queue.h instead of --- libraries/libldap_r/tpool.c | 57 +++++++++++++++--------------- servers/slapd/abandon.c | 6 ++-- servers/slapd/back-monitor/conn.c | 4 +-- servers/slapd/back-shell/abandon.c | 4 +-- servers/slapd/connection.c | 42 +++++++++++----------- servers/slapd/operation.c | 2 +- servers/slapd/saslauthz.c | 4 +-- servers/slapd/slap.h | 8 ++--- servers/slapd/starttls.c | 8 ++--- 9 files changed, 67 insertions(+), 68 deletions(-) diff --git a/libraries/libldap_r/tpool.c b/libraries/libldap_r/tpool.c index b1b32957da..fa159b3df0 100644 --- a/libraries/libldap_r/tpool.c +++ b/libraries/libldap_r/tpool.c @@ -17,11 +17,10 @@ #include #include #include -#include #include "ldap-int.h" #include "ldap_pvt_thread.h" - +#include "ldap_queue.h" #ifndef LDAP_THREAD_HAVE_TPOOL @@ -33,19 +32,19 @@ enum ldap_int_thread_pool_state { typedef struct ldap_int_thread_ctx_s { union { - STAILQ_ENTRY(ldap_int_thread_ctx_s) q; - SLIST_ENTRY(ldap_int_thread_ctx_s) l; + LDAP_STAILQ_ENTRY(ldap_int_thread_ctx_s) q; + LDAP_SLIST_ENTRY(ldap_int_thread_ctx_s) l; } ltc_next; void *(*ltc_start_routine)( void *); void *ltc_arg; } ldap_int_thread_ctx_t; struct ldap_int_thread_pool_s { - STAILQ_ENTRY(ldap_int_thread_pool_s) ltp_next; + LDAP_STAILQ_ENTRY(ldap_int_thread_pool_s) ltp_next; ldap_pvt_thread_mutex_t ltp_mutex; ldap_pvt_thread_cond_t ltp_cond; - STAILQ_HEAD(tcq, ldap_int_thread_ctx_s) ltp_pending_list; - SLIST_HEAD(tcl, ldap_int_thread_ctx_s) ltp_free_list; + LDAP_STAILQ_HEAD(tcq, ldap_int_thread_ctx_s) ltp_pending_list; + LDAP_SLIST_HEAD(tcl, ldap_int_thread_ctx_s) ltp_free_list; long ltp_state; long ltp_max_count; long ltp_max_pending; @@ -55,9 +54,9 @@ struct ldap_int_thread_pool_s { long ltp_starting; }; -static STAILQ_HEAD(tpq, ldap_int_thread_pool_s) +static LDAP_STAILQ_HEAD(tpq, ldap_int_thread_pool_s) ldap_int_thread_pool_list = - STAILQ_HEAD_INITIALIZER(ldap_int_thread_pool_list); + LDAP_STAILQ_HEAD_INITIALIZER(ldap_int_thread_pool_list); static ldap_pvt_thread_mutex_t ldap_pvt_thread_pool_mutex; @@ -75,8 +74,8 @@ ldap_int_thread_pool_shutdown ( void ) { struct ldap_int_thread_pool_s *pool; - while ((pool = STAILQ_FIRST(&ldap_int_thread_pool_list)) != NULL) { - STAILQ_REMOVE_HEAD(&ldap_int_thread_pool_list, ltp_next); + while ((pool = LDAP_STAILQ_FIRST(&ldap_int_thread_pool_list)) != NULL) { + LDAP_STAILQ_REMOVE_HEAD(&ldap_int_thread_pool_list, ltp_next); ldap_pvt_thread_pool_destroy( &pool, 0); } ldap_pvt_thread_mutex_destroy(&ldap_pvt_thread_pool_mutex); @@ -107,10 +106,10 @@ ldap_pvt_thread_pool_init ( pool->ltp_state = LDAP_INT_THREAD_POOL_RUNNING; pool->ltp_max_count = max_threads; pool->ltp_max_pending = max_pending; - STAILQ_INIT(&pool->ltp_pending_list); - SLIST_INIT(&pool->ltp_free_list); + LDAP_STAILQ_INIT(&pool->ltp_pending_list); + LDAP_SLIST_INIT(&pool->ltp_free_list); ldap_pvt_thread_mutex_lock(&ldap_pvt_thread_pool_mutex); - STAILQ_INSERT_TAIL(&ldap_int_thread_pool_list, pool, ltp_next); + LDAP_STAILQ_INSERT_TAIL(&ldap_int_thread_pool_list, pool, ltp_next); ldap_pvt_thread_mutex_unlock(&ldap_pvt_thread_pool_mutex); #if 0 @@ -137,7 +136,7 @@ ldap_pvt_thread_pool_init ( if( rc != 0) { /* couldn't start one? then don't start any */ ldap_pvt_thread_mutex_lock(&ldap_pvt_thread_pool_mutex); - STAILQ_REMOVE(ldap_int_thread_pool_list, pool, + LDAP_STAILQ_REMOVE(ldap_int_thread_pool_list, pool, ldap_int_thread_pool_s, ltp_next); ldap_pvt_thread_mutex_unlock(&ldap_pvt_thread_pool_mutex); ldap_pvt_thread_cond_destroy(&pool->ltp_cond); @@ -177,9 +176,9 @@ ldap_pvt_thread_pool_submit ( ldap_pvt_thread_mutex_unlock(&pool->ltp_mutex); return(-1); } - ctx = SLIST_FIRST(&pool->ltp_free_list); + ctx = LDAP_SLIST_FIRST(&pool->ltp_free_list); if (ctx) { - SLIST_REMOVE_HEAD(&pool->ltp_free_list, ltc_next.l); + LDAP_SLIST_REMOVE_HEAD(&pool->ltp_free_list, ltc_next.l); } else { ctx = (ldap_int_thread_ctx_t *) LDAP_MALLOC( sizeof(ldap_int_thread_ctx_t)); @@ -193,7 +192,7 @@ ldap_pvt_thread_pool_submit ( ctx->ltc_arg = arg; pool->ltp_pending_count++; - STAILQ_INSERT_TAIL(&pool->ltp_pending_list, ctx, ltc_next.q); + LDAP_STAILQ_INSERT_TAIL(&pool->ltp_pending_list, ctx, ltc_next.q); ldap_pvt_thread_cond_signal(&pool->ltp_cond); if ((pool->ltp_open_count <= 0 || pool->ltp_pending_count > 1 @@ -223,14 +222,14 @@ ldap_pvt_thread_pool_submit ( /* no open threads at all?!? */ ldap_int_thread_ctx_t *ptr; - STAILQ_FOREACH(ptr, &pool->ltp_pending_list, ltc_next.q) + LDAP_STAILQ_FOREACH(ptr, &pool->ltp_pending_list, ltc_next.q) if (ptr == ctx) break; if (ptr == ctx) { /* no open threads, context not handled, so * back out of ltp_pending_count, free the context, * report the error. */ - STAILQ_REMOVE(&pool->ltp_pending_list, ctx, + LDAP_STAILQ_REMOVE(&pool->ltp_pending_list, ctx, ldap_int_thread_ctx_s, ltc_next.q); pool->ltp_pending_count++; ldap_pvt_thread_mutex_unlock(&pool->ltp_mutex); @@ -304,10 +303,10 @@ ldap_pvt_thread_pool_destroy ( ldap_pvt_thread_pool_t *tpool, int run_pending ) if (pool == NULL) return(-1); ldap_pvt_thread_mutex_lock(&ldap_pvt_thread_pool_mutex); - STAILQ_FOREACH(pptr, &ldap_int_thread_pool_list, ltp_next) + LDAP_STAILQ_FOREACH(pptr, &ldap_int_thread_pool_list, ltp_next) if (pptr == pool) break; if (pptr == pool) - STAILQ_REMOVE(&ldap_int_thread_pool_list, pool, + LDAP_STAILQ_REMOVE(&ldap_int_thread_pool_list, pool, ldap_int_thread_pool_s, ltp_next); ldap_pvt_thread_mutex_unlock(&ldap_pvt_thread_pool_mutex); @@ -334,15 +333,15 @@ ldap_pvt_thread_pool_destroy ( ldap_pvt_thread_pool_t *tpool, int run_pending ) ldap_pvt_thread_mutex_unlock(&pool->ltp_mutex); } while (waiting > 0); - while ((ctx = STAILQ_FIRST(&pool->ltp_pending_list)) != NULL) + while ((ctx = LDAP_STAILQ_FIRST(&pool->ltp_pending_list)) != NULL) { - STAILQ_REMOVE_HEAD(&pool->ltp_pending_list, ltc_next.q); + LDAP_STAILQ_REMOVE_HEAD(&pool->ltp_pending_list, ltc_next.q); free(ctx); } - while ((ctx = SLIST_FIRST(&pool->ltp_free_list)) != NULL) + while ((ctx = LDAP_SLIST_FIRST(&pool->ltp_free_list)) != NULL) { - SLIST_REMOVE_HEAD(&pool->ltp_free_list, ltc_next.l); + LDAP_SLIST_REMOVE_HEAD(&pool->ltp_free_list, ltc_next.l); free(ctx); } @@ -364,9 +363,9 @@ ldap_int_thread_pool_wrapper ( ldap_pvt_thread_mutex_lock(&pool->ltp_mutex); while (pool->ltp_state != LDAP_INT_THREAD_POOL_STOPPING) { - ctx = STAILQ_FIRST(&pool->ltp_pending_list); + ctx = LDAP_STAILQ_FIRST(&pool->ltp_pending_list); if (ctx) { - STAILQ_REMOVE_HEAD(&pool->ltp_pending_list, ltc_next.q); + LDAP_STAILQ_REMOVE_HEAD(&pool->ltp_pending_list, ltc_next.q); } else { if (pool->ltp_state == LDAP_INT_THREAD_POOL_FINISHING) break; @@ -401,7 +400,7 @@ ldap_int_thread_pool_wrapper ( ldap_pvt_thread_mutex_unlock(&pool->ltp_mutex); (ctx->ltc_start_routine)(ctx->ltc_arg); - SLIST_INSERT_HEAD(&pool->ltp_free_list, ctx, ltc_next.l); + LDAP_SLIST_INSERT_HEAD(&pool->ltp_free_list, ctx, ltc_next.l); ldap_pvt_thread_yield(); /* if we use an idle timer, here's diff --git a/servers/slapd/abandon.c b/servers/slapd/abandon.c index d283603198..30ba6af812 100644 --- a/servers/slapd/abandon.c +++ b/servers/slapd/abandon.c @@ -91,7 +91,7 @@ do_abandon( * flag and abort the operation at a convenient time. */ - STAILQ_FOREACH( o, &conn->c_ops, o_next ) { + LDAP_STAILQ_FOREACH( o, &conn->c_ops, o_next ) { if ( o->o_msgid == id ) { ldap_pvt_thread_mutex_lock( &o->o_abandonmutex ); o->o_abandon = 1; @@ -102,13 +102,13 @@ do_abandon( } } - STAILQ_FOREACH( o, &conn->c_pending_ops, o_next ) { + LDAP_STAILQ_FOREACH( o, &conn->c_pending_ops, o_next ) { if ( o->o_msgid == id ) break; } if( o != NULL ) { - STAILQ_REMOVE( &conn->c_pending_ops, o, slap_op, o_next ); + LDAP_STAILQ_REMOVE( &conn->c_pending_ops, o, slap_op, o_next ); slap_op_free( o ); notfound = 0; } diff --git a/servers/slapd/back-monitor/conn.c b/servers/slapd/back-monitor/conn.c index e2bfdc5bd7..6fe1d0a5e9 100644 --- a/servers/slapd/back-monitor/conn.c +++ b/servers/slapd/back-monitor/conn.c @@ -331,8 +331,8 @@ conn_create( c->c_currentber ? "r" : "", c->c_writewaiter ? "w" : "", - STAILQ_EMPTY( &c->c_ops ) ? "" : "x", - STAILQ_EMPTY( &c->c_pending_ops ) ? "" : "p", + LDAP_STAILQ_EMPTY( &c->c_ops ) ? "" : "x", + LDAP_STAILQ_EMPTY( &c->c_pending_ops ) ? "" : "p", connection_state2str( c->c_conn_state ), c->c_sasl_bind_in_progress ? "S" : "", diff --git a/servers/slapd/back-shell/abandon.c b/servers/slapd/back-shell/abandon.c index a638feca38..0bcdf769e7 100644 --- a/servers/slapd/back-shell/abandon.c +++ b/servers/slapd/back-shell/abandon.c @@ -33,14 +33,14 @@ shell_back_abandon( if ( si->si_abandon == NULL ) { ldap_pvt_thread_mutex_lock( &conn->c_mutex ); pid = -1; - STAILQ_FOREACH( o, &conn->c_ops, o_next ) { + LDAP_STAILQ_FOREACH( o, &conn->c_ops, o_next ) { if ( o->o_msgid == msgid ) { pid = (pid_t) o->o_private; break; } } if( pid == -1 ) { - STAILQ_FOREACH( o, &conn->c_pending_ops, o_next ) { + LDAP_STAILQ_FOREACH( o, &conn->c_pending_ops, o_next ) { if ( o->o_msgid == msgid ) { pid = (pid_t) o->o_private; break; diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 5e68e4e563..799c4adf7b 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -425,8 +425,8 @@ long connection_init( c->c_peer_name = NULL; c->c_sock_name = NULL; - STAILQ_INIT(&c->c_ops); - STAILQ_INIT(&c->c_pending_ops); + LDAP_STAILQ_INIT(&c->c_ops); + LDAP_STAILQ_INIT(&c->c_pending_ops); c->c_sasl_bind_mech = NULL; c->c_sasl_context = NULL; @@ -461,8 +461,8 @@ long connection_init( assert( c->c_peer_domain == NULL ); assert( c->c_peer_name == NULL ); assert( c->c_sock_name == NULL ); - assert( STAILQ_EMPTY(&c->c_ops) ); - assert( STAILQ_EMPTY(&c->c_pending_ops) ); + assert( LDAP_STAILQ_EMPTY(&c->c_ops) ); + assert( LDAP_STAILQ_EMPTY(&c->c_pending_ops) ); assert( c->c_sasl_bind_mech == NULL ); assert( c->c_sasl_context == NULL ); assert( c->c_sasl_extra == NULL ); @@ -621,7 +621,7 @@ connection_destroy( Connection *c ) assert( c != NULL ); assert( c->c_struct_state != SLAP_C_UNUSED ); assert( c->c_conn_state != SLAP_C_INVALID ); - assert( STAILQ_EMPTY(&c->c_ops) ); + assert( LDAP_STAILQ_EMPTY(&c->c_ops) ); backend_connection_destroy(c); @@ -720,16 +720,16 @@ static void connection_abandon( Connection *c ) Operation *o; - STAILQ_FOREACH(o, &c->c_ops, o_next) { + LDAP_STAILQ_FOREACH(o, &c->c_ops, o_next) { ldap_pvt_thread_mutex_lock( &o->o_abandonmutex ); o->o_abandon = 1; ldap_pvt_thread_mutex_unlock( &o->o_abandonmutex ); } /* remove pending operations */ - while ( (o = STAILQ_FIRST( &c->c_pending_ops )) != NULL) { - STAILQ_REMOVE_HEAD( &c->c_pending_ops, o_next ); - STAILQ_NEXT(o, o_next) = NULL; + while ( (o = LDAP_STAILQ_FIRST( &c->c_pending_ops )) != NULL) { + LDAP_STAILQ_REMOVE_HEAD( &c->c_pending_ops, o_next ); + LDAP_STAILQ_NEXT(o, o_next) = NULL; slap_op_free( o ); } } @@ -783,7 +783,7 @@ static void connection_close( Connection *c ) /* note: connections_mutex and c_mutex should be locked by caller */ ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd ); - if( !STAILQ_EMPTY(&c->c_ops) ) { + if( !LDAP_STAILQ_EMPTY(&c->c_ops) ) { #ifdef NEW_LOGGING LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1, "connection_close: conn %d deferring sd %d\n", @@ -986,8 +986,8 @@ operations_error: conn->c_n_ops_executing--; conn->c_n_ops_completed++; - STAILQ_REMOVE( &conn->c_ops, arg->co_op, slap_op, o_next); - STAILQ_NEXT(arg->co_op, o_next) = NULL; + LDAP_STAILQ_REMOVE( &conn->c_ops, arg->co_op, slap_op, o_next); + LDAP_STAILQ_NEXT(arg->co_op, o_next) = NULL; slap_op_free( arg->co_op ); arg->co_op = NULL; arg->co_conn = NULL; @@ -1351,7 +1351,7 @@ connection_input( Debug( LDAP_DEBUG_ANY, "deferring operation\n", 0, 0, 0 ); #endif conn->c_n_ops_pending++; - STAILQ_INSERT_TAIL( &conn->c_pending_ops, op, o_next ); + LDAP_STAILQ_INSERT_TAIL( &conn->c_pending_ops, op, o_next ); } else { conn->c_n_ops_executing++; @@ -1434,9 +1434,9 @@ connection_resched( Connection *conn ) return 0; } - while ((op = STAILQ_FIRST( &conn->c_pending_ops )) != NULL) { - STAILQ_REMOVE_HEAD( &conn->c_pending_ops, o_next ); - STAILQ_NEXT(op, o_next) = NULL; + while ((op = LDAP_STAILQ_FIRST( &conn->c_pending_ops )) != NULL) { + LDAP_STAILQ_REMOVE_HEAD( &conn->c_pending_ops, o_next ); + LDAP_STAILQ_NEXT(op, o_next) = NULL; /* pending operations should not be marked for abandonment */ assert(!op->o_abandon); @@ -1483,7 +1483,7 @@ static int connection_op_activate( Connection *conn, Operation *op ) } arg->co_op->o_connid = conn->c_connid; - STAILQ_INSERT_TAIL( &conn->c_ops, arg->co_op, o_next ); + LDAP_STAILQ_INSERT_TAIL( &conn->c_ops, arg->co_op, o_next ); status = ldap_pvt_thread_pool_submit( &connection_pool, connection_operation, (void *) arg ); @@ -1586,7 +1586,7 @@ int connection_internal_open( Connection **conn, LDAP **ldp, const char *id ) op->o_protocol = LDAP_VERSION3; (*conn) = connection_get( fd[1] ); - STAILQ_INSERT_HEAD( &(*conn)->c_ops, op, o_next); + LDAP_STAILQ_INSERT_HEAD( &(*conn)->c_ops, op, o_next); (*conn)->c_conn_state = SLAP_C_ACTIVE; /* Create the client side of the connection */ @@ -1605,10 +1605,10 @@ int connection_internal_open( Connection **conn, LDAP **ldp, const char *id ) void connection_internal_close( Connection *conn ) { - Operation *op = STAILQ_FIRST(&conn->c_ops); + Operation *op = LDAP_STAILQ_FIRST(&conn->c_ops); - STAILQ_REMOVE_HEAD(&conn->c_ops, o_next); - STAILQ_NEXT(op, o_next) = NULL; + LDAP_STAILQ_REMOVE_HEAD(&conn->c_ops, o_next); + LDAP_STAILQ_NEXT(op, o_next) = NULL; slap_op_free( op ); connection_closing( conn ); connection_close( conn ); diff --git a/servers/slapd/operation.c b/servers/slapd/operation.c index 9440784b4d..67f31c5c74 100644 --- a/servers/slapd/operation.c +++ b/servers/slapd/operation.c @@ -18,7 +18,7 @@ void slap_op_free( Operation *op ) { - assert( STAILQ_NEXT(op, o_next) == NULL ); + assert( LDAP_STAILQ_NEXT(op, o_next) == NULL ); if ( op->o_ber != NULL ) { ber_free( op->o_ber, 1 ); diff --git a/servers/slapd/saslauthz.c b/servers/slapd/saslauthz.c index 6de3bf20b3..9ceef3e6d0 100644 --- a/servers/slapd/saslauthz.c +++ b/servers/slapd/saslauthz.c @@ -354,7 +354,7 @@ char *slap_sasl2dn( char *saslname ) if( rc != LDAP_SUCCESS ) goto FINISHED; - (*be->be_search)( be, conn, STAILQ_FIRST(&conn->c_ops), /*base*/NULL, &searchbase, + (*be->be_search)( be, conn, LDAP_STAILQ_FIRST(&conn->c_ops), /*base*/NULL, &searchbase, scope, /*deref=*/1, /*sizelimit=*/1, /*time=*/0, filter, /*fstr=*/NULL, /*attrs=*/NULL, /*attrsonly=*/0 ); @@ -484,7 +484,7 @@ int slap_sasl_match( char *rule, char *assertDN, char *authc ) if( rc != LDAP_SUCCESS ) goto CONCLUDED; - (*be->be_search)( be, conn, STAILQ_FIRST(&conn->c_ops), /*base=*/NULL, &searchbase, + (*be->be_search)( be, conn, LDAP_STAILQ_FIRST(&conn->c_ops), /*base=*/NULL, &searchbase, scope, /*deref=*/1, /*sizelimit=*/0, /*time=*/0, filter, /*fstr=*/NULL, /*attrs=*/NULL, /*attrsonly=*/0 ); diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index cefc21e844..598f4af7e9 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -32,7 +32,7 @@ #include #include "ldap_pvt_thread.h" -#include "queue-compat.h" +#include "ldap_queue.h" LDAP_BEGIN_DECL @@ -1294,7 +1294,7 @@ typedef struct slap_op { slap_response *o_response; /* callback function */ slap_sresult *o_sresult; /* search result callback */ - STAILQ_ENTRY(slap_op) o_next; /* next operation in list */ + LDAP_STAILQ_ENTRY(slap_op) o_next; /* next operation in list */ void *o_private; /* anything the backend needs */ void *o_glue; /* for the glue backend */ } Operation; @@ -1348,8 +1348,8 @@ typedef struct slap_conn { ber_int_t c_protocol; /* version of the LDAP protocol used by client */ - STAILQ_HEAD(c_o, slap_op) c_ops; /* list of operations being processed */ - STAILQ_HEAD(c_po, slap_op) c_pending_ops; /* list of pending operations */ + LDAP_STAILQ_HEAD(c_o, slap_op) c_ops; /* list of operations being processed */ + LDAP_STAILQ_HEAD(c_po, slap_op) c_pending_ops; /* list of pending operations */ ldap_pvt_thread_mutex_t c_write_mutex; /* only one pdu written at a time */ ldap_pvt_thread_cond_t c_write_cv; /* used to wait for sd write-ready*/ diff --git a/servers/slapd/starttls.c b/servers/slapd/starttls.c index d08ddce042..750a3ff28a 100644 --- a/servers/slapd/starttls.c +++ b/servers/slapd/starttls.c @@ -52,10 +52,10 @@ starttls_extop ( } /* can't start TLS if there are other op's around */ - if (( !STAILQ_EMPTY(&conn->c_ops) && - (STAILQ_FIRST(&conn->c_ops) != op || - STAILQ_NEXT(op, o_next) != NULL)) || - ( !STAILQ_EMPTY(&conn->c_pending_ops) )) + if (( !LDAP_STAILQ_EMPTY(&conn->c_ops) && + (LDAP_STAILQ_FIRST(&conn->c_ops) != op || + LDAP_STAILQ_NEXT(op, o_next) != NULL)) || + ( !LDAP_STAILQ_EMPTY(&conn->c_pending_ops) )) { *text = "cannot start TLS when operations are outstanding"; rc = LDAP_OPERATIONS_ERROR; -- 2.39.5