From 4658b761e4dd86d64bca0c9ed9b153dff8846903 Mon Sep 17 00:00:00 2001 From: Nathan Hjelm Date: Wed, 27 Jul 2016 13:40:35 -0600 Subject: [PATCH] rcache/udreg: make reference count thread safe Signed-off-by: Nathan Hjelm --- opal/mca/rcache/udreg/rcache_udreg_module.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/opal/mca/rcache/udreg/rcache_udreg_module.c b/opal/mca/rcache/udreg/rcache_udreg_module.c index 97103ddf83..51c2467652 100644 --- a/opal/mca/rcache/udreg/rcache_udreg_module.c +++ b/opal/mca/rcache/udreg/rcache_udreg_module.c @@ -301,7 +301,7 @@ static int mca_rcache_udreg_register(mca_rcache_base_module_t *rcache, void *add OPAL_THREAD_UNLOCK(&rcache_udreg->lock); *reg = udreg_reg; - ++udreg_reg->ref_count; + (void) OPAL_THREAD_ADD32(&udreg_reg->ref_count, 1); udreg_reg->rcache_context = udreg_entry; return OPAL_SUCCESS; @@ -318,16 +318,15 @@ static int mca_rcache_udreg_deregister(mca_rcache_base_module_t *rcache, mca_rcache_base_registration_t *reg) { mca_rcache_udreg_module_t *rcache_udreg = (mca_rcache_udreg_module_t *) rcache; + int32_t ref_count = OPAL_THREAD_ADD32 (®->ref_count, -1); - assert(reg->ref_count > 0); - - --reg->ref_count; + assert(ref_count >= 0); if (!(reg->flags & MCA_RCACHE_FLAGS_CACHE_BYPASS)) { OPAL_THREAD_LOCK(&rcache_udreg->lock); UDREG_DecrRefcount (rcache_udreg->udreg_handle, reg->rcache_context); OPAL_THREAD_UNLOCK(&rcache_udreg->lock); - } else if (!reg->ref_count) { + } else if (!ref_count) { mca_rcache_udreg_dereg_func (reg, rcache); }