]> git.sur5r.net Git - openldap/commitdiff
Rework connection lock code to avoid unnecessary lock reaquire
authorKurt Zeilenga <kurt@openldap.org>
Tue, 5 Sep 2000 19:11:27 +0000 (19:11 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Tue, 5 Sep 2000 19:11:27 +0000 (19:11 +0000)
servers/slapd/connection.c

index 14e3b40c54c92e024284003aaf2407b6c50cca81..f50eb3d269abfe8e47dc0f4721e1b9d8dd72a05b 100644 (file)
@@ -1098,29 +1098,35 @@ connection_resched( Connection *conn )
        Operation *op;
 
        if( conn->c_conn_state == SLAP_C_CLOSING ) {
+               int rc;
                ber_socket_t    sd;
                ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
 
-               Debug( LDAP_DEBUG_TRACE,
-                       "connection_resched: reaquiring locks conn=%ld sd=%d\n",
-                       conn->c_connid, sd, 0 );
+               /* us trylock to avoid possible deadlock */
+               rc = ldap_pvt_thread_mutex_trylock( &connections_mutex );
 
-               /* reaquire locks in the right order... this may
-                * allow another thread to close this connection,
-                * so recheck state
-                */
-               ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
-               ldap_pvt_thread_mutex_lock( &connections_mutex );
-               ldap_pvt_thread_mutex_lock( &conn->c_mutex );
+               if( rc ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "connection_resched: reaquiring locks conn=%ld sd=%d\n",
+                               conn->c_connid, sd, 0 );
+                       /*
+                        * reaquire locks in the right order...
+                        * this may allow another thread to close this connection,
+                        * so recheck state below.
+                        */
+                       ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
+                       ldap_pvt_thread_mutex_lock( &connections_mutex );
+                       ldap_pvt_thread_mutex_lock( &conn->c_mutex );
+               }
 
                if( conn->c_conn_state != SLAP_C_CLOSING ) {
-                       Debug( LDAP_DEBUG_TRACE,
-                               "connection_resched: closed by other thread conn=%ld sd=%d\n",
+                       Debug( LDAP_DEBUG_TRACE, "connection_resched: "
+                               "closed by other thread conn=%ld sd=%d\n",
                                conn->c_connid, sd, 0 );
 
                } else {
-                       Debug( LDAP_DEBUG_TRACE,
-                               "connection_resched: attempting closing conn=%ld sd=%d\n",
+                       Debug( LDAP_DEBUG_TRACE, "connection_resched: "
+                               "attempting closing conn=%ld sd=%d\n",
                                conn->c_connid, sd, 0 );
 
                        connection_close( conn );