]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/connection.c
cleanup
[openldap] / servers / slapd / connection.c
index 4cf698c15b3767c8b135aca7487d392c0eedcc36..f067714cd8c88df9bbec81537856ada270d3f853 100644 (file)
@@ -919,6 +919,17 @@ Connection* connection_next( Connection *c, ber_socket_t *index )
                if( connections[*index].c_struct_state == SLAP_C_USED ) {
                        assert( connections[*index].c_conn_state != SLAP_C_INVALID );
                        c = &connections[(*index)++];
+                       if ( ldap_pvt_thread_mutex_trylock( &c->c_mutex )) {
+                               /* avoid deadlock */
+                               ldap_pvt_thread_mutex_unlock( &connections_mutex );
+                               ldap_pvt_thread_mutex_lock( &c->c_mutex );
+                               ldap_pvt_thread_mutex_lock( &connections_mutex );
+                               if ( c->c_struct_state != SLAP_C_USED ) {
+                                       ldap_pvt_thread_mutex_unlock( &c->c_mutex );
+                                       c = NULL;
+                                       continue;
+                               }
+                       }
                        break;
                }
 
@@ -926,7 +937,6 @@ Connection* connection_next( Connection *c, ber_socket_t *index )
                assert( connections[*index].c_conn_state == SLAP_C_INVALID );
        }
 
-       if( c != NULL ) ldap_pvt_thread_mutex_lock( &c->c_mutex );
        ldap_pvt_thread_mutex_unlock( &connections_mutex );
        return c;
 }
@@ -972,7 +982,7 @@ void connection_done( Connection *c )
 /*
  * NOTE: keep in sync with enum in slapd.h
  */
-static int (*opfun[])( Operation *op, SlapReply *rs ) = {
+static BI_op_func *opfun[] = {
        do_bind,
        do_unbind,
        do_add,