summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/client_t.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/client_t.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/client_t.c')
-rw-r--r--libglusterfs/src/client_t.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/libglusterfs/src/client_t.c b/libglusterfs/src/client_t.c
index c20c4089ec3..1adfef5c7e3 100644
--- a/libglusterfs/src/client_t.c
+++ b/libglusterfs/src/client_t.c
@@ -192,8 +192,7 @@ gf_client_get (xlator_t *this, struct rpcsvc_auth_data *cred, char *client_uid)
memcmp (cred->authdata,
client->auth.data,
client->auth.len) == 0))) {
- INCREMENT_ATOMIC (client->ref.lock,
- client->ref.bind);
+ GF_ATOMIC_INC (client->bind);
goto unlock;
}
}
@@ -207,7 +206,6 @@ gf_client_get (xlator_t *this, struct rpcsvc_auth_data *cred, char *client_uid)
client->this = this;
LOCK_INIT (&client->scratch_ctx.lock);
- LOCK_INIT (&client->ref.lock);
client->client_uid = gf_strdup (client_uid);
if (client->client_uid == NULL) {
@@ -229,8 +227,8 @@ gf_client_get (xlator_t *this, struct rpcsvc_auth_data *cred, char *client_uid)
goto unlock;
}
- /* no need to do these atomically here */
- client->ref.bind = client->ref.count = 1;
+ GF_ATOMIC_INIT (client->bind, 1);
+ GF_ATOMIC_INIT (client->count, 1);
client->auth.flavour = cred->flavour;
if (cred->flavour != AUTH_NONE) {
@@ -277,9 +275,10 @@ unlock:
if (client)
gf_msg_callingfn ("client_t", GF_LOG_DEBUG, 0, LG_MSG_BIND_REF,
- "%s: bind_ref: %d, ref: %d",
- client->client_uid, client->ref.bind,
- client->ref.count);
+ "%s: bind_ref: %"GF_PRI_ATOMIC", ref: "
+ "%"GF_PRI_ATOMIC, client->client_uid,
+ GF_ATOMIC_GET (client->bind),
+ GF_ATOMIC_GET (client->count));
return client;
}
@@ -295,14 +294,15 @@ gf_client_put (client_t *client, gf_boolean_t *detached)
if (detached)
*detached = _gf_false;
- bind_ref = DECREMENT_ATOMIC (client->ref.lock, client->ref.bind);
+ bind_ref = GF_ATOMIC_DEC (client->bind);
if (bind_ref == 0)
unref = _gf_true;
gf_msg_callingfn ("client_t", GF_LOG_DEBUG, 0, LG_MSG_BIND_REF, "%s: "
- "bind_ref: %d, ref: %d, unref: %d",
- client->client_uid, client->ref.bind,
- client->ref.count, unref);
+ "bind_ref: %"GF_PRI_ATOMIC", ref: %"GF_PRI_ATOMIC", "
+ "unref: %d", client->client_uid,
+ GF_ATOMIC_GET (client->bind),
+ GF_ATOMIC_GET (client->count), unref);
if (unref) {
if (detached)
*detached = _gf_true;
@@ -322,10 +322,10 @@ gf_client_ref (client_t *client)
return NULL;
}
- INCREMENT_ATOMIC (client->ref.lock, client->ref.count);
+ GF_ATOMIC_INC (client->count);
gf_msg_callingfn ("client_t", GF_LOG_DEBUG, 0, LG_MSG_REF_COUNT, "%s: "
- "ref-count %d", client->client_uid,
- client->ref.count);
+ "ref-count %"GF_PRI_ATOMIC, client->client_uid,
+ GF_ATOMIC_GET (client->count));
return client;
}
@@ -360,7 +360,6 @@ client_destroy (client_t *client)
clienttable = client->this->ctx->clienttable;
LOCK_DESTROY (&client->scratch_ctx.lock);
- LOCK_DESTROY (&client->ref.lock);
LOCK (&clienttable->lock);
{
@@ -419,7 +418,7 @@ gf_client_disconnect (client_t *client)
void
gf_client_unref (client_t *client)
{
- int refcount;
+ uint64_t refcount;
if (!client) {
gf_msg_callingfn ("client_t", GF_LOG_ERROR, EINVAL,
@@ -427,10 +426,10 @@ gf_client_unref (client_t *client)
return;
}
- refcount = DECREMENT_ATOMIC (client->ref.lock, client->ref.count);
+ refcount = GF_ATOMIC_DEC (client->count);
gf_msg_callingfn ("client_t", GF_LOG_DEBUG, 0, LG_MSG_REF_COUNT, "%s: "
- "ref-count %d", client->client_uid,
- (int)client->ref.count);
+ "ref-count %"GF_PRI_ATOMIC, client->client_uid,
+ refcount);
if (refcount == 0) {
gf_msg (THIS->name, GF_LOG_INFO, 0, LG_MSG_DISCONNECT_CLIENT,
"Shutting down connection %s", client->client_uid);
@@ -586,7 +585,8 @@ client_dump (client_t *client, char *prefix)
return;
memset(key, 0, sizeof key);
- gf_proc_dump_write("refcount", "%d", client->ref.count);
+ gf_proc_dump_write("refcount", GF_PRI_ATOMIC,
+ GF_ATOMIC_GET (client->count));
}
@@ -780,7 +780,8 @@ gf_client_dump_fdtables (xlator_t *this)
gf_proc_dump_build_key (key, "conn", "%d.ref",
count);
- gf_proc_dump_write (key, "%d", client->ref.count);
+ gf_proc_dump_write (key, GF_PRI_ATOMIC,
+ GF_ATOMIC_GET (client->count));
if (client->bound_xl) {
gf_proc_dump_build_key (key, "conn",
"%d.bound_xl", count);