From 127ac19045cc2ceec6b1ed7638f79efe15da0fae Mon Sep 17 00:00:00 2001 From: Morris Jette <jette@schedmd.com> Date: Wed, 8 Jun 2016 08:06:12 -0700 Subject: [PATCH] Wrap variable with mutex Valgrind's drd tool reported a race condition on a variable, so mutex was added to wrap it. The chances of this causing a problem are nill, but this makes it zero. --- src/common/slurm_acct_gather.c | 16 +++++++++++++++- src/common/slurm_acct_gather.h | 3 +-- src/common/slurm_acct_gather_profile.c | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/common/slurm_acct_gather.c b/src/common/slurm_acct_gather.c index e15cd414216..8db8397e853 100644 --- a/src/common/slurm_acct_gather.c +++ b/src/common/slurm_acct_gather.c @@ -42,7 +42,8 @@ #include "src/common/slurm_strcasestr.h" #include "src/common/xstring.h" -bool acct_gather_suspended = false; +static bool acct_gather_suspended = false; +static pthread_mutex_t suspended_mutex = PTHREAD_MUTEX_INITIALIZER; static bool inited = 0; @@ -244,10 +245,23 @@ extern int acct_gather_check_acct_freq_task( extern void acct_gather_suspend_poll(void) { + slurm_mutex_lock(&suspended_mutex); acct_gather_suspended = true; + slurm_mutex_unlock(&suspended_mutex); } extern void acct_gather_resume_poll(void) { + slurm_mutex_lock(&suspended_mutex); acct_gather_suspended = false; + slurm_mutex_unlock(&suspended_mutex); +} + +extern bool acct_gather_suspend_test(void) +{ + bool rc; + slurm_mutex_lock(&suspended_mutex); + rc = acct_gather_suspended; + slurm_mutex_unlock(&suspended_mutex); + return rc; } diff --git a/src/common/slurm_acct_gather.h b/src/common/slurm_acct_gather.h index e6533a92a01..eda1d90697e 100644 --- a/src/common/slurm_acct_gather.h +++ b/src/common/slurm_acct_gather.h @@ -57,8 +57,6 @@ #include "slurm_acct_gather_infiniband.h" #include "slurm_acct_gather_filesystem.h" -extern bool acct_gather_suspended; - extern int acct_gather_conf_init(void); extern int acct_gather_conf_destroy(void); @@ -69,5 +67,6 @@ extern int acct_gather_check_acct_freq_task( uint32_t job_mem_lim, char *acctg_freq); extern void acct_gather_suspend_poll(void); extern void acct_gather_resume_poll(void); +extern bool acct_gather_suspend_test(void); #endif diff --git a/src/common/slurm_acct_gather_profile.c b/src/common/slurm_acct_gather_profile.c index c016c0102d3..949003d50c2 100644 --- a/src/common/slurm_acct_gather_profile.c +++ b/src/common/slurm_acct_gather_profile.c @@ -147,7 +147,7 @@ static void *_timer_thread(void *args) now = time(NULL); for (i=0; i<PROFILE_CNT; i++) { - if (acct_gather_suspended) { + if (acct_gather_suspend_test()) { /* Handle suspended time as if it * didn't happen */ if (!acct_gather_profile_timer[i].freq) -- GitLab