]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/operation.c
silence warning
[openldap] / servers / slapd / operation.c
index b5b2f3d1e661b180962917607614e7a74be17893..1d84d0c7eaf07f78d573e9142bbd10f28f45683a 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2007 The OpenLDAP Foundation.
+ * Copyright 1998-2011 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #endif
 
 static ldap_pvt_thread_mutex_t slap_op_mutex;
-static LDAP_STAILQ_HEAD(s_o, Operation)        slap_free_ops;
 static time_t last_time;
 static int last_incr;
 
 void slap_op_init(void)
 {
        ldap_pvt_thread_mutex_init( &slap_op_mutex );
-       LDAP_STAILQ_INIT(&slap_free_ops);
 }
 
 void slap_op_destroy(void)
 {
-       Operation *o;
+       ldap_pvt_thread_mutex_destroy( &slap_op_mutex );
+}
 
-       while ( (o = LDAP_STAILQ_FIRST( &slap_free_ops )) != NULL) {
-               LDAP_STAILQ_REMOVE_HEAD( &slap_free_ops, o_next );
-               LDAP_STAILQ_NEXT(o, o_next) = NULL;
-               ch_free( o );
+static void
+slap_op_q_destroy( void *key, void *data )
+{
+       Operation *op, *op2;
+       for ( op = data; op; op = op2 ) {
+               op2 = LDAP_STAILQ_NEXT( op, o_next );
+               ber_memfree_x( op, NULL );
        }
-       ldap_pvt_thread_mutex_destroy( &slap_op_mutex );
 }
 
 void
@@ -72,12 +73,15 @@ slap_op_groups_free( Operation *op )
 }
 
 void
-slap_op_free( Operation *op )
+slap_op_free( Operation *op, void *ctx )
 {
        OperationBuffer *opbuf;
 
        assert( LDAP_STAILQ_NEXT(op, o_next) == NULL );
 
+       /* paranoia */
+       op->o_abandon = 1;
+
        if ( op->o_ber != NULL ) {
                ber_free( op->o_ber, 1 );
        }
@@ -110,22 +114,52 @@ slap_op_free( Operation *op )
        }
 #endif /* defined( LDAP_SLAPI ) */
 
+       if ( !BER_BVISNULL( &op->o_csn ) ) {
+               op->o_tmpfree( op->o_csn.bv_val, op->o_tmpmemctx );
+       }
+
+       if ( op->o_pagedresults_state != NULL ) {
+               op->o_tmpfree( op->o_pagedresults_state, op->o_tmpmemctx );
+       }
 
+       /* Selectively zero out the struct. Ignore fields that will
+        * get explicitly initialized later anyway. Keep o_abandon intact.
+        */
        opbuf = (OperationBuffer *) op;
-       memset( opbuf, 0, sizeof(*opbuf) );
-       op->o_hdr = &opbuf->ob_hdr;
+       op->o_bd = NULL;
+       BER_BVZERO( &op->o_req_dn );
+       BER_BVZERO( &op->o_req_ndn );
+       memset( &op->o_request, 0, sizeof( op->o_request ));
+       memset( &op->o_do_not_cache, 0, sizeof( Operation ) - offsetof( Operation, o_do_not_cache ));
+       memset( opbuf->ob_controls, 0, sizeof( opbuf->ob_controls ));
        op->o_controls = opbuf->ob_controls;
 
-       ldap_pvt_thread_mutex_lock( &slap_op_mutex );
-       LDAP_STAILQ_INSERT_HEAD( &slap_free_ops, op, o_next );
-       ldap_pvt_thread_mutex_unlock( &slap_op_mutex );
+       if ( ctx ) {
+               Operation *op2 = NULL;
+               ldap_pvt_thread_pool_setkey( ctx, (void *)slap_op_free,
+                       op, slap_op_q_destroy, (void **)&op2, NULL );
+               LDAP_STAILQ_NEXT( op, o_next ) = op2;
+               if ( op2 ) {
+                       op->o_tincr = op2->o_tincr + 1;
+                       /* No more than 10 ops on per-thread free list */
+                       if ( op->o_tincr > 10 ) {
+                               ldap_pvt_thread_pool_setkey( ctx, (void *)slap_op_free,
+                                       op2, slap_op_q_destroy, NULL, NULL );
+                               ber_memfree_x( op, NULL );
+                       }
+               } else {
+                       op->o_tincr = 1;
+               }
+       } else {
+               ber_memfree_x( op, NULL );
+       }
 }
 
 void
 slap_op_time(time_t *t, int *nop)
 {
-       *t = slap_get_time();
        ldap_pvt_thread_mutex_lock( &slap_op_mutex );
+       *t = slap_get_time();
        if ( *t == last_time ) {
                *nop = ++last_incr;
        } else {
@@ -141,16 +175,23 @@ slap_op_alloc(
     BerElement         *ber,
     ber_int_t  msgid,
     ber_tag_t  tag,
-    ber_int_t  id )
+    ber_int_t  id,
+       void *ctx )
 {
-       Operation       *op;
-
-       ldap_pvt_thread_mutex_lock( &slap_op_mutex );
-       if ((op = LDAP_STAILQ_FIRST( &slap_free_ops ))) {
-               LDAP_STAILQ_REMOVE_HEAD( &slap_free_ops, o_next );
+       Operation       *op = NULL;
+
+       if ( ctx ) {
+               void *otmp = NULL;
+               ldap_pvt_thread_pool_getkey( ctx, (void *)slap_op_free, &otmp, NULL );
+               if ( otmp ) {
+                       op = otmp;
+                       otmp = LDAP_STAILQ_NEXT( op, o_next );
+                       ldap_pvt_thread_pool_setkey( ctx, (void *)slap_op_free,
+                               otmp, slap_op_q_destroy, NULL, NULL );
+                       op->o_abandon = 0;
+                       op->o_cancel = 0;
+               }
        }
-       ldap_pvt_thread_mutex_unlock( &slap_op_mutex );
-
        if (!op) {
                op = (Operation *) ch_calloc( 1, sizeof(OperationBuffer) );
                op->o_hdr = &((OperationBuffer *) op)->ob_hdr;
@@ -163,7 +204,6 @@ slap_op_alloc(
 
        slap_op_time( &op->o_time, &op->o_tincr );
        op->o_opid = id;
-       op->o_res_ber = NULL;
 
 #if defined( LDAP_SLAPI )
        if ( slapi_plugins_used ) {