From 21194cfbb427b6d6b75e43fefc6ea7e4af4f0d6c Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 23 Feb 2015 20:21:05 +1100 Subject: [PATCH] Count dropped workers in _dec_instance_ref Conflicts: src/stratifier.c --- src/stratifier.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/stratifier.c b/src/stratifier.c index c844c1dd..5752ef2f 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1223,11 +1223,15 @@ static void client_drop_message(const int64_t client_id, const int dropped, cons } } +static void dec_worker(ckpool_t *ckp, user_instance_t *instance); + /* Decrease the reference count of instance. */ static void _dec_instance_ref(sdata_t *sdata, stratum_instance_t *client, const char *file, const char *func, const int line) { + user_instance_t *user = client->user_instance; int64_t client_id = client->id; + ckpool_t *ckp = client->ckp; int dropped = 0, ref; ck_wlock(&sdata->instance_lock); @@ -1235,7 +1239,7 @@ static void _dec_instance_ref(sdata_t *sdata, stratum_instance_t *client, const /* See if there are any instances that were dropped that could not be * moved due to holding a reference and drop them now. */ if (unlikely(client->dropped && !ref)) - dropped = __drop_client(sdata, client, client->user_instance); + dropped = __drop_client(sdata, client, user); ck_wunlock(&sdata->instance_lock); client_drop_message(client_id, dropped, true); @@ -1243,6 +1247,9 @@ static void _dec_instance_ref(sdata_t *sdata, stratum_instance_t *client, const /* This should never happen */ if (unlikely(ref < 0)) LOGERR("Instance ref count dropped below zero from %s %s:%d", file, func, line); + + if (dropped) + dec_worker(ckp, user); } #define dec_instance_ref(sdata, instance) _dec_instance_ref(sdata, instance, __FILE__, __func__, __LINE__)