summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/xlator.c
diff options
context:
space:
mode:
authorNiels de Vos <ndevos@redhat.com>2017-03-29 13:44:03 +0200
committerJeff Darcy <jeff@pl.atyp.us>2017-04-05 09:14:26 -0400
commit93e3c9abce1a02ac724afa382751852fa5edf713 (patch)
tree887c599c2a31ab65a2f0b2440e5f3fe8b6061afc /libglusterfs/src/xlator.c
parentd6b88e9b8b02813620c3c1a2ea49d58d29062b3e (diff)
libglusterfs: provide standardized atomic operations
The current macros ATOMIC_INCREMENT() and ATOMIC_DECREMENT() expect a lock as first argument. There are at least two issues with this approach: 1. this lock is unused on architectures that have atomic operations 2. some structures use a single lock for multiple variables By defining a gf_atomic_t type, the unused lock can be removed, saving a few bytes on modern architectures. Because the gf_atomic_t type locates the lock for the variable (in case of older architectures), each variable is protected the same on all architectures. This makes the behaviour across all architectures more equal (per variable locking, by a gf_lock_t or compiler optimization). BUG: 1437037 Change-Id: Ic164892b06ea676e6a9566f8a98b7faf0efe76d6 Signed-off-by: Niels de Vos <ndevos@redhat.com> Reviewed-on: https://review.gluster.org/16963 Smoke: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Xavier Hernandez <xhernandez@datalab.es> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Amar Tumballi <amarts@redhat.com> Reviewed-by: Jeff Darcy <jeff@pl.atyp.us>
Diffstat (limited to 'libglusterfs/src/xlator.c')
-rw-r--r--libglusterfs/src/xlator.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
index 0d09b3fbc82..408012e7846 100644
--- a/libglusterfs/src/xlator.c
+++ b/libglusterfs/src/xlator.c
@@ -596,8 +596,7 @@ xlator_mem_acct_init (xlator_t *xl, int num_types)
memset (xl->mem_acct, 0, sizeof(struct mem_acct));
xl->mem_acct->num_types = num_types;
- LOCK_INIT (&xl->mem_acct->lock);
- xl->mem_acct->refcnt = 1;
+ GF_ATOMIC_INIT (xl->mem_acct->refcnt, 1);
for (i = 0; i < num_types; i++) {
memset (&xl->mem_acct->rec[i], 0, sizeof(struct mem_acct_rec));
@@ -654,7 +653,7 @@ xlator_memrec_free (xlator_t *xl)
for (i = 0; i < mem_acct->num_types; i++) {
LOCK_DESTROY (&(mem_acct->rec[i].lock));
}
- if (DECREMENT_ATOMIC (mem_acct->lock, mem_acct->refcnt) == 0) {
+ if (GF_ATOMIC_DEC (mem_acct->refcnt) == 0) {
FREE (mem_acct);
xl->mem_acct = NULL;
}