From aa9938973e1410c34500992ff304c131f6fde9b2 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 5 Nov 2013 09:08:52 +1100 Subject: [PATCH] Use only a trylock in flush queue to prevent deadlocks. --- cgminer.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cgminer.c b/cgminer.c index bd5a7ed2..d1046459 100644 --- a/cgminer.c +++ b/cgminer.c @@ -6614,7 +6614,13 @@ static void flush_queue(struct cgpu_info *cgpu) { struct work *work = NULL; - wr_lock(&cgpu->qlock); + if (unlikely(!cgpu)) + return; + + /* Use only a trylock in case we get into a deadlock with a queueing + * function holding the read lock when we're called. */ + if (wr_trylock(&cgpu->qlock)) + return; work = cgpu->unqueued_work; cgpu->unqueued_work = NULL; wr_unlock(&cgpu->qlock);