Browse Source

Bugfix: SSM: We already hold the pool lock when we need to call stale_work, so avoid trying to lock it a second time inside the function

Luke Dashjr 9 years ago
parent
commit
be37d5eb49
3 changed files with 10 additions and 7 deletions
  1. 1 1
      driver-stratum.c
  2. 7 5
      miner.c
  3. 2 1
      miner.h

+ 1 - 1
driver-stratum.c

@@ -140,7 +140,7 @@ fail:
 		struct work work;
 		work2d_gen_dummy_work(&work, &pool->swork, &tv_now, NULL, 0);
 		
-		const bool is_stale = stale_work(&work, false);
+		const bool is_stale = stale_work2(&work, false, true);
 		
 		clean_work(&work);
 		

+ 7 - 5
miner.c

@@ -6364,8 +6364,6 @@ static void push_curl_entry(struct curl_ent *ce, struct pool *pool)
 	mutex_unlock(&pool->pool_lock);
 }
 
-bool stale_work(struct work *work, bool share);
-
 static inline bool should_roll(struct work *work)
 {
 	struct timeval now;
@@ -6559,7 +6557,7 @@ static void pool_died(struct pool *pool)
 		mutex_unlock(&lp_lock);
 }
 
-bool stale_work(struct work *work, bool share)
+bool stale_work2(struct work * const work, const bool share, const bool have_pool_data_lock)
 {
 	unsigned work_expiry;
 	struct pool *pool;
@@ -6632,10 +6630,14 @@ bool stale_work(struct work *work, bool share)
 
 		same_job = true;
 
-		cg_rlock(&pool->data_lock);
+		if (!have_pool_data_lock) {
+			cg_rlock(&pool->data_lock);
+		}
 		if (strcmp(work->job_id, pool->swork.job_id))
 			same_job = false;
-		cg_runlock(&pool->data_lock);
+		if (!have_pool_data_lock) {
+			cg_runlock(&pool->data_lock);
+		}
 
 		if (!same_job) {
 			applog(LOG_DEBUG, "Work stale due to stratum job_id mismatch");

+ 2 - 1
miner.h

@@ -1073,7 +1073,8 @@ extern void thread_reportin(struct thr_info *thr);
 extern void thread_reportout(struct thr_info *);
 extern void clear_stratum_shares(struct pool *pool);
 extern void hashmeter2(struct thr_info *);
-extern bool stale_work(struct work *, bool share);
+extern bool stale_work2(struct work *, bool share, bool have_pool_data_lock);
+#define stale_work(work, share)  stale_work2(work, share, false)
 extern bool stale_work_future(struct work *, bool share, unsigned long ustime);
 extern void blkhashstr(char *out, const unsigned char *hash);
 static const float minimum_pdiff = max(FLT_MIN, 1./0x100000000);