diff options
| author | Niels de Vos <ndevos@redhat.com> | 2017-04-07 13:02:08 +0200 | 
|---|---|---|
| committer | Jeff Darcy <jeff@pl.atyp.us> | 2017-04-10 11:05:56 -0400 | 
| commit | ec0e1176d476ef5765efe7713ce6a57f2f081722 (patch) | |
| tree | f3a3aacfc9aa0342d62d44e1decb49c17041b77b | |
| parent | 44b1a68bc9bc1605d208d50fbafae85967085e58 (diff) | |
mem-pool: use gf_atomic_t for atomic counters
Reduce the usage of __sync_fetch_and_add() builtins in mem-pool. The new
gf_atomic_t type can be used instead, so that the architecture and
compiler specific builtins are hidden from the mem-pool implementation.
BUG: 1437037
Change-Id: Icbeeb187dd2b835b35f32f54f821ceddfc7b2638
Signed-off-by: Niels de Vos <ndevos@redhat.com>
Reviewed-on: https://review.gluster.org/17012
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Smoke: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
| -rw-r--r-- | libglusterfs/src/mem-pool.c | 13 | ||||
| -rw-r--r-- | libglusterfs/src/mem-pool.h | 8 | 
2 files changed, 13 insertions, 8 deletions
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index 4b600f4681a..23af8619fb5 100644 --- a/libglusterfs/src/mem-pool.c +++ b/libglusterfs/src/mem-pool.c @@ -529,6 +529,11 @@ mem_pools_preinit (void)          for (i = 0; i < NPOOLS; ++i) {                  pools[i].power_of_two = POOL_SMALLEST + i; + +                GF_ATOMIC_INIT (pools[i].allocs_hot, 0); +                GF_ATOMIC_INIT (pools[i].allocs_cold, 0); +                GF_ATOMIC_INIT (pools[i].allocs_stdc, 0); +                GF_ATOMIC_INIT (pools[i].frees_to_list, 0);          }          pool_list_size = sizeof (per_thread_pool_list_t) @@ -641,19 +646,19 @@ mem_get_from_pool (per_thread_pool_t *pt_pool)          retval = pt_pool->hot_list;          if (retval) { -                (void) __sync_fetch_and_add (&pt_pool->parent->allocs_hot, 1); +                GF_ATOMIC_INC (pt_pool->parent->allocs_hot);                  pt_pool->hot_list = retval->next;                  return retval;          }          retval = pt_pool->cold_list;          if (retval) { -                (void) __sync_fetch_and_add (&pt_pool->parent->allocs_cold, 1); +                GF_ATOMIC_INC (pt_pool->parent->allocs_cold);                  pt_pool->cold_list = retval->next;                  return retval;          } -        (void) __sync_fetch_and_add (&pt_pool->parent->allocs_stdc, 1); +        GF_ATOMIC_INC (pt_pool->parent->allocs_stdc);          return malloc (1 << pt_pool->parent->power_of_two);  } @@ -727,7 +732,7 @@ mem_put (void *ptr)          hdr->magic = GF_MEM_INVALID_MAGIC;          hdr->next = pt_pool->hot_list;          pt_pool->hot_list = hdr; -        (void) __sync_fetch_and_add (&pt_pool->parent->frees_to_list, 1); +        GF_ATOMIC_INC (pt_pool->parent->frees_to_list);          (void) pthread_spin_unlock (&pool_list->lock);  #endif /* GF_DISABLE_MEMPOOL */  } diff --git a/libglusterfs/src/mem-pool.h b/libglusterfs/src/mem-pool.h index 1b27119cf6c..1b8132bf315 100644 --- a/libglusterfs/src/mem-pool.h +++ b/libglusterfs/src/mem-pool.h @@ -250,10 +250,10 @@ struct mem_pool {           * them to line up exactly.  It's the general trends that matter, and           * it's not worth the locked-bus-cycle overhead to make these precise.           */ -        unsigned long           allocs_hot; -        unsigned long           allocs_cold; -        unsigned long           allocs_stdc; -        unsigned long           frees_to_list; +        gf_atomic_t             allocs_hot; +        gf_atomic_t             allocs_cold; +        gf_atomic_t             allocs_stdc; +        gf_atomic_t             frees_to_list;  };  void mem_pools_init (void);  | 
