Blame SOURCES/0081-Ticket-48406-Avoid-self-deadlock-by-PR_Lock-conn-c_m.patch

400eba
From ae9df61b523152e01051afa8c115c97fe59310b5 Mon Sep 17 00:00:00 2001
400eba
From: Noriko Hosoi <nhosoi@redhat.com>
400eba
Date: Mon, 11 Jan 2016 15:53:28 -0800
400eba
Subject: [PATCH 81/81] Ticket #48406 - Avoid self deadlock by
400eba
 PR_Lock(conn->c_mutex)
400eba
400eba
Description:  Fixing ticket 48338 introduced a self deadlock.
400eba
To avoid the self deadlock, tried to remove PR_Lock(conn->c_mutex)
400eba
which looked harmless, but it introduced a crash by memory corruption.
400eba
400eba
This patch replaces PR_Lock/Unlock with PR_EnterMonitor/ExitMonitor,
400eba
respectively.
400eba
400eba
https://fedorahosted.org/389/ticket/48406
400eba
400eba
Reviewed by rmeggins@redhat.com, lkrispen@redhat.com, and wibrown@redhat.com.
400eba
Thank you, Rich, Ludwig and William!
400eba
400eba
(cherry picked from commit f25f804a8bce83b3790e7045dfc03230d7ece1af)
400eba
(cherry picked from commit 84da7d05ddc5a963b0d025df08f38a6ccd7d90d2)
400eba
---
400eba
 ldap/servers/slapd/abandon.c         |   4 +-
400eba
 ldap/servers/slapd/bind.c            |   4 +-
400eba
 ldap/servers/slapd/connection.c      |  64 +++++++++++-----------
400eba
 ldap/servers/slapd/conntable.c       |  19 +++----
400eba
 ldap/servers/slapd/daemon.c          |  22 ++++----
400eba
 ldap/servers/slapd/extendop.c        |  10 ++--
400eba
 ldap/servers/slapd/operation.c       |  18 +++----
400eba
 ldap/servers/slapd/opshared.c        |  18 +++----
400eba
 ldap/servers/slapd/pagedresults.c    | 100 +++++++++++++++++------------------
400eba
 ldap/servers/slapd/pblock.c          |  72 ++++++++++++-------------
400eba
 ldap/servers/slapd/psearch.c         |  10 ++--
400eba
 ldap/servers/slapd/saslbind.c        |  26 ++++-----
400eba
 ldap/servers/slapd/slap.h            |   2 +-
400eba
 ldap/servers/slapd/start_tls_extop.c |  10 ++--
400eba
 ldap/servers/slapd/unbind.c          |   4 +-
400eba
 15 files changed, 192 insertions(+), 191 deletions(-)
400eba
400eba
diff --git a/ldap/servers/slapd/abandon.c b/ldap/servers/slapd/abandon.c
400eba
index 761b895..9a39f6a 100644
400eba
--- a/ldap/servers/slapd/abandon.c
400eba
+++ b/ldap/servers/slapd/abandon.c
400eba
@@ -77,7 +77,7 @@ do_abandon( Slapi_PBlock *pb )
400eba
 	 * flag and abort the operation at a convenient time.
400eba
 	 */
400eba
 
400eba
-	PR_Lock( pb->pb_conn->c_mutex );
400eba
+	PR_EnterMonitor(pb->pb_conn->c_mutex);
400eba
 	for ( o = pb->pb_conn->c_ops; o != NULL; o = o->o_next ) {
400eba
 		if ( o->o_msgid == id && o != pb->pb_op)
400eba
 			break;
400eba
@@ -138,7 +138,7 @@ do_abandon( Slapi_PBlock *pb )
400eba
 			o->o_results.r.r_search.nentries, current_time() - o->o_time );
400eba
 	}
400eba
 
400eba
-	PR_Unlock( pb->pb_conn->c_mutex );
400eba
+	PR_ExitMonitor(pb->pb_conn->c_mutex);
400eba
 	/*
400eba
 	 * Wake up the persistent searches, so they
400eba
 	 * can notice if they've been abandoned.
400eba
diff --git a/ldap/servers/slapd/bind.c b/ldap/servers/slapd/bind.c
400eba
index 474b508..f81edfb 100644
400eba
--- a/ldap/servers/slapd/bind.c
400eba
+++ b/ldap/servers/slapd/bind.c
400eba
@@ -258,7 +258,7 @@ do_bind( Slapi_PBlock *pb )
400eba
         slapi_pblock_get (pb, SLAPI_PWPOLICY, &pw_response_requested);
400eba
     }
400eba
 
400eba
-    PR_Lock( pb->pb_conn->c_mutex );
400eba
+    PR_EnterMonitor(pb->pb_conn->c_mutex);
400eba
 
400eba
     bind_credentials_clear( pb->pb_conn, PR_FALSE, /* do not lock conn */
400eba
                             PR_FALSE /* do not clear external creds. */ );
400eba
@@ -291,7 +291,7 @@ do_bind( Slapi_PBlock *pb )
400eba
      * bound user can work properly
400eba
      */
400eba
     pb->pb_conn->c_needpw = 0;
400eba
-    PR_Unlock( pb->pb_conn->c_mutex );
400eba
+    PR_ExitMonitor(pb->pb_conn->c_mutex);
400eba
 
400eba
     log_bind_access(pb, dn?dn:"empty", method, version, saslmech, NULL);
400eba
 
400eba
diff --git a/ldap/servers/slapd/connection.c b/ldap/servers/slapd/connection.c
400eba
index fc3b741..a3d123e 100644
400eba
--- a/ldap/servers/slapd/connection.c
400eba
+++ b/ldap/servers/slapd/connection.c
400eba
@@ -147,7 +147,7 @@ connection_done(Connection *conn)
400eba
 	}
400eba
 	if (NULL != conn->c_mutex)
400eba
 	{
400eba
-		PR_DestroyLock(conn->c_mutex);
400eba
+		PR_DestroyMonitor(conn->c_mutex);
400eba
 	}
400eba
 	if (NULL != conn->c_pdumutex)
400eba
 	{
400eba
@@ -738,10 +738,10 @@ int connection_is_free (Connection *conn)
400eba
 {
400eba
     int rc;
400eba
 
400eba
-    PR_Lock(conn->c_mutex);
400eba
+    PR_EnterMonitor(conn->c_mutex);
400eba
     rc = conn->c_sd == SLAPD_INVALID_SOCKET && conn->c_refcnt == 0 &&
400eba
          !(conn->c_flags & CONN_FLAG_CLOSING);
400eba
-    PR_Unlock(conn->c_mutex);
400eba
+    PR_ExitMonitor(conn->c_mutex);
400eba
 
400eba
     return rc;
400eba
 }
400eba
@@ -1128,7 +1128,7 @@ int connection_read_operation(Connection *conn, Operation *op, ber_tag_t *tag, i
400eba
 	PRInt32 syserr = 0;
400eba
 	size_t buffer_data_avail;
400eba
 
400eba
-	PR_Lock(conn->c_mutex);
400eba
+	PR_EnterMonitor(conn->c_mutex);
400eba
 	/*
400eba
 	 * if the socket is still valid, get the ber element
400eba
 	 * waiting for us on this connection. timeout is handled
400eba
@@ -1317,15 +1317,15 @@ int connection_read_operation(Connection *conn, Operation *op, ber_tag_t *tag, i
400eba
 	}
400eba
 	op->o_tag = *tag;
400eba
 done:
400eba
-	PR_Unlock(conn->c_mutex);
400eba
+	PR_ExitMonitor(conn->c_mutex);
400eba
 	return ret;
400eba
 }
400eba
 
400eba
 void connection_make_readable(Connection *conn)
400eba
 {
400eba
-	PR_Lock( conn->c_mutex );
400eba
+	PR_EnterMonitor(conn->c_mutex);
400eba
 	conn->c_gettingber = 0;
400eba
-	PR_Unlock( conn->c_mutex );
400eba
+	PR_ExitMonitor(conn->c_mutex);
400eba
 	signal_listner();
400eba
 }
400eba
 
400eba
@@ -1347,7 +1347,7 @@ void connection_check_activity_level(Connection *conn)
400eba
 {
400eba
 	int current_count = 0;
400eba
 	int delta_count = 0;
400eba
-	PR_Lock( conn->c_mutex );
400eba
+	PR_EnterMonitor(conn->c_mutex);
400eba
 	/* get the current op count */
400eba
 	current_count = conn->c_opscompleted;
400eba
 	/* compare to the previous op count */
400eba
@@ -1358,7 +1358,7 @@ void connection_check_activity_level(Connection *conn)
400eba
 	conn->c_private->previous_op_count = current_count;
400eba
 	/* update the last checked time */
400eba
 	conn->c_private->previous_count_check_time = current_time();
400eba
-	PR_Unlock( conn->c_mutex );
400eba
+	PR_ExitMonitor(conn->c_mutex);
400eba
 	LDAPDebug(LDAP_DEBUG_CONNS,"conn %" NSPRIu64 " activity level = %d\n",conn->c_connid,delta_count,0); 
400eba
 }
400eba
 
400eba
@@ -1402,7 +1402,7 @@ void connection_enter_leave_turbo(Connection *conn, int current_turbo_flag, int
400eba
 	int connection_count = 0;
400eba
 	int our_rank = 0;
400eba
 	int threshold_rank = 0;
400eba
-	PR_Lock(conn->c_mutex);
400eba
+	PR_EnterMonitor(conn->c_mutex);
400eba
 	/* We can already be in turbo mode, or not */
400eba
 	current_mode = current_turbo_flag;
400eba
 	if (pagedresults_in_use_nolock(conn)) {
400eba
@@ -1458,7 +1458,7 @@ void connection_enter_leave_turbo(Connection *conn, int current_turbo_flag, int
400eba
 		}
400eba
 	  }
400eba
 	}
400eba
-	PR_Unlock(conn->c_mutex);
400eba
+	PR_ExitMonitor(conn->c_mutex);
400eba
 	if (current_mode != new_mode) {
400eba
 		if (current_mode) {
400eba
 			LDAPDebug(LDAP_DEBUG_CONNS,"conn %" NSPRIu64 " leaving turbo mode\n",conn->c_connid,0,0); 
400eba
@@ -1564,13 +1564,13 @@ connection_threadmain()
400eba
 			*/
400eba
 			PR_Sleep(PR_INTERVAL_NO_WAIT);
400eba
 
400eba
-			PR_Lock(conn->c_mutex);
400eba
+			PR_EnterMonitor(conn->c_mutex);
400eba
 			/* Make our own pb in turbo mode */
400eba
 			connection_make_new_pb(pb,conn);
400eba
 			if (connection_call_io_layer_callbacks(conn)) {
400eba
 				LDAPDebug0Args( LDAP_DEBUG_ANY, "Error: could not add/remove IO layers from connection\n" );
400eba
 			}
400eba
-			PR_Unlock(conn->c_mutex);
400eba
+			PR_ExitMonitor(conn->c_mutex);
400eba
 			if (! config_check_referral_mode()) {
400eba
 			  slapi_counter_increment(ops_initiated);
400eba
 			  slapi_counter_increment(g_get_global_snmp_vars()->ops_tbl.dsInOps); 
400eba
@@ -1685,7 +1685,7 @@ connection_threadmain()
400eba
  */
400eba
 			} else if (!enable_nunc_stans) { /* more data in conn - just put back on work_q - bypass poll */
400eba
 				bypasspollcnt++;
400eba
-				PR_Lock(conn->c_mutex);
400eba
+				PR_EnterMonitor(conn->c_mutex);
400eba
 				/* don't do this if it would put us over the max threads per conn */
400eba
 				if (conn->c_threadnumber < maxthreads) {
400eba
 					/* for turbo, c_idlesince is set above - for !turbo and
400eba
@@ -1700,7 +1700,7 @@ connection_threadmain()
400eba
 					/* keep count of how many times maxthreads has blocked an operation */
400eba
 					conn->c_maxthreadsblocked++;
400eba
 				}
400eba
-				PR_Unlock(conn->c_mutex);
400eba
+				PR_ExitMonitor(conn->c_mutex);
400eba
 			}
400eba
 		}
400eba
 
400eba
@@ -1736,14 +1736,14 @@ connection_threadmain()
400eba
 
400eba
 done:	
400eba
 		if (doshutdown) {
400eba
-			PR_Lock(conn->c_mutex);
400eba
+			PR_EnterMonitor(conn->c_mutex);
400eba
 			connection_remove_operation_ext(pb, conn, op);
400eba
 			connection_make_readable_nolock(conn);
400eba
 			conn->c_threadnumber--;
400eba
 			slapi_counter_decrement(conns_in_maxthreads);
400eba
 			slapi_counter_decrement(g_get_global_snmp_vars()->ops_tbl.dsConnectionsInMaxThreads);
400eba
 			connection_release_nolock(conn);
400eba
-			PR_Unlock(conn->c_mutex);
400eba
+			PR_ExitMonitor(conn->c_mutex);
400eba
 			signal_listner();
400eba
 			return;
400eba
 		}
400eba
@@ -1760,9 +1760,9 @@ done:
400eba
 		slapi_counter_increment(ops_completed);
400eba
 		/* If this op isn't a persistent search, remove it */
400eba
 		if ( pb->pb_op->o_flags & OP_FLAG_PS ) {
400eba
-			    PR_Lock( conn->c_mutex );
400eba
+			    PR_EnterMonitor(conn->c_mutex);
400eba
 			    connection_release_nolock (conn); /* psearch acquires ref to conn - release this one now */
400eba
-			    PR_Unlock( conn->c_mutex );
400eba
+			    PR_ExitMonitor(conn->c_mutex);
400eba
 			    /* ps_add makes a shallow copy of the pb - so we
400eba
 			     * can't free it or init it here - just memset it to 0
400eba
 			     * ps_send_results will call connection_remove_operation_ext to free it
400eba
@@ -1770,7 +1770,7 @@ done:
400eba
 			    memset(pb, 0, sizeof(*pb));
400eba
 		} else {
400eba
 			/* delete from connection operation queue & decr refcnt */
400eba
-			PR_Lock( conn->c_mutex );
400eba
+			PR_EnterMonitor(conn->c_mutex);
400eba
 			connection_remove_operation_ext( pb, conn, op );
400eba
 
400eba
 			/* If we're in turbo mode, we keep our reference to the connection alive */
400eba
@@ -1811,7 +1811,7 @@ done:
400eba
 					signal_listner();
400eba
 				}
400eba
 			}
400eba
-			PR_Unlock( conn->c_mutex );
400eba
+			PR_ExitMonitor(conn->c_mutex);
400eba
 		}
400eba
 	} /* while (1) */
400eba
 }
400eba
@@ -2071,16 +2071,16 @@ op_copy_identity(Connection *conn, Operation *op)
400eba
     size_t dnlen;
400eba
     size_t typelen;
400eba
 
400eba
-	PR_Lock( conn->c_mutex );
400eba
-	dnlen= conn->c_dn ? strlen (conn->c_dn) : 0;
400eba
-	typelen= conn->c_authtype ? strlen (conn->c_authtype) : 0;
400eba
+    PR_EnterMonitor(conn->c_mutex);
400eba
+    dnlen= conn->c_dn ? strlen (conn->c_dn) : 0;
400eba
+    typelen= conn->c_authtype ? strlen (conn->c_authtype) : 0;
400eba
 
400eba
-	slapi_sdn_done(&op->o_sdn);
400eba
-	slapi_ch_free_string(&(op->o_authtype));
400eba
+    slapi_sdn_done(&op->o_sdn);
400eba
+    slapi_ch_free_string(&(op->o_authtype));
400eba
     if (dnlen <= 0 && typelen <= 0) {
400eba
         op->o_authtype = NULL;
400eba
     } else {
400eba
-	    slapi_sdn_set_dn_byval(&op->o_sdn,conn->c_dn);
400eba
+        slapi_sdn_set_dn_byval(&op->o_sdn,conn->c_dn);
400eba
         op->o_authtype = slapi_ch_strdup(conn->c_authtype);
400eba
         /* set the thread data bind dn index */
400eba
         slapi_td_set_dn(slapi_ch_strdup(conn->c_dn));
400eba
@@ -2103,14 +2103,14 @@ op_copy_identity(Connection *conn, Operation *op)
400eba
         op->o_ssf = conn->c_local_ssf;
400eba
     }
400eba
 
400eba
-    PR_Unlock( conn->c_mutex );
400eba
+    PR_ExitMonitor(conn->c_mutex);
400eba
 }
400eba
 
400eba
 /* Sets the SSL SSF in the connection struct. */
400eba
 static void
400eba
 connection_set_ssl_ssf(Connection *conn)
400eba
 {
400eba
-	PR_Lock( conn->c_mutex );
400eba
+	PR_EnterMonitor(conn->c_mutex);
400eba
 
400eba
 	if (conn->c_flags & CONN_FLAG_SSL) {
400eba
 		SSL_SecurityStatus(conn->c_prfd, NULL, NULL, NULL, &(conn->c_ssl_ssf), NULL, NULL);
400eba
@@ -2118,7 +2118,7 @@ connection_set_ssl_ssf(Connection *conn)
400eba
 		conn->c_ssl_ssf = 0;
400eba
 	}
400eba
 
400eba
-	PR_Unlock( conn->c_mutex );
400eba
+	PR_ExitMonitor(conn->c_mutex);
400eba
 }
400eba
 
400eba
 static int
400eba
@@ -2165,9 +2165,9 @@ log_ber_too_big_error(const Connection *conn, ber_len_t ber_len,
400eba
 void
400eba
 disconnect_server( Connection *conn, PRUint64 opconnid, int opid, PRErrorCode reason, PRInt32 error )
400eba
 {
400eba
-	PR_Lock( conn->c_mutex );
400eba
+	PR_EnterMonitor(conn->c_mutex);
400eba
 	disconnect_server_nomutex( conn, opconnid, opid, reason, error );
400eba
-	PR_Unlock( conn->c_mutex );
400eba
+	PR_ExitMonitor(conn->c_mutex);
400eba
 }
400eba
 
400eba
 static ps_wakeup_all_fn_ptr ps_wakeup_all_fn = NULL;
400eba
diff --git a/ldap/servers/slapd/conntable.c b/ldap/servers/slapd/conntable.c
400eba
index d5b9058..37da9a5 100644
400eba
--- a/ldap/servers/slapd/conntable.c
400eba
+++ b/ldap/servers/slapd/conntable.c
400eba
@@ -85,11 +85,11 @@ connection_table_abandon_all_operations(Connection_Table *ct)
400eba
 	int	i;
400eba
 	for ( i = 0; i < ct->size; i++ )
400eba
 	{
400eba
-		if ( ct->c[i].c_mutex != NULL )
400eba
+		if ( ct->c[i].c_mutex )
400eba
 		{
400eba
-			PR_Lock( ct->c[i].c_mutex );
400eba
+			PR_EnterMonitor(ct->c[i].c_mutex);
400eba
 			connection_abandon_operations( &ct->c[i] );
400eba
-			PR_Unlock( ct->c[i].c_mutex );
400eba
+			PR_ExitMonitor(ct->c[i].c_mutex);
400eba
 		}
400eba
 	}
400eba
 }
400eba
@@ -139,7 +139,7 @@ connection_table_get_connection(Connection_Table *ct, int sd)
400eba
 		if ( c->c_mutex == NULL )
400eba
 		{
400eba
 			PR_Lock( ct->table_mutex );
400eba
-			c->c_mutex = PR_NewLock();
400eba
+			c->c_mutex = PR_NewMonitor();
400eba
 			c->c_pdumutex = PR_NewLock();
400eba
 			PR_Unlock( ct->table_mutex );
400eba
 			if ( c->c_mutex == NULL || c->c_pdumutex == NULL )
400eba
@@ -360,7 +360,7 @@ connection_table_as_entry(Connection_Table *ct, Slapi_Entry *e)
400eba
 		/* Can't take c_mutex if holding table_mutex; temporarily unlock */ 
400eba
 		PR_Unlock( ct->table_mutex );
400eba
 
400eba
-		PR_Lock( ct->c[i].c_mutex );
400eba
+		PR_EnterMonitor(ct->c[i].c_mutex);
400eba
 		if ( ct->c[i].c_sd != SLAPD_INVALID_SOCKET )
400eba
 		{
400eba
 			char buf2[20];
400eba
@@ -420,7 +420,7 @@ connection_table_as_entry(Connection_Table *ct, Slapi_Entry *e)
400eba
 			attrlist_merge( &e->e_attrs, "connection", vals );
400eba
 			slapi_ch_free_string(&newbuf);
400eba
 		}
400eba
-		PR_Unlock( ct->c[i].c_mutex );
400eba
+		PR_ExitMonitor(ct->c[i].c_mutex);
400eba
 	}
400eba
 
400eba
 	PR_snprintf( buf, sizeof(buf), "%d", nconns );
400eba
@@ -458,14 +458,15 @@ void
400eba
 connection_table_dump_activity_to_errors_log(Connection_Table *ct)
400eba
 {
400eba
 	int i;
400eba
+
400eba
 	for ( i = 0; i < ct->size; i++ )
400eba
 	{
400eba
 		Connection *c= &(ct->c[i]);
400eba
-		if ( c->c_mutex != NULL )
400eba
+		if ( c->c_mutex )
400eba
 		{
400eba
 			/* Find the connection we are referring to */
400eba
 			int j= c->c_fdi;
400eba
-			PR_Lock( c->c_mutex );
400eba
+			PR_EnterMonitor(c->c_mutex);
400eba
 			if ( (c->c_sd != SLAPD_INVALID_SOCKET) && 
400eba
 			     (j >= 0) && (c->c_prfd == ct->fd[j].fd) )
400eba
 			{
400eba
@@ -475,7 +476,7 @@ connection_table_dump_activity_to_errors_log(Connection_Table *ct)
400eba
 					LDAPDebug( LDAP_DEBUG_CONNS,"activity on %d%s\n", i, r ? "r" : "",0 );
400eba
 				}
400eba
 			}
400eba
-			PR_Unlock( c->c_mutex );
400eba
+			PR_ExitMonitor(c->c_mutex);
400eba
 		}
400eba
 	}
400eba
 }
400eba
diff --git a/ldap/servers/slapd/daemon.c b/ldap/servers/slapd/daemon.c
400eba
index 5d70647..355f0fc 100644
400eba
--- a/ldap/servers/slapd/daemon.c
400eba
+++ b/ldap/servers/slapd/daemon.c
400eba
@@ -1612,7 +1612,7 @@ setup_pr_read_pds(Connection_Table *ct, PRFileDesc **n_tcps, PRFileDesc **s_tcps
400eba
 		}
400eba
 		else
400eba
 		{
400eba
-			PR_Lock( c->c_mutex );
400eba
+			PR_EnterMonitor(c->c_mutex);
400eba
 			if (c->c_flags & CONN_FLAG_CLOSING)
400eba
 			{
400eba
 				/* A worker thread has marked that this connection
400eba
@@ -1661,7 +1661,7 @@ setup_pr_read_pds(Connection_Table *ct, PRFileDesc **n_tcps, PRFileDesc **s_tcps
400eba
 					c->c_fdi = SLAPD_INVALID_SOCKET_INDEX;
400eba
 				}
400eba
 			}
400eba
-			PR_Unlock( c->c_mutex );
400eba
+			PR_ExitMonitor(c->c_mutex);
400eba
 		}
400eba
 		c = next;
400eba
 	}
400eba
@@ -1680,7 +1680,7 @@ handle_timeout( void )
400eba
 	time_t curtime = current_time();
400eba
 
400eba
 	if (0 == prevtime) {
400eba
-		prevtime = time (&housekeeping_fire_time);		
400eba
+		prevtime = time (&housekeeping_fire_time);
400eba
 	}
400eba
 
400eba
 	if ( difftime(curtime, prevtime) >= 
400eba
@@ -1740,7 +1740,7 @@ handle_pr_read_ready(Connection_Table *ct, PRIntn num_poll)
400eba
 	{
400eba
 		if ( c->c_mutex != NULL )
400eba
 		{
400eba
-			PR_Lock( c->c_mutex );
400eba
+			PR_EnterMonitor(c->c_mutex);
400eba
 			if ( connection_is_active_nolock (c) && c->c_gettingber == 0 )
400eba
 			{
400eba
 			    PRInt16 out_flags;
400eba
@@ -1797,7 +1797,7 @@ handle_pr_read_ready(Connection_Table *ct, PRIntn num_poll)
400eba
 								   SLAPD_DISCONNECT_IDLE_TIMEOUT, EAGAIN );
400eba
 				}
400eba
 			}
400eba
-			PR_Unlock( c->c_mutex );
400eba
+			PR_ExitMonitor(c->c_mutex);
400eba
 		}
400eba
 	}
400eba
 }
400eba
@@ -1843,12 +1843,12 @@ ns_handle_closure(struct ns_job_t *job)
400eba
 		return;
400eba
 	}
400eba
 #endif
400eba
-	PR_Lock(c->c_mutex);
400eba
+	PR_EnterMonitor(c->c_mutex);
400eba
 	connection_release_nolock_ext(c, 1); /* release ref acquired for event framework */
400eba
 	PR_ASSERT(c->c_ns_close_jobs == 1); /* should be exactly 1 active close job - this one */
400eba
 	c->c_ns_close_jobs--; /* this job is processing closure */
400eba
 	do_yield = ns_handle_closure_nomutex(c);
400eba
-	PR_Unlock(c->c_mutex);
400eba
+	PR_ExitMonitor(c->c_mutex);
400eba
 	ns_job_done(job);
400eba
 	if (do_yield) {
400eba
 		/* closure not done - another reference still outstanding */
400eba
@@ -1939,7 +1939,7 @@ ns_handle_pr_read_ready(struct ns_job_t *job)
400eba
 	}
400eba
 #endif
400eba
 
400eba
-	PR_Lock(c->c_mutex);
400eba
+	PR_EnterMonitor(c->c_mutex);
400eba
 	LDAPDebug2Args(LDAP_DEBUG_CONNS, "activity on conn %" NSPRIu64 " for fd=%d\n",
400eba
 		       c->c_connid, c->c_sd);
400eba
 	/* if we were called due to some i/o event, see what the state of the socket is */
400eba
@@ -1986,7 +1986,7 @@ ns_handle_pr_read_ready(struct ns_job_t *job)
400eba
 		LDAPDebug2Args(LDAP_DEBUG_CONNS, "queued conn %" NSPRIu64 " for fd=%d\n",
400eba
 			       c->c_connid, c->c_sd);
400eba
 	}
400eba
-	PR_Unlock(c->c_mutex);
400eba
+	PR_ExitMonitor(c->c_mutex);
400eba
 	ns_job_done(job);
400eba
 	return;
400eba
 }
400eba
@@ -2493,7 +2493,7 @@ handle_new_connection(Connection_Table *ct, int tcps, PRFileDesc *pr_acceptfd, i
400eba
 		PR_Close(pr_acceptfd);
400eba
 		return -1;
400eba
 	}
400eba
-	PR_Lock( conn->c_mutex );
400eba
+	PR_EnterMonitor(conn->c_mutex);
400eba
 
400eba
 	/*
400eba
 	 * Set the default idletimeout and the handle.  We'll update c_idletimeout
400eba
@@ -2592,7 +2592,7 @@ handle_new_connection(Connection_Table *ct, int tcps, PRFileDesc *pr_acceptfd, i
400eba
 		connection_table_move_connection_on_to_active_list(the_connection_table,conn);
400eba
 	}
400eba
 
400eba
-	PR_Unlock( conn->c_mutex );
400eba
+	PR_ExitMonitor(conn->c_mutex);
400eba
 
400eba
 	g_increment_current_conn_count();
400eba
 
400eba
diff --git a/ldap/servers/slapd/extendop.c b/ldap/servers/slapd/extendop.c
400eba
index 94036c6..8d0b8fb 100644
400eba
--- a/ldap/servers/slapd/extendop.c
400eba
+++ b/ldap/servers/slapd/extendop.c
400eba
@@ -61,7 +61,7 @@ static void extop_handle_import_start(Slapi_PBlock *pb, char *extoid,
400eba
         send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL, NULL, 0, NULL);
400eba
         return;
400eba
     }
400eba
-	suffix = slapi_sdn_get_dn(sdn);
400eba
+    suffix = slapi_sdn_get_dn(sdn);
400eba
     /*    be = slapi_be_select(sdn); */
400eba
     be = slapi_mapping_tree_find_backend_for_sdn(sdn);
400eba
     if (be == NULL || be == defbackend_get_backend()) {
400eba
@@ -135,10 +135,10 @@ static void extop_handle_import_start(Slapi_PBlock *pb, char *extoid,
400eba
     /* okay, the import is starting now -- save the backend in the
400eba
      * connection block & mark this connection as belonging to a bulk import
400eba
      */
400eba
-    PR_Lock(pb->pb_conn->c_mutex);
400eba
+    PR_EnterMonitor(pb->pb_conn->c_mutex);
400eba
     pb->pb_conn->c_flags |= CONN_FLAG_IMPORT;
400eba
     pb->pb_conn->c_bi_backend = be;
400eba
-    PR_Unlock(pb->pb_conn->c_mutex);
400eba
+    PR_ExitMonitor(pb->pb_conn->c_mutex);
400eba
 
400eba
     slapi_pblock_set(pb, SLAPI_EXT_OP_RET_OID, EXTOP_BULK_IMPORT_START_OID);
400eba
     bv.bv_val = NULL;
400eba
@@ -160,11 +160,11 @@ static void extop_handle_import_done(Slapi_PBlock *pb, char *extoid,
400eba
     struct berval bv;
400eba
     int ret;
400eba
 
400eba
-    PR_Lock(pb->pb_conn->c_mutex);
400eba
+    PR_EnterMonitor(pb->pb_conn->c_mutex);
400eba
     pb->pb_conn->c_flags &= ~CONN_FLAG_IMPORT;
400eba
     be = pb->pb_conn->c_bi_backend;
400eba
     pb->pb_conn->c_bi_backend = NULL;
400eba
-    PR_Unlock(pb->pb_conn->c_mutex);
400eba
+    PR_ExitMonitor(pb->pb_conn->c_mutex);
400eba
 
400eba
     if ((be == NULL) || (be->be_wire_import == NULL)) {
400eba
         /* can this even happen? */
400eba
diff --git a/ldap/servers/slapd/operation.c b/ldap/servers/slapd/operation.c
400eba
index 869298b..6c95552 100644
400eba
--- a/ldap/servers/slapd/operation.c
400eba
+++ b/ldap/servers/slapd/operation.c
400eba
@@ -570,7 +570,7 @@ int slapi_connection_acquire(Slapi_Connection *conn)
400eba
 {
400eba
     int rc;
400eba
 
400eba
-    PR_Lock(conn->c_mutex);
400eba
+    PR_EnterMonitor(conn->c_mutex);
400eba
     /* rc = connection_acquire_nolock(conn); */
400eba
     /* connection in the closing state can't be acquired */
400eba
     if (conn->c_flags & CONN_FLAG_CLOSING)
400eba
@@ -586,7 +586,7 @@ int slapi_connection_acquire(Slapi_Connection *conn)
400eba
         conn->c_refcnt++;
400eba
         rc = 0;
400eba
     }
400eba
-    PR_Unlock(conn->c_mutex);
400eba
+    PR_ExitMonitor(conn->c_mutex);
400eba
     return(rc);
400eba
 }
400eba
 
400eba
@@ -596,7 +596,7 @@ slapi_connection_remove_operation( Slapi_PBlock *pb, Slapi_Connection *conn, Sla
400eba
 	int rc = 0;
400eba
 	Slapi_Operation **olist= &conn->c_ops;
400eba
 	Slapi_Operation **tmp;
400eba
-	PR_Lock( conn->c_mutex );
400eba
+	PR_EnterMonitor(conn->c_mutex);
400eba
 	/* connection_remove_operation_ext(pb, conn,op); */
400eba
 	for ( tmp = olist; *tmp != NULL && *tmp != op; tmp = &(*tmp)->o_next )
400eba
 		;	/* NULL */
400eba
@@ -614,15 +614,15 @@ slapi_connection_remove_operation( Slapi_PBlock *pb, Slapi_Connection *conn, Sla
400eba
 	if (release) {
400eba
 		/* connection_release_nolock(conn); */
400eba
 		if (conn->c_refcnt <= 0) {
400eba
-        		slapi_log_error(SLAPI_LOG_FATAL, "connection",
400eba
-		                "conn=%" NSPRIu64 " fd=%d Attempt to release connection that is not acquired\n",
400eba
-		                conn->c_connid, conn->c_sd);
400eba
-        		rc = -1;
400eba
+			slapi_log_error(SLAPI_LOG_FATAL, "connection",
400eba
+			                "conn=%" NSPRIu64 " fd=%d Attempt to release connection that is not acquired\n",
400eba
+			                conn->c_connid, conn->c_sd);
400eba
+			rc = -1;
400eba
 		} else {
400eba
-        		conn->c_refcnt--;
400eba
+			conn->c_refcnt--;
400eba
 			rc = 0;
400eba
 		}
400eba
 	}
400eba
-	PR_Unlock( conn->c_mutex );
400eba
+	PR_ExitMonitor(conn->c_mutex);
400eba
 	return (rc);
400eba
 }
400eba
diff --git a/ldap/servers/slapd/opshared.c b/ldap/servers/slapd/opshared.c
400eba
index 5cafc3c..e76ca0f 100644
400eba
--- a/ldap/servers/slapd/opshared.c
400eba
+++ b/ldap/servers/slapd/opshared.c
400eba
@@ -675,7 +675,7 @@ op_shared_search (Slapi_PBlock *pb, int send_result)
400eba
        * In async paged result case, the search result might be released
400eba
        * by other theads.  We need to double check it in the locked region.
400eba
        */
400eba
-      PR_Lock(pb->pb_conn->c_mutex);
400eba
+      PR_EnterMonitor(pb->pb_conn->c_mutex);
400eba
       pr_search_result = pagedresults_get_search_result(pb->pb_conn, operation, 1/*locked*/, pr_idx);
400eba
       if (pr_search_result) {
400eba
         if (pagedresults_is_abandoned_or_notavailable(pb->pb_conn, 1/*locked*/, pr_idx)) {
400eba
@@ -683,7 +683,7 @@ op_shared_search (Slapi_PBlock *pb, int send_result)
400eba
           /* Previous operation was abandoned and the simplepaged object is not in use. */
400eba
           send_ldap_result(pb, 0, NULL, "Simple Paged Results Search abandoned", 0, NULL);
400eba
           rc = LDAP_SUCCESS;
400eba
-          PR_Unlock(pb->pb_conn->c_mutex);
400eba
+          PR_ExitMonitor(pb->pb_conn->c_mutex);
400eba
           goto free_and_return;
400eba
         } else {
400eba
           slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_SET, pr_search_result );
400eba
@@ -692,7 +692,7 @@ op_shared_search (Slapi_PBlock *pb, int send_result)
400eba
           /* search result could be reset in the backend/dse */
400eba
           slapi_pblock_get(pb, SLAPI_SEARCH_RESULT_SET, &sr);
400eba
           pagedresults_set_search_result(pb->pb_conn, operation, sr, 1/*locked*/, pr_idx);
400eba
-          PR_Unlock(pb->pb_conn->c_mutex);
400eba
+          PR_ExitMonitor(pb->pb_conn->c_mutex);
400eba
         }
400eba
       } else {
400eba
         pr_stat = PAGEDRESULTS_SEARCH_END;
400eba
@@ -826,10 +826,10 @@ op_shared_search (Slapi_PBlock *pb, int send_result)
400eba
         /* PAGED RESULTS */
400eba
         if (op_is_pagedresults(operation)) {
400eba
             /* cleanup the slot */
400eba
-            PR_Lock(pb->pb_conn->c_mutex);
400eba
+            PR_EnterMonitor(pb->pb_conn->c_mutex);
400eba
             pagedresults_set_search_result(pb->pb_conn, operation, NULL, 1, pr_idx);
400eba
             rc = pagedresults_set_current_be(pb->pb_conn, NULL, pr_idx, 1);
400eba
-            PR_Unlock(pb->pb_conn->c_mutex);
400eba
+            PR_ExitMonitor(pb->pb_conn->c_mutex);
400eba
         }
400eba
         if (1 == flag_no_such_object) {
400eba
             break;
400eba
@@ -871,11 +871,11 @@ op_shared_search (Slapi_PBlock *pb, int send_result)
400eba
             slapi_pblock_get(pb, SLAPI_SEARCH_RESULT_SET, &sr);
400eba
             if (PAGEDRESULTS_SEARCH_END == pr_stat) {
400eba
               /* no more entries, but at least another backend */
400eba
-              PR_Lock(pb->pb_conn->c_mutex);
400eba
+              PR_EnterMonitor(pb->pb_conn->c_mutex);
400eba
               pagedresults_set_search_result(pb->pb_conn, operation, NULL, 1, pr_idx);
400eba
               be->be_search_results_release(&sr);
400eba
               rc = pagedresults_set_current_be(pb->pb_conn, next_be, pr_idx, 1);
400eba
-              PR_Unlock(pb->pb_conn->c_mutex);
400eba
+              PR_ExitMonitor(pb->pb_conn->c_mutex);
400eba
               if (NULL == next_be) {
400eba
                   /* no more entries && no more backends */
400eba
                   curr_search_count = -1;
400eba
@@ -900,9 +900,9 @@ op_shared_search (Slapi_PBlock *pb, int send_result)
400eba
             next_be = NULL; /* to break the loop */
400eba
             if (operation->o_status & SLAPI_OP_STATUS_ABANDONED) {
400eba
                 /* It turned out this search was abandoned. */
400eba
-                PR_Lock(pb->pb_conn->c_mutex);
400eba
+                PR_EnterMonitor(pb->pb_conn->c_mutex);
400eba
                 pagedresults_free_one_msgid_nolock( pb->pb_conn, operation->o_msgid);
400eba
-                PR_Unlock(pb->pb_conn->c_mutex);
400eba
+                PR_ExitMonitor(pb->pb_conn->c_mutex);
400eba
                 /* paged-results-request was abandoned; making an empty cookie. */
400eba
                 pagedresults_set_response_control(pb, 0, estimate, -1, pr_idx);
400eba
                 send_ldap_result(pb, 0, NULL, "Simple Paged Results Search abandoned", 0, NULL);
400eba
diff --git a/ldap/servers/slapd/pagedresults.c b/ldap/servers/slapd/pagedresults.c
400eba
index 4458cfb..d394dab 100644
400eba
--- a/ldap/servers/slapd/pagedresults.c
400eba
+++ b/ldap/servers/slapd/pagedresults.c
400eba
@@ -98,7 +98,7 @@ pagedresults_parse_control_value( Slapi_PBlock *pb,
400eba
         return LDAP_UNWILLING_TO_PERFORM;
400eba
     }
400eba
 
400eba
-    PR_Lock(conn->c_mutex);
400eba
+    PR_EnterMonitor(conn->c_mutex);
400eba
     /* the ber encoding is no longer needed */
400eba
     ber_free(ber, 1);
400eba
     if ( cookie.bv_len <= 0 ) {
400eba
@@ -204,7 +204,7 @@ bail:
400eba
             }
400eba
         }
400eba
     }
400eba
-    PR_Unlock(conn->c_mutex);
400eba
+    PR_ExitMonitor(conn->c_mutex);
400eba
 
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "<-- pagedresults_parse_control_value: idx %d\n", *index);
400eba
@@ -301,7 +301,7 @@ pagedresults_free_one( Connection *conn, Operation *op, int index )
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "--> pagedresults_free_one: idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (conn->c_pagedresults.prl_count <= 0) {
400eba
             LDAPDebug2Args(LDAP_DEBUG_TRACE, "pagedresults_free_one: "
400eba
                            "conn=%d paged requests list count is %d\n",
400eba
@@ -312,7 +312,7 @@ pagedresults_free_one( Connection *conn, Operation *op, int index )
400eba
             conn->c_pagedresults.prl_count--;
400eba
             rc = 0;
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
 
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE, "<-- pagedresults_free_one: %d\n", rc);
400eba
@@ -364,11 +364,11 @@ pagedresults_get_current_be(Connection *conn, int index)
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "--> pagedresults_get_current_be: idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             be = conn->c_pagedresults.prl_list[index].pr_current_be;
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "<-- pagedresults_get_current_be: %p\n", be);
400eba
@@ -382,12 +382,12 @@ pagedresults_set_current_be(Connection *conn, Slapi_Backend *be, int index, int
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "--> pagedresults_set_current_be: idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        if (!nolock) PR_Lock(conn->c_mutex);
400eba
+        if (!nolock) PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             conn->c_pagedresults.prl_list[index].pr_current_be = be;
400eba
         }
400eba
         rc = 0;
400eba
-        if (!nolock) PR_Unlock(conn->c_mutex);
400eba
+        if (!nolock) PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "<-- pagedresults_set_current_be: %d\n", rc);
400eba
@@ -406,13 +406,13 @@ pagedresults_get_search_result(Connection *conn, Operation *op, int locked, int
400eba
                    locked?"locked":"not locked", index);
400eba
     if (conn && (index > -1)) {
400eba
         if (!locked) {
400eba
-            PR_Lock(conn->c_mutex);
400eba
+            PR_EnterMonitor(conn->c_mutex);
400eba
         }
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             sr = conn->c_pagedresults.prl_list[index].pr_search_result_set;
400eba
         }
400eba
         if (!locked) {
400eba
-            PR_Unlock(conn->c_mutex);
400eba
+            PR_ExitMonitor(conn->c_mutex);
400eba
         }
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
@@ -431,7 +431,7 @@ pagedresults_set_search_result(Connection *conn, Operation *op, void *sr, int lo
400eba
                    "--> pagedresults_set_search_result: idx=%d, sr=%p\n",
400eba
                    index, sr);
400eba
     if (conn && (index > -1)) {
400eba
-        if (!locked) PR_Lock(conn->c_mutex);
400eba
+        if (!locked) PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             PagedResults *prp = conn->c_pagedresults.prl_list + index;
400eba
             if (!(prp->pr_flags & CONN_FLAG_PAGEDRESULTS_ABANDONED) || !sr) {
400eba
@@ -440,7 +440,7 @@ pagedresults_set_search_result(Connection *conn, Operation *op, void *sr, int lo
400eba
             }
400eba
             rc = 0;
400eba
         }
400eba
-        if (!locked) PR_Unlock(conn->c_mutex);
400eba
+        if (!locked) PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "<-- pagedresults_set_search_result: %d\n", rc);
400eba
@@ -457,11 +457,11 @@ pagedresults_get_search_result_count(Connection *conn, Operation *op, int index)
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "--> pagedresults_get_search_result_count: idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             count = conn->c_pagedresults.prl_list[index].pr_search_result_count;
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "<-- pagedresults_get_search_result_count: %d\n", count);
400eba
@@ -479,11 +479,11 @@ pagedresults_set_search_result_count(Connection *conn, Operation *op,
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "--> pagedresults_set_search_result_count: idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             conn->c_pagedresults.prl_list[index].pr_search_result_count = count;
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
         rc = 0;
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
@@ -504,11 +504,11 @@ pagedresults_get_search_result_set_size_estimate(Connection *conn,
400eba
                   "--> pagedresults_get_search_result_set_size_estimate: "
400eba
                   "idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             count = conn->c_pagedresults.prl_list[index].pr_search_result_set_size_estimate;
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "<-- pagedresults_get_search_result_set_size_estimate: %d\n",
400eba
@@ -529,11 +529,11 @@ pagedresults_set_search_result_set_size_estimate(Connection *conn,
400eba
                   "--> pagedresults_set_search_result_set_size_estimate: "
400eba
                   "idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             conn->c_pagedresults.prl_list[index].pr_search_result_set_size_estimate = count;
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
         rc = 0;
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
@@ -552,11 +552,11 @@ pagedresults_get_with_sort(Connection *conn, Operation *op, int index)
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "--> pagedresults_get_with_sort: idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             flags = conn->c_pagedresults.prl_list[index].pr_flags&CONN_FLAG_PAGEDRESULTS_WITH_SORT;
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "<-- pagedresults_get_with_sort: %p\n", flags);
400eba
@@ -574,14 +574,14 @@ pagedresults_set_with_sort(Connection *conn, Operation *op,
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "--> pagedresults_set_with_sort: idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             if (flags & OP_FLAG_SERVER_SIDE_SORTING) {
400eba
                 conn->c_pagedresults.prl_list[index].pr_flags |=
400eba
                                                CONN_FLAG_PAGEDRESULTS_WITH_SORT;
400eba
             }
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
         rc = 0;
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE, "<-- pagedresults_set_with_sort: %d\n", rc);
400eba
@@ -598,11 +598,11 @@ pagedresults_get_unindexed(Connection *conn, Operation *op, int index)
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "--> pagedresults_get_unindexed: idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             flags = conn->c_pagedresults.prl_list[index].pr_flags&CONN_FLAG_PAGEDRESULTS_UNINDEXED;
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "<-- pagedresults_get_unindexed: %p\n", flags);
400eba
@@ -619,12 +619,12 @@ pagedresults_set_unindexed(Connection *conn, Operation *op, int index)
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "--> pagedresults_set_unindexed: idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             conn->c_pagedresults.prl_list[index].pr_flags |=
400eba
                                                CONN_FLAG_PAGEDRESULTS_UNINDEXED;
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
         rc = 0;
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
@@ -642,11 +642,11 @@ pagedresults_get_sort_result_code(Connection *conn, Operation *op, int index)
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "--> pagedresults_get_sort_result_code: idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             code = conn->c_pagedresults.prl_list[index].pr_sort_result_code;
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "<-- pagedresults_get_sort_result_code: %d\n", code);
400eba
@@ -664,11 +664,11 @@ pagedresults_set_sort_result_code(Connection *conn, Operation *op,
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "--> pagedresults_set_sort_result_code: idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             conn->c_pagedresults.prl_list[index].pr_sort_result_code = code;
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
         rc = 0;
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
@@ -687,11 +687,11 @@ pagedresults_set_timelimit(Connection *conn, Operation *op,
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "--> pagedresults_set_timelimit: idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             conn->c_pagedresults.prl_list[index].pr_timelimit = timelimit;
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
         rc = 0;
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE, "<-- pagedresults_set_timelimit: %d\n", rc);
400eba
@@ -749,7 +749,7 @@ pagedresults_cleanup(Connection *conn, int needlock)
400eba
     }
400eba
 
400eba
     if (needlock) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
     }
400eba
     for (i = 0; conn->c_pagedresults.prl_list &&
400eba
                 i < conn->c_pagedresults.prl_maxlen; i++) {
400eba
@@ -767,7 +767,7 @@ pagedresults_cleanup(Connection *conn, int needlock)
400eba
     }
400eba
     conn->c_pagedresults.prl_count = 0;
400eba
     if (needlock) {
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE, "<-- pagedresults_cleanup: %d\n", rc);
400eba
     return rc;
400eba
@@ -794,7 +794,7 @@ pagedresults_cleanup_all(Connection *conn, int needlock)
400eba
     }
400eba
 
400eba
     if (needlock) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
     }
400eba
     for (i = 0; conn->c_pagedresults.prl_list &&
400eba
                 i < conn->c_pagedresults.prl_maxlen; i++) {
400eba
@@ -813,7 +813,7 @@ pagedresults_cleanup_all(Connection *conn, int needlock)
400eba
     conn->c_pagedresults.prl_maxlen = 0;
400eba
     conn->c_pagedresults.prl_count = 0;
400eba
     if (needlock) {
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE, "<-- pagedresults_cleanup_all: %d\n", rc);
400eba
     return rc;
400eba
@@ -832,7 +832,7 @@ pagedresults_check_or_set_processing(Connection *conn, int index)
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "--> pagedresults_check_or_set_processing\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             ret = (conn->c_pagedresults.prl_list[index].pr_flags &
400eba
                    CONN_FLAG_PAGEDRESULTS_PROCESSING);
400eba
@@ -840,7 +840,7 @@ pagedresults_check_or_set_processing(Connection *conn, int index)
400eba
             conn->c_pagedresults.prl_list[index].pr_flags |=
400eba
                                               CONN_FLAG_PAGEDRESULTS_PROCESSING;
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "<-- pagedresults_check_or_set_processing: %d\n", ret);
400eba
@@ -859,7 +859,7 @@ pagedresults_reset_processing(Connection *conn, int index)
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "--> pagedresults_reset_processing: idx=%d\n", index);
400eba
     if (conn && (index > -1)) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             ret = (conn->c_pagedresults.prl_list[index].pr_flags &
400eba
                    CONN_FLAG_PAGEDRESULTS_PROCESSING);
400eba
@@ -867,7 +867,7 @@ pagedresults_reset_processing(Connection *conn, int index)
400eba
             conn->c_pagedresults.prl_list[index].pr_flags &=
400eba
                                              ~CONN_FLAG_PAGEDRESULTS_PROCESSING;
400eba
         }
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "<-- pagedresults_reset_processing: %d\n", ret);
400eba
@@ -981,9 +981,9 @@ pagedresults_lock( Connection *conn, int index )
400eba
     if (!conn || (index < 0) || (index >= conn->c_pagedresults.prl_maxlen)) {
400eba
         return;
400eba
     }
400eba
-    PR_Lock(conn->c_mutex);
400eba
+    PR_EnterMonitor(conn->c_mutex);
400eba
     prp = conn->c_pagedresults.prl_list + index;
400eba
-    PR_Unlock(conn->c_mutex);
400eba
+    PR_ExitMonitor(conn->c_mutex);
400eba
     if (prp->pr_mutex) {
400eba
         PR_Lock(prp->pr_mutex);
400eba
     }
400eba
@@ -997,9 +997,9 @@ pagedresults_unlock( Connection *conn, int index )
400eba
     if (!conn || (index < 0) || (index >= conn->c_pagedresults.prl_maxlen)) {
400eba
         return;
400eba
     }
400eba
-    PR_Lock(conn->c_mutex);
400eba
+    PR_EnterMonitor(conn->c_mutex);
400eba
     prp = conn->c_pagedresults.prl_list + index;
400eba
-    PR_Unlock(conn->c_mutex);
400eba
+    PR_ExitMonitor(conn->c_mutex);
400eba
     if (prp->pr_mutex) {
400eba
         PR_Unlock(prp->pr_mutex);
400eba
     }
400eba
@@ -1014,11 +1014,11 @@ pagedresults_is_abandoned_or_notavailable(Connection *conn, int locked, int inde
400eba
         return 1; /* not abandoned, but do not want to proceed paged results op. */
400eba
     }
400eba
     if (!locked) {
400eba
-        PR_Lock(conn->c_mutex);
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
     }
400eba
     prp = conn->c_pagedresults.prl_list + index;
400eba
     if (!locked) {
400eba
-        PR_Unlock(conn->c_mutex);
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
     return prp->pr_flags & CONN_FLAG_PAGEDRESULTS_ABANDONED;
400eba
 }
400eba
@@ -1042,12 +1042,12 @@ pagedresults_set_search_result_pb(Slapi_PBlock *pb, void *sr, int locked)
400eba
     LDAPDebug2Args(LDAP_DEBUG_TRACE,
400eba
                    "--> pagedresults_set_search_result_pb: idx=%d, sr=%p\n", index, sr);
400eba
     if (conn && (index > -1)) {
400eba
-        if (!locked) PR_Lock(conn->c_mutex);
400eba
+        if (!locked) PR_EnterMonitor(conn->c_mutex);
400eba
         if (index < conn->c_pagedresults.prl_maxlen) {
400eba
             conn->c_pagedresults.prl_list[index].pr_search_result_set = sr;
400eba
             rc = 0;
400eba
         }
400eba
-        if (!locked) PR_Unlock(conn->c_mutex);
400eba
+        if (!locked) PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
     LDAPDebug1Arg(LDAP_DEBUG_TRACE,
400eba
                   "<-- pagedresults_set_search_result_pb: %d\n", rc);
400eba
diff --git a/ldap/servers/slapd/pblock.c b/ldap/servers/slapd/pblock.c
400eba
index bf57a33..d373d99 100644
400eba
--- a/ldap/servers/slapd/pblock.c
400eba
+++ b/ldap/servers/slapd/pblock.c
400eba
@@ -117,7 +117,7 @@ if ( PBLOCK ->pb_plugin->plg_type != TYPE) return( -1 )
400eba
 int
400eba
 slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 {
400eba
-    char *authtype;
400eba
+	char *authtype;
400eba
 	Slapi_Backend		*be;
400eba
 
400eba
 	PR_ASSERT( NULL != pblock );
400eba
@@ -174,10 +174,10 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 		          "Connection is NULL and hence cannot access SLAPI_CONN_DN \n", 0, 0, 0 );
400eba
 			return (-1);
400eba
 		}
400eba
-		PR_Lock( pblock->pb_conn->c_mutex );
400eba
+		PR_EnterMonitor(pblock->pb_conn->c_mutex);
400eba
 		(*(char **)value) = (NULL == pblock->pb_conn->c_dn ? NULL :
400eba
 		    slapi_ch_strdup( pblock->pb_conn->c_dn ));
400eba
-		PR_Unlock( pblock->pb_conn->c_mutex );
400eba
+		PR_ExitMonitor(pblock->pb_conn->c_mutex);
400eba
 		break;
400eba
 	case SLAPI_CONN_AUTHTYPE:/* deprecated */
400eba
 		if (pblock->pb_conn == NULL) {
400eba
@@ -185,9 +185,9 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 		          "Connection is NULL and hence cannot access SLAPI_CONN_AUTHTYPE \n", 0, 0, 0 );
400eba
 			return (-1);
400eba
 		}
400eba
-		PR_Lock( pblock->pb_conn->c_mutex );
400eba
-                authtype = pblock->pb_conn->c_authtype;
400eba
-		PR_Unlock( pblock->pb_conn->c_mutex );
400eba
+		PR_EnterMonitor(pblock->pb_conn->c_mutex);
400eba
+		authtype = pblock->pb_conn->c_authtype;
400eba
+		PR_ExitMonitor(pblock->pb_conn->c_mutex);
400eba
                 if (authtype == NULL) {
400eba
                     (*(char **)value) = NULL;
400eba
                 } else if (strcasecmp(authtype, SLAPD_AUTH_NONE) == 0) {
400eba
@@ -212,10 +212,10 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 		          "Connection is NULL and hence cannot access SLAPI_CONN_AUTHMETHOD \n", 0, 0, 0 );
400eba
 			return (-1);
400eba
 		}
400eba
-		PR_Lock( pblock->pb_conn->c_mutex );
400eba
+		PR_EnterMonitor(pblock->pb_conn->c_mutex);
400eba
 		(*(char **)value) = pblock->pb_conn->c_authtype ?
400eba
                     slapi_ch_strdup(pblock->pb_conn->c_authtype) : NULL;
400eba
-		PR_Unlock( pblock->pb_conn->c_mutex );
400eba
+		PR_ExitMonitor(pblock->pb_conn->c_mutex);
400eba
 		break;
400eba
 	case SLAPI_CONN_CLIENTNETADDR:
400eba
 		if (pblock->pb_conn == NULL)
400eba
@@ -223,14 +223,14 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 			memset( value, 0, sizeof( PRNetAddr ));
400eba
 			break;
400eba
 		}
400eba
-		PR_Lock( pblock->pb_conn->c_mutex );
400eba
+		PR_EnterMonitor(pblock->pb_conn->c_mutex);
400eba
 		if ( pblock->pb_conn->cin_addr == NULL ) {
400eba
 			memset( value, 0, sizeof( PRNetAddr ));
400eba
 		} else {
400eba
 			(*(PRNetAddr *)value) =
400eba
 			    *(pblock->pb_conn->cin_addr);
400eba
 		}
400eba
-		PR_Unlock( pblock->pb_conn->c_mutex );
400eba
+		PR_ExitMonitor(pblock->pb_conn->c_mutex);
400eba
 		break;
400eba
 	case SLAPI_CONN_SERVERNETADDR:
400eba
 		if (pblock->pb_conn == NULL)
400eba
@@ -238,14 +238,14 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 			memset( value, 0, sizeof( PRNetAddr ));
400eba
 			break;
400eba
 		}
400eba
-		PR_Lock( pblock->pb_conn->c_mutex );
400eba
+		PR_EnterMonitor(pblock->pb_conn->c_mutex);
400eba
 		if ( pblock->pb_conn->cin_destaddr == NULL ) {
400eba
 			memset( value, 0, sizeof( PRNetAddr ));
400eba
 		} else {
400eba
 			(*(PRNetAddr *)value) =
400eba
 				*(pblock->pb_conn->cin_destaddr);
400eba
 		}
400eba
-		PR_Unlock( pblock->pb_conn->c_mutex );
400eba
+		PR_ExitMonitor(pblock->pb_conn->c_mutex);
400eba
 		break;
400eba
 	case SLAPI_CONN_CLIENTIP:
400eba
 		if (pblock->pb_conn == NULL)
400eba
@@ -253,7 +253,7 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 			memset( value, 0, sizeof( struct in_addr ));
400eba
 			break;
400eba
 		}
400eba
-		PR_Lock( pblock->pb_conn->c_mutex );
400eba
+		PR_EnterMonitor(pblock->pb_conn->c_mutex);
400eba
 		if ( pblock->pb_conn->cin_addr == NULL ) {
400eba
 			memset( value, 0, sizeof( struct in_addr ));
400eba
 		} else {
400eba
@@ -268,7 +268,7 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 				memset( value, 0, sizeof( struct in_addr ));
400eba
 			}
400eba
 		}
400eba
-		PR_Unlock( pblock->pb_conn->c_mutex );
400eba
+		PR_ExitMonitor(pblock->pb_conn->c_mutex);
400eba
 		break;
400eba
 	case SLAPI_CONN_SERVERIP:
400eba
 		if (pblock->pb_conn == NULL)
400eba
@@ -276,7 +276,7 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 			memset( value, 0, sizeof( struct in_addr ));
400eba
 			break;
400eba
 		}
400eba
-		PR_Lock( pblock->pb_conn->c_mutex );
400eba
+		PR_EnterMonitor(pblock->pb_conn->c_mutex);
400eba
 		if ( pblock->pb_conn->cin_destaddr == NULL ) {
400eba
 			memset( value, 0, sizeof( PRNetAddr ));
400eba
 		} else {
400eba
@@ -292,7 +292,7 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 			}
400eba
 
400eba
 		}
400eba
-		PR_Unlock( pblock->pb_conn->c_mutex );
400eba
+		PR_ExitMonitor(pblock->pb_conn->c_mutex);
400eba
 		break;
400eba
 	case SLAPI_CONN_IS_REPLICATION_SESSION:
400eba
 		if (pblock->pb_conn == NULL) {
400eba
@@ -300,9 +300,9 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 		          "Connection is NULL and hence cannot access SLAPI_CONN_IS_REPLICATION_SESSION \n", 0, 0, 0 );
400eba
 			return (-1);
400eba
 		}
400eba
-		PR_Lock( pblock->pb_conn->c_mutex );
400eba
+		PR_EnterMonitor(pblock->pb_conn->c_mutex);
400eba
 		(*(int *)value) = pblock->pb_conn->c_isreplication_session;
400eba
-		PR_Unlock( pblock->pb_conn->c_mutex );
400eba
+		PR_ExitMonitor(pblock->pb_conn->c_mutex);
400eba
 		break;
400eba
 	case SLAPI_CONN_IS_SSL_SESSION:
400eba
 		if (pblock->pb_conn == NULL) {
400eba
@@ -310,9 +310,9 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 		          "Connection is NULL and hence cannot access SLAPI_CONN_IS_SSL_SESSION \n", 0, 0, 0 );
400eba
 			return (-1);
400eba
 		}
400eba
-		PR_Lock( pblock->pb_conn->c_mutex );
400eba
+		PR_EnterMonitor(pblock->pb_conn->c_mutex);
400eba
 		(*(int *)value) = pblock->pb_conn->c_flags & CONN_FLAG_SSL;
400eba
-		PR_Unlock( pblock->pb_conn->c_mutex );
400eba
+		PR_ExitMonitor(pblock->pb_conn->c_mutex);
400eba
 		break;
400eba
 	case SLAPI_CONN_SASL_SSF:
400eba
 		if (pblock->pb_conn == NULL) {
400eba
@@ -320,9 +320,9 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 			  "Connection is NULL and hence cannot access SLAPI_CONN_SASL_SSF \n", 0, 0, 0 );
400eba
 			return (-1);
400eba
 		}
400eba
-		PR_Lock( pblock->pb_conn->c_mutex );
400eba
+		PR_EnterMonitor(pblock->pb_conn->c_mutex);
400eba
 		(*(int *)value) = pblock->pb_conn->c_sasl_ssf;
400eba
-		PR_Unlock( pblock->pb_conn->c_mutex );
400eba
+		PR_ExitMonitor(pblock->pb_conn->c_mutex);
400eba
 		break;
400eba
 	case SLAPI_CONN_SSL_SSF:
400eba
 		if (pblock->pb_conn == NULL) {
400eba
@@ -330,9 +330,9 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 			  "Connection is NULL and hence cannot access SLAPI_CONN_SSL_SSF \n", 0, 0, 0 );
400eba
 			return (-1);
400eba
 		}
400eba
-		PR_Lock( pblock->pb_conn->c_mutex );
400eba
+		PR_EnterMonitor(pblock->pb_conn->c_mutex);
400eba
 		(*(int *)value) = pblock->pb_conn->c_ssl_ssf;
400eba
-		PR_Unlock( pblock->pb_conn->c_mutex );
400eba
+		PR_ExitMonitor(pblock->pb_conn->c_mutex);
400eba
 		break;
400eba
 	case SLAPI_CONN_LOCAL_SSF:
400eba
 		if (pblock->pb_conn == NULL) {
400eba
@@ -340,9 +340,9 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 			    "Connection is NULL and hence cannot access SLAPI_CONN_LOCAL_SSF \n", 0, 0, 0 );
400eba
 			return (-1);
400eba
 		}
400eba
-		PR_Lock( pblock->pb_conn->c_mutex );
400eba
+		PR_EnterMonitor(pblock->pb_conn->c_mutex);
400eba
 		(*(int *)value) = pblock->pb_conn->c_local_ssf;
400eba
-		PR_Unlock( pblock->pb_conn->c_mutex );
400eba
+		PR_ExitMonitor(pblock->pb_conn->c_mutex);
400eba
 		break;
400eba
 	case SLAPI_CONN_CERT:
400eba
 		if (pblock->pb_conn == NULL) {
400eba
@@ -1953,7 +1953,7 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
400eba
 int
400eba
 slapi_pblock_set( Slapi_PBlock *pblock, int arg, void *value )
400eba
 {
400eba
-    char *authtype;
400eba
+	char *authtype;
400eba
 
400eba
 	PR_ASSERT( NULL != pblock );
400eba
 
400eba
@@ -2020,10 +2020,10 @@ slapi_pblock_set( Slapi_PBlock *pblock, int arg, void *value )
400eba
 		          "Connection is NULL and hence cannot access SLAPI_CONN_AUTHMETHOD \n", 0, 0, 0 );
400eba
 			return (-1);
400eba
 		}
400eba
-		PR_Lock( pblock->pb_conn->c_mutex );
400eba
-                slapi_ch_free((void**)&pblock->pb_conn->c_authtype);
400eba
+		PR_EnterMonitor(pblock->pb_conn->c_mutex);
400eba
+		slapi_ch_free((void**)&pblock->pb_conn->c_authtype);
400eba
 		pblock->pb_conn->c_authtype = slapi_ch_strdup((char *) value);
400eba
-		PR_Unlock( pblock->pb_conn->c_mutex );
400eba
+		PR_ExitMonitor(pblock->pb_conn->c_mutex);
400eba
 		break;
400eba
 	case SLAPI_CONN_IS_REPLICATION_SESSION:
400eba
 		if (pblock->pb_conn == NULL) {
400eba
@@ -2031,9 +2031,9 @@ slapi_pblock_set( Slapi_PBlock *pblock, int arg, void *value )
400eba
 		          "Connection is NULL and hence cannot access SLAPI_CONN_IS_REPLICATION_SESSION \n", 0, 0, 0 );
400eba
 			return (-1);
400eba
 		}
400eba
-		PR_Lock( pblock->pb_conn->c_mutex );
400eba
+		PR_EnterMonitor(pblock->pb_conn->c_mutex);
400eba
 		pblock->pb_conn->c_isreplication_session = *((int *) value);
400eba
-		PR_Unlock( pblock->pb_conn->c_mutex );
400eba
+		PR_ExitMonitor(pblock->pb_conn->c_mutex);
400eba
 		break;
400eba
 
400eba
 	/* stuff related to config file processing */
400eba
@@ -3571,7 +3571,7 @@ bind_credentials_clear( Connection *conn, PRBool lock_conn,
400eba
 		PRBool clear_externalcreds )
400eba
 {
400eba
     if ( lock_conn ) {
400eba
-        PR_Lock( conn->c_mutex );
400eba
+        PR_EnterMonitor(conn->c_mutex);
400eba
     }
400eba
 
400eba
     if ( conn->c_dn != NULL ) {		/* a non-anonymous bind has occurred */
400eba
@@ -3597,7 +3597,7 @@ bind_credentials_clear( Connection *conn, PRBool lock_conn,
400eba
     }
400eba
 
400eba
     if ( lock_conn ) {
400eba
-        PR_Unlock( conn->c_mutex );
400eba
+        PR_ExitMonitor(conn->c_mutex);
400eba
     }
400eba
 
400eba
 }
400eba
@@ -3653,10 +3653,10 @@ void
400eba
 bind_credentials_set( Connection *conn, char *authtype, char *normdn,
400eba
 		char *extauthtype, char *externaldn, CERTCertificate *clientcert, Slapi_Entry * bind_target_entry )
400eba
 {
400eba
-	PR_Lock( conn->c_mutex );
400eba
+	PR_EnterMonitor(conn->c_mutex);
400eba
 	bind_credentials_set_nolock(conn, authtype, normdn,
400eba
 		extauthtype, externaldn, clientcert, bind_target_entry);
400eba
-	PR_Unlock( conn->c_mutex );
400eba
+	PR_ExitMonitor(conn->c_mutex);
400eba
 }
400eba
 
400eba
 void
400eba
diff --git a/ldap/servers/slapd/psearch.c b/ldap/servers/slapd/psearch.c
400eba
index c9d23cf..00f13be 100644
400eba
--- a/ldap/servers/slapd/psearch.c
400eba
+++ b/ldap/servers/slapd/psearch.c
400eba
@@ -277,9 +277,9 @@ ps_send_results( void *arg )
400eba
 
400eba
     /* need to acquire a reference to this connection so that it will not
400eba
        be released or cleaned up out from under us */
400eba
-    PR_Lock( ps->ps_pblock->pb_conn->c_mutex );
400eba
+    PR_EnterMonitor(ps->ps_pblock->pb_conn->c_mutex);
400eba
     conn_acq_flag = connection_acquire_nolock(ps->ps_pblock->pb_conn);    
400eba
-    PR_Unlock( ps->ps_pblock->pb_conn->c_mutex );
400eba
+    PR_ExitMonitor(ps->ps_pblock->pb_conn->c_mutex);
400eba
 
400eba
 	if (conn_acq_flag) {
400eba
 		slapi_log_error(SLAPI_LOG_CONNS, "Persistent Search",
400eba
@@ -397,7 +397,7 @@ ps_send_results( void *arg )
400eba
 
400eba
     conn = ps->ps_pblock->pb_conn; /* save to release later - connection_remove_operation_ext will NULL the pb_conn */
400eba
     /* Clean up the connection structure */
400eba
-    PR_Lock( conn->c_mutex );
400eba
+    PR_EnterMonitor(conn->c_mutex);
400eba
 
400eba
 	slapi_log_error(SLAPI_LOG_CONNS, "Persistent Search",
400eba
 					"conn=%" NSPRIu64 " op=%d Releasing the connection and operation\n",
400eba
@@ -407,9 +407,9 @@ ps_send_results( void *arg )
400eba
 
400eba
     /* Decrement the connection refcnt */
400eba
     if (conn_acq_flag == 0) { /* we acquired it, so release it */
400eba
-	connection_release_nolock (conn);
400eba
+        connection_release_nolock (conn);
400eba
     }
400eba
-    PR_Unlock( conn->c_mutex );
400eba
+    PR_ExitMonitor(conn->c_mutex);
400eba
     conn = NULL;
400eba
 
400eba
     PR_DestroyLock ( ps->ps_lock );
400eba
diff --git a/ldap/servers/slapd/saslbind.c b/ldap/servers/slapd/saslbind.c
400eba
index 1e3e94d..7259d78 100644
400eba
--- a/ldap/servers/slapd/saslbind.c
400eba
+++ b/ldap/servers/slapd/saslbind.c
400eba
@@ -659,7 +659,7 @@ char **ids_sasl_listmech(Slapi_PBlock *pb)
400eba
     if (sasl_conn == NULL) return ret;
400eba
 
400eba
     /* sasl library mechanisms are connection dependent */
400eba
-    PR_Lock(pb->pb_conn->c_mutex);
400eba
+    PR_EnterMonitor(pb->pb_conn->c_mutex);
400eba
     if (sasl_listmech(sasl_conn, 
400eba
                       NULL,     /* username */
400eba
                       "", ",", "",
400eba
@@ -672,7 +672,7 @@ char **ids_sasl_listmech(Slapi_PBlock *pb)
400eba
         charray_free(others);
400eba
         slapi_ch_free((void**)&dupstr);
400eba
     }
400eba
-    PR_Unlock(pb->pb_conn->c_mutex);
400eba
+    PR_ExitMonitor(pb->pb_conn->c_mutex);
400eba
 
400eba
     LDAPDebug( LDAP_DEBUG_TRACE, "<= ids_sasl_listmech\n", 0, 0, 0 );
400eba
 
400eba
@@ -755,13 +755,13 @@ void ids_sasl_check_bind(Slapi_PBlock *pb)
400eba
     PR_ASSERT(pb);
400eba
     PR_ASSERT(pb->pb_conn);
400eba
 
400eba
-    PR_Lock(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
+    PR_EnterMonitor(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
     continuing = pb->pb_conn->c_flags & CONN_FLAG_SASL_CONTINUE;
400eba
     pb->pb_conn->c_flags &= ~CONN_FLAG_SASL_CONTINUE; /* reset flag */
400eba
 
400eba
     sasl_conn = (sasl_conn_t*)pb->pb_conn->c_sasl_conn;
400eba
     if (sasl_conn == NULL) {
400eba
-        PR_Unlock(pb->pb_conn->c_mutex);
400eba
+        PR_ExitMonitor(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
         send_ldap_result( pb, LDAP_AUTH_METHOD_NOT_SUPPORTED, NULL,
400eba
                           "sasl library unavailable", 0, NULL );
400eba
         return;
400eba
@@ -842,7 +842,7 @@ void ids_sasl_check_bind(Slapi_PBlock *pb)
400eba
         if (sasl_conn == NULL) {
400eba
             send_ldap_result( pb, LDAP_AUTH_METHOD_NOT_SUPPORTED, NULL,
400eba
                           "sasl library unavailable", 0, NULL );
400eba
-            PR_Unlock(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
+            PR_ExitMonitor(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
             return;
400eba
         }
400eba
     }
400eba
@@ -858,7 +858,7 @@ sasl_check_result:
400eba
         /* retrieve the authenticated username */
400eba
         if (sasl_getprop(sasl_conn, SASL_USERNAME,
400eba
                          (const void**)&username) != SASL_OK) {
400eba
-            PR_Unlock(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
+            PR_ExitMonitor(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
             send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL,
400eba
                              "could not obtain sasl username", 0, NULL);
400eba
             break;
400eba
@@ -879,7 +879,7 @@ sasl_check_result:
400eba
             }
400eba
         }
400eba
         if (dn == NULL) {
400eba
-            PR_Unlock(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
+            PR_ExitMonitor(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
             send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULL,
400eba
                              "could not get auth dn from sasl", 0, NULL);
400eba
             break;
400eba
@@ -920,7 +920,7 @@ sasl_check_result:
400eba
                                     slapi_ch_strdup(normdn), 
400eba
                                     NULL, NULL, NULL, bind_target_entry);
400eba
 
400eba
-        PR_Unlock(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
+        PR_ExitMonitor(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
 
400eba
         if (plugin_call_plugins( pb, SLAPI_PLUGIN_PRE_BIND_FN ) != 0){
400eba
             break;
400eba
@@ -995,9 +995,9 @@ sasl_check_result:
400eba
         /* see if we negotiated a security layer */
400eba
         if (*ssfp > 0) {
400eba
             /* Enable SASL I/O on the connection */
400eba
-            PR_Lock(pb->pb_conn->c_mutex);
400eba
+            PR_EnterMonitor(pb->pb_conn->c_mutex);
400eba
             connection_set_io_layer_cb(pb->pb_conn, sasl_io_enable, NULL, NULL);
400eba
-            PR_Unlock(pb->pb_conn->c_mutex);
400eba
+            PR_ExitMonitor(pb->pb_conn->c_mutex);
400eba
         }
400eba
 
400eba
         /* send successful result */
400eba
@@ -1010,7 +1010,7 @@ sasl_check_result:
400eba
 
400eba
     case SASL_CONTINUE:         /* another step needed */
400eba
         pb->pb_conn->c_flags |= CONN_FLAG_SASL_CONTINUE;
400eba
-        PR_Unlock(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
+        PR_ExitMonitor(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
 
400eba
         if (plugin_call_plugins( pb, SLAPI_PLUGIN_PRE_BIND_FN ) != 0){
400eba
             break;
400eba
@@ -1032,7 +1032,7 @@ sasl_check_result:
400eba
 
400eba
     case SASL_NOMECH:
400eba
 
400eba
-        PR_Unlock(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
+        PR_ExitMonitor(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
         send_ldap_result(pb, LDAP_AUTH_METHOD_NOT_SUPPORTED, NULL,
400eba
                          "sasl mechanism not supported", 0, NULL);
400eba
         break;
400eba
@@ -1040,7 +1040,7 @@ sasl_check_result:
400eba
     default:                    /* other error */
400eba
         errstr = sasl_errdetail(sasl_conn);
400eba
 
400eba
-        PR_Unlock(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
+        PR_ExitMonitor(pb->pb_conn->c_mutex); /* BIG LOCK */
400eba
         send_ldap_result(pb, LDAP_INVALID_CREDENTIALS, NULL,
400eba
                          (char*)errstr, 0, NULL);
400eba
         break;
400eba
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
400eba
index 823568d..2641f76 100644
400eba
--- a/ldap/servers/slapd/slap.h
400eba
+++ b/ldap/servers/slapd/slap.h
400eba
@@ -1411,7 +1411,7 @@ typedef struct conn {
400eba
 	PRInt32			c_opscompleted;	/* # ops completed		  */
400eba
 	PRInt32			c_threadnumber; /* # threads used in this conn    */
400eba
 	int				c_refcnt;	/* # ops refering to this conn    */
400eba
-	PRLock			*c_mutex;	/* protect each conn structure    */
400eba
+	PRMonitor		*c_mutex;	/* protect each conn structure; need to be re-entrant */ 
400eba
 	PRLock			*c_pdumutex;	/* only write one pdu at a time   */
400eba
 	time_t			c_idlesince;	/* last time of activity on conn  */
400eba
 	int			c_idletimeout;	/* local copy of idletimeout */
400eba
diff --git a/ldap/servers/slapd/start_tls_extop.c b/ldap/servers/slapd/start_tls_extop.c
400eba
index 69b8607..af8d8f7 100644
400eba
--- a/ldap/servers/slapd/start_tls_extop.c
400eba
+++ b/ldap/servers/slapd/start_tls_extop.c
400eba
@@ -172,7 +172,7 @@ start_tls( Slapi_PBlock *pb )
400eba
 	/* At least we know that the request was indeed an Start TLS one. */
400eba
 
400eba
 	conn = pb->pb_conn;
400eba
-	PR_Lock( conn->c_mutex );
400eba
+	PR_EnterMonitor(conn->c_mutex);
400eba
 	/* cannot call slapi_send_ldap_result with mutex locked - will deadlock if ber_flush returns error */
400eba
 	if ( conn->c_prfd == (PRFileDesc *) NULL ) {
400eba
 		slapi_log_error( SLAPI_LOG_PLUGIN, "start_tls",
400eba
@@ -246,10 +246,10 @@ start_tls( Slapi_PBlock *pb )
400eba
 	 * we send a success response back to the client. */
400eba
 	ldapmsg = "Start TLS request accepted.Server willing to negotiate SSL.";
400eba
 unlock_and_return:
400eba
-	PR_Unlock( conn->c_mutex );
400eba
+	PR_ExitMonitor(conn->c_mutex);
400eba
 	slapi_send_ldap_result( pb, ldaprc, NULL, ldapmsg, 0, NULL );
400eba
 
400eba
-	return( SLAPI_PLUGIN_EXTENDED_SENT_RESULT );	
400eba
+	return( SLAPI_PLUGIN_EXTENDED_SENT_RESULT );
400eba
 
400eba
 }/* start_tls */
400eba
 
400eba
@@ -312,7 +312,7 @@ start_tls_graceful_closure( Connection *c, Slapi_PBlock * pb, int is_initiator )
400eba
 	   */
400eba
 	}
400eba
 
400eba
-	PR_Lock( c->c_mutex );
400eba
+	PR_EnterMonitor(c->c_mutex);
400eba
 
400eba
 	/* "Unimport" the socket from SSL, i.e. get rid of the upper layer of the 
400eba
 	 * file descriptor stack, which represents SSL. 
400eba
@@ -342,7 +342,7 @@ start_tls_graceful_closure( Connection *c, Slapi_PBlock * pb, int is_initiator )
400eba
 
400eba
 	bind_credentials_clear( c, PR_FALSE, PR_TRUE );
400eba
 
400eba
-	PR_Unlock( c->c_mutex );
400eba
+	PR_ExitMonitor(c->c_mutex);
400eba
 
400eba
 	return ( SLAPI_PLUGIN_EXTENDED_SENT_RESULT );
400eba
 }    
400eba
diff --git a/ldap/servers/slapd/unbind.c b/ldap/servers/slapd/unbind.c
400eba
index 9b6a70f..c0dec9d 100644
400eba
--- a/ldap/servers/slapd/unbind.c
400eba
+++ b/ldap/servers/slapd/unbind.c
400eba
@@ -73,9 +73,9 @@ do_unbind( Slapi_PBlock *pb )
400eba
 	}
400eba
 
400eba
 	/* target spec is used to decide which plugins are applicable for the operation */
400eba
-	PR_Lock( pb->pb_conn->c_mutex );
400eba
+	PR_EnterMonitor(pb->pb_conn->c_mutex);
400eba
 	operation_set_target_spec_str (operation, pb->pb_conn->c_dn);
400eba
-	PR_Unlock( pb->pb_conn->c_mutex );
400eba
+	PR_ExitMonitor(pb->pb_conn->c_mutex);
400eba
 
400eba
 	/* ONREPL - plugins should be called and passed bind dn and, possibly, other data */
400eba
 
400eba
-- 
400eba
2.4.3
400eba