Skip to content

Commit

Permalink
Merge pull request #1897 from yosefe/topic/ucs-rcache-fix-put-race
Browse files Browse the repository at this point in the history
UCS/RCACHE: Fix race condition in rcache region put.
  • Loading branch information
yosefe authored Oct 9, 2017
2 parents d1bd58e + 7c7b531 commit 18cee9d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/ucs/sys/rcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,16 +523,15 @@ void ucs_rcache_region_put(ucs_rcache_t *rcache, ucs_rcache_region_t *region)
{
ucs_rcache_region_trace(rcache, region, "put");

pthread_rwlock_wrlock(&rcache->lock);

ucs_assert(region->refcount > 0);
ucs_atomic_add32(&region->refcount, -1);

if (ucs_unlikely(region->flags & UCS_RCACHE_REGION_FLAG_INVALID) &&
(region->refcount == 0))
{
pthread_rwlock_wrlock(&rcache->lock);
if (region->refcount == 0) {
ucs_rcache_region_invalidate(rcache, region, 0, 1);
pthread_rwlock_unlock(&rcache->lock);
}
pthread_rwlock_unlock(&rcache->lock);
}

static UCS_CLASS_INIT_FUNC(ucs_rcache_t, const ucs_rcache_params_t *params,
Expand Down

0 comments on commit 18cee9d

Please sign in to comment.