#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/time.h>
-#include <ac/queue.h>
#include "ldap-int.h"
#include "ldap_pvt_thread.h"
-
+#include "ldap_queue.h"
#ifndef LDAP_THREAD_HAVE_TPOOL
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;
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;
{
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);
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
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);
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));
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
/* 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);
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);
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);
}
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;
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
* 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;
}
}
- 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;
}
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" : "",
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;
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;
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 );
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);
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 );
}
}
/* 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",
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;
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++;
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);
}
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 );
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 */
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 );
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 );
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 );
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 );
#include <ldap_schema.h>
#include "ldap_pvt_thread.h"
-#include "queue-compat.h"
+#include "ldap_queue.h"
LDAP_BEGIN_DECL
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;
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*/
}
/* 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;