From a9f16e427d5a66138eca28926aa9b81f9e05cb49 Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Thu, 15 Nov 2012 12:57:35 -0500 Subject: [PATCH] Ticket 507 - use mutex for FrontendConfig lock instead of rwlock Bug Description: There was a lot of contention over the read/write lock for the frontend config Fix Description: Updated the macros to use a simple lock. https://fedorahosted.org/389/ticket/507 Reviewed by: noriko(Thanks!) --- ldap/servers/slapd/daemon.c | 8 ++++---- ldap/servers/slapd/libglobs.c | 14 ++++++++++---- ldap/servers/slapd/slap.h | 16 ++++++++++++++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/ldap/servers/slapd/daemon.c b/ldap/servers/slapd/daemon.c index 62a52fc..85052fe 100644 --- a/ldap/servers/slapd/daemon.c +++ b/ldap/servers/slapd/daemon.c @@ -602,11 +602,11 @@ disk_mon_get_dirs(char ***list, int logs_critical){ char *dir = NULL; if(logs_critical){ - slapi_rwlock_rdlock(config->cfg_rwlock); + CFG_LOCK_READ(config); disk_mon_add_dir(list, config->accesslog); disk_mon_add_dir(list, config->errorlog); disk_mon_add_dir(list, config->auditlog); - slapi_rwlock_unlock(config->cfg_rwlock); + CFG_UNLOCK_READ(config); } /* Add /var just to be safe */ @@ -617,9 +617,9 @@ disk_mon_get_dirs(char ***list, int logs_critical){ #endif /* config and backend directories */ - slapi_rwlock_rdlock(config->cfg_rwlock); + CFG_LOCK_READ(config); disk_mon_add_dir(list, config->configdir); - slapi_rwlock_unlock(config->cfg_rwlock); + CFG_UNLOCK_READ(config); be = slapi_get_first_backend (&cookie); while (be) { diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c index a7e504f..a5a59e0 100644 --- a/ldap/servers/slapd/libglobs.c +++ b/ldap/servers/slapd/libglobs.c @@ -1238,14 +1238,20 @@ void FrontendConfig_init () { slapdFrontendConfig_t *cfg = getFrontendConfig(); +#if SLAPI_CFG_USE_RWLOCK == 1 /* initialize the read/write configuration lock */ if ( (cfg->cfg_rwlock = slapi_new_rwlock()) == NULL ) { - LDAPDebug ( LDAP_DEBUG_ANY, - "FrontendConfig_init: failed to initialize cfg_rwlock. Exiting now.", - 0,0,0 ); + LDAPDebug ( LDAP_DEBUG_ANY, "FrontendConfig_init: " + "failed to initialize cfg_rwlock. Exiting now.",0,0,0); exit(-1); } - +#else + if ((cfg->cfg_lock = PR_NewLock()) == NULL){ + LDAPDebug(LDAP_DEBUG_ANY, "FrontendConfig_init: " + "failed to initialize cfg_lock. Exiting now.",0,0,0); + exit(-1); + } +#endif cfg->port = LDAP_PORT; cfg->secureport = LDAPS_PORT; cfg->ldapi_filename = slapi_ch_strdup(SLAPD_LDAPI_DEFAULT_FILENAME); diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h index dbd9727..cc99486 100644 --- a/ldap/servers/slapd/slap.h +++ b/ldap/servers/slapd/slap.h @@ -2056,10 +2056,18 @@ typedef struct _slapdEntryPoints { /* flag used to indicate that the change to the config parameter should be saved */ #define CONFIG_APPLY 1 -#define CFG_LOCK_READ(cfg) slapi_rwlock_rdlock(cfg->cfg_rwlock) -#define CFG_UNLOCK_READ(cfg) slapi_rwlock_unlock(cfg->cfg_rwlock) +#define SLAPI_CFG_USE_RWLOCK 0 +#if SLAPI_CFG_USE_RWLOCK == 0 +#define CFG_LOCK_READ(cfg) PR_Lock(cfg->cfg_lock) +#define CFG_UNLOCK_READ(cfg) PR_Unlock(cfg->cfg_lock) +#define CFG_LOCK_WRITE(cfg) PR_Lock(cfg->cfg_lock) +#define CFG_UNLOCK_WRITE(cfg) PR_Unlock(cfg->cfg_lock) +#else +#define CFG_LOCK_READ(cfg) slapi_rwlock_rdlock(cfg->cfg_rwlock) +#define CFG_UNLOCK_READ(cfg) slapi_rwlock_unlock(cfg->cfg_rwlock) #define CFG_LOCK_WRITE(cfg) slapi_rwlock_wrlock(cfg->cfg_rwlock) #define CFG_UNLOCK_WRITE(cfg) slapi_rwlock_unlock(cfg->cfg_rwlock) +#endif #define REFER_MODE_OFF 0 #define REFER_MODE_ON 1 @@ -2067,7 +2075,11 @@ typedef struct _slapdEntryPoints { #define MAX_ALLOWED_TIME_IN_SECS 2147483647 typedef struct _slapdFrontendConfig { +#if SLAPI_CFG_USE_RWLOCK == 1 Slapi_RWLock *cfg_rwlock; /* read/write lock to serialize access */ +#else + PRLock *cfg_lock; +#endif struct pw_scheme *rootpwstoragescheme; int accesscontrol; int groupevalnestlevel; -- 1.7.1