From 6b30cfc9d04402e9e92d686400a297857d75603b Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 26 Jan 2015 15:19:31 +1100 Subject: [PATCH] Move possible LOGERR usage ouf ot lock in __drop_client --- src/stratifier.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index 8952b228..02603fc3 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1171,16 +1171,19 @@ static void __drop_client(sdata_t *sdata, stratum_instance_t *client, user_insta static void _dec_instance_ref(sdata_t *sdata, stratum_instance_t *instance, const char *file, const char *func, const int line) { + int ref; + ck_wlock(&sdata->instance_lock); - if (unlikely(--instance->ref < 0)) { - LOGERR("Instance ref count dropped below zero from %s %s:%d", file, func, line); - instance->ref = 0; - } + ref = --instance->ref; /* 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(instance->dropped && !instance->ref)) + if (unlikely(instance->dropped && !ref)) __drop_client(sdata, instance, instance->user_instance, instance->id); ck_wunlock(&sdata->instance_lock); + + /* This should never happen */ + if (unlikely(ref < 0)) + LOGERR("Instance ref count dropped below zero from %s %s:%d", file, func, line); } #define dec_instance_ref(sdata, instance) _dec_instance_ref(sdata, instance, __FILE__, __func__, __LINE__)