From cdc7497a28c613aa9d9529afbe089ba611cb4974 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 12 Jan 2016 16:18:28 +1100 Subject: [PATCH] Add instance counter to worker data --- src/stratifier.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index 9982ebae..d1071759 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -205,6 +205,9 @@ struct worker_instance { user_instance_t *user_instance; char *workername; + /* Number of stratum instances attached as this one worker */ + int instance_count; + worker_instance_t *next; worker_instance_t *prev; @@ -1227,18 +1230,20 @@ static void __kill_instance(sdata_t *sdata, stratum_instance_t *client) /* Called with instance_lock held. Note stats.users is protected by * instance lock to avoid recursive locking. */ -static void __inc_worker(sdata_t *sdata, user_instance_t *instance) +static void __inc_worker(sdata_t *sdata, user_instance_t *user, worker_instance_t *worker) { sdata->stats.workers++; - if (!instance->workers++) + if (!user->workers++) sdata->stats.users++; + worker->instance_count++; } -static void __dec_worker(sdata_t *sdata, user_instance_t *instance) +static void __dec_worker(sdata_t *sdata, user_instance_t *user, worker_instance_t *worker) { sdata->stats.workers--; - if (!--instance->workers) + if (!--user->workers) sdata->stats.users--; + worker->instance_count--; } static void __disconnect_session(sdata_t *sdata, const stratum_instance_t *client) @@ -1281,7 +1286,7 @@ static void __del_client(sdata_t *sdata, stratum_instance_t *client) HASH_DEL(sdata->stratum_instances, client); if (user) { DL_DELETE(user->clients, client); - __dec_worker(sdata, user); + __dec_worker(sdata, user, client->worker_instance); } } @@ -4130,7 +4135,7 @@ static user_instance_t *generate_user(ckpool_t *ckp, stratum_instance_t *client, client->user_instance = user; client->worker_instance = worker; DL_APPEND(user->clients, client); - __inc_worker(sdata,user); + __inc_worker(sdata,user, worker); ck_wunlock(&sdata->instance_lock); if (new_user && !ckp->proxy) {