Browse Source

Bugfix: Hold the control lock when updating the generate-to script

Luke Dashjr 9 years ago
parent
commit
3aa8b6aafd
2 changed files with 9 additions and 0 deletions
  1. 4 0
      miner.c
  2. 5 0
      miner.h

+ 4 - 0
miner.c

@@ -2926,14 +2926,18 @@ void refresh_bitcoind_address(const bool fresh)
 			json_decref(json);
 			continue;
 		}
+		cg_ilock(&control_lock);
 		if (bytes_eq(&newscript, &opt_coinbase_script))
 		{
+			cg_iunlock(&control_lock);
 			applog(LOG_DEBUG, "Pool %d returned coinbase address already in use (%s)", pool->pool_no, s);
 			json_decref(json);
 			break;
 		}
+		cg_ulock(&control_lock);
 		bytes_assimilate(&opt_coinbase_script, &newscript);
 		coinbase_script_block_id = current_block_id;
+		cg_wunlock(&control_lock);
 		applog(LOG_NOTICE, "Now using coinbase address %s, provided by pool %d", s, pool->pool_no);
 		json_decref(json);
 		break;

+ 5 - 0
miner.h

@@ -913,6 +913,11 @@ static inline void cg_runlock(cglock_t *lock)
 	rd_unlock(&lock->rwlock);
 }
 
+static inline void cg_iunlock(cglock_t *lock)
+{
+	mutex_unlock(&lock->mutex);
+}
+
 static inline void cg_wunlock(cglock_t *lock)
 {
 	wr_unlock_noyield(&lock->rwlock);