From: Ondřej Kuzník Date: Mon, 23 Jan 2023 11:48:33 +0000 (+0000) Subject: ITS#9045 rlock only if there may be other threads X-Git-Tag: OPENLDAP_REL_ENG_2_5_14~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5936d721227596e5994f6bee4ad014482181e455;p=thirdparty%2Fopenldap.git 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? --- diff --git a/include/ldap_pvt_thread.h b/include/ldap_pvt_thread.h index 037d6e966a..20f5fb8c1e 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 797d59e841..86234643c9 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 4e00802723..52fe6ad67c 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -6979,13 +6979,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 ) { @@ -7001,7 +7004,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;