From ced22bd5ea04973ab8078f7422f911f39e9b71db Mon Sep 17 00:00:00 2001 From: ckolivas Date: Mon, 19 Jan 2015 10:54:25 +1100 Subject: [PATCH] Only lock/unlock once in drop_client --- src/stratifier.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index e9de70e3..da9b545b 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1216,6 +1216,8 @@ static void dec_worker(ckpool_t *ckp, user_instance_t *instance) static void drop_client(sdata_t *sdata, int64_t id) { stratum_instance_t *client, *tmp; + user_instance_t *instance = NULL; + ckpool_t *ckp = NULL; bool dec = false; LOGINFO("Stratifier dropping client %ld", id); @@ -1225,10 +1227,11 @@ static void drop_client(sdata_t *sdata, int64_t id) if (client) { stratum_instance_t *old_client = NULL; - __inc_instance_ref(client); if (client->authorised) { dec = true; client->authorised = false; + ckp = client->ckp; + instance = client->user_instance; } HASH_DEL(sdata->stratum_instances, client); @@ -1242,18 +1245,8 @@ static void drop_client(sdata_t *sdata, int64_t id) LL_PREPEND(sdata->dead_instances, client); } } - ck_wunlock(&sdata->instance_lock); - - /* Decrease worker count outside of instance_lock to avoid recursive - * locking */ - if (dec) - dec_worker(client->ckp, client->user_instance); - /* Cull old unused clients lazily when there are no more reference * counts for them. */ - ck_wlock(&sdata->instance_lock); - if (client) - __dec_instance_ref(client); LL_FOREACH_SAFE(sdata->dead_instances, client, tmp) { if (!client->ref) { LOGINFO("Stratifier discarding instance %ld", client->id); @@ -1264,6 +1257,11 @@ static void drop_client(sdata_t *sdata, int64_t id) } } ck_wunlock(&sdata->instance_lock); + + /* Decrease worker count outside of instance_lock to avoid recursive + * locking */ + if (dec) + dec_worker(ckp, instance); } static void stratum_broadcast_message(sdata_t *sdata, const char *msg)