]> git.sur5r.net Git - openldap/commitdiff
Added slap_op_init/destroy, cache Operation structures
authorHoward Chu <hyc@openldap.org>
Tue, 25 Mar 2003 20:18:50 +0000 (20:18 +0000)
committerHoward Chu <hyc@openldap.org>
Tue, 25 Mar 2003 20:18:50 +0000 (20:18 +0000)
servers/slapd/main.c
servers/slapd/operation.c

index 2624b98d2f7dd3610e572b2032c69b3ea189d68a..0b399288905f5b2d22bf27196778181dc5f8f817 100644 (file)
@@ -361,6 +361,7 @@ int main( int argc, char **argv )
 
        extops_init();
        lutil_passwd_init();
+       slap_op_init();
 
 #ifdef SLAPD_MODULES
        if ( module_init() != 0 ) {
@@ -587,6 +588,8 @@ destroy:
        module_kill();
 #endif
 
+       slap_op_destroy();
+
        extops_kill();
 
 stop:
index 2a8da886da336e1b588d7941c8da1bfba0274b6d..499c884eaeb3484a4358a5eb1a880695d83977ef 100644 (file)
 #include "slapi.h"
 #endif
 
+static ldap_pvt_thread_mutex_t slap_op_mutex;
+static LDAP_STAILQ_HEAD(s_o, slap_op)  slap_free_ops;
+
+void slap_op_init()
+{
+       ldap_pvt_thread_mutex_init( &slap_op_mutex );
+       LDAP_STAILQ_INIT(&slap_free_ops);
+}
+
+void slap_op_destroy()
+{
+       Operation *o;
+
+       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 );
+       }
+       ldap_pvt_thread_mutex_destroy( &slap_op_mutex );
+}
 
 void
 slap_op_free( Operation *op )
@@ -62,7 +82,10 @@ slap_op_free( Operation *op )
        }
 #endif /* defined( LDAP_SLAPI ) */
 
-       free( (char *) op );
+       memset( op, 0, sizeof(Operation) );
+       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 );
 }
 
 Operation *
@@ -75,7 +98,14 @@ slap_op_alloc(
 {
        Operation       *op;
 
-       op = (Operation *) ch_calloc( 1, sizeof(Operation) );
+       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 );
+       }
+       ldap_pvt_thread_mutex_unlock( &slap_op_mutex );
+
+       if (!op)
+               op = (Operation *) ch_calloc( 1, sizeof(Operation) );
 
        op->o_ber = ber;
        op->o_msgid = msgid;