From 66c2b5ad5f67dd8d04d854f9d84ced4eb180888c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ond=C5=99ej=20Kuzn=C3=ADk?= Date: Mon, 23 Jan 2023 11:48:33 +0000 Subject: [PATCH] ITS#9045 rlock only if there may be other threads We can't rlock if we've registered ourselves as a writer. We can only figure that out by checking if we're the thread that initiated the pause: is the server paused already? --- include/ldap_pvt_thread.h | 3 ++- libraries/libldap/tpool.c | 6 ++++++ servers/slapd/bconfig.c | 11 +++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/ldap_pvt_thread.h b/include/ldap_pvt_thread.h index d476312990..829ce8a1a8 100644 --- a/include/ldap_pvt_thread.h +++ b/include/ldap_pvt_thread.h @@ -253,7 +253,8 @@ typedef enum { LDAP_PVT_THREAD_POOL_PARAM_ACTIVE_MAX, LDAP_PVT_THREAD_POOL_PARAM_PENDING_MAX, LDAP_PVT_THREAD_POOL_PARAM_BACKLOAD_MAX, - LDAP_PVT_THREAD_POOL_PARAM_STATE + LDAP_PVT_THREAD_POOL_PARAM_STATE, + LDAP_PVT_THREAD_POOL_PARAM_PAUSED } ldap_pvt_thread_pool_param_t; #endif /* !LDAP_PVT_THREAD_H_DONE */ diff --git a/libraries/libldap/tpool.c b/libraries/libldap/tpool.c index 8d7b6ef6c9..f3b0da8ca2 100644 --- a/libraries/libldap/tpool.c +++ b/libraries/libldap/tpool.c @@ -769,6 +769,12 @@ ldap_pvt_thread_pool_query( } break; + case LDAP_PVT_THREAD_POOL_PARAM_PAUSED: + ldap_pvt_thread_mutex_lock(&pool->ltp_mutex); + count = (pool->ltp_pause == PAUSED); + ldap_pvt_thread_mutex_unlock(&pool->ltp_mutex); + break; + case LDAP_PVT_THREAD_POOL_PARAM_UNKNOWN: break; } diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index c7f969d2a4..027ebdcf74 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -6903,13 +6903,16 @@ int config_back_entry_get( CfBackInfo *cfb; CfEntryInfo *ce, *last; Entry *e = NULL; - int locked = 0, rc = LDAP_NO_SUCH_OBJECT; + int paused = 0, rc = LDAP_NO_SUCH_OBJECT; cfb = (CfBackInfo *)op->o_bd->be_private; - if ( !ldap_pvt_thread_pool_pausequery( &connection_pool ) ) { + if ( ldap_pvt_thread_pool_query( &connection_pool, + LDAP_PVT_THREAD_POOL_PARAM_PAUSED, &paused ) ) { + return -1; + } + if ( !paused ) { ldap_pvt_thread_rdwr_rlock( &cfb->cb_rwlock ); - locked = 1; } ce = config_find_base( cfb->cb_root, ndn, &last ); if ( ce ) { @@ -6925,7 +6928,7 @@ int config_back_entry_get( if ( e ) { *ent = entry_dup( e ); } - if ( locked ) + if ( !paused ) ldap_pvt_thread_rdwr_runlock( &cfb->cb_rwlock ); return rc; -- 2.47.3