Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit d29331e

Browse files
authored
Merge pull request #1288 from hjelmn/v2.x_ugni
rcache/udreg: make reference count thread safe
2 parents c0e2099 + 756764c commit d29331e

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

opal/mca/mpool/udreg/mpool_udreg_module.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,12 @@ static uint32_t mca_mpool_udreg_dereg_func (void *device_data, void *dreg_contex
221221
{
222222
mca_mpool_udreg_module_t *mpool_udreg = (mca_mpool_udreg_module_t *) dreg_context;
223223
mca_mpool_base_registration_t *udreg_reg = (mca_mpool_base_registration_t *) device_data;
224+
int32_t ref_count = OPAL_THREAD_ADD32(&udreg_reg->ref_count, -1);
224225
int rc;
225226

226-
if (udreg_reg->ref_count) {
227+
assert(ref_count >= 0);
228+
229+
if (ref_count) {
227230
/* there are still users of this registration. leave it alone */
228231
return 0;
229232
}
@@ -442,7 +445,7 @@ int mca_mpool_udreg_register(mca_mpool_base_module_t *mpool, void *addr,
442445
udreg_reg->flags = flags;
443446

444447
*reg = udreg_reg;
445-
udreg_reg->ref_count++;
448+
OPAL_THREAD_ADD32(&udreg_reg->ref_count, 1);
446449

447450
return OPAL_SUCCESS;
448451
}
@@ -490,10 +493,6 @@ int mca_mpool_udreg_deregister(struct mca_mpool_base_module_t *mpool,
490493
{
491494
mca_mpool_udreg_module_t *mpool_udreg = (mca_mpool_udreg_module_t *) mpool;
492495

493-
assert(reg->ref_count > 0);
494-
495-
--reg->ref_count;
496-
497496
if (!(reg->flags & MCA_MPOOL_FLAGS_CACHE_BYPASS)) {
498497
OPAL_THREAD_LOCK(&mpool_udreg->lock);
499498
UDREG_DecrRefcount (mpool_udreg->udreg_handle, reg->mpool_context);

0 commit comments

Comments
 (0)