Browse Source

Merge branch 'master' into bfgminer

Luke Dashjr 13 years ago
parent
commit
14b43a39c4
3 changed files with 19 additions and 11 deletions
  1. 3 0
      NEWS
  2. 1 1
      configure.ac
  3. 15 10
      miner.c

+ 3 - 0
NEWS

@@ -1,5 +1,8 @@
 BFGMiner Version 2.3.6 - April 29, 2012
 
+- Shorten stale share messages slightly.
+- Protect the freeing of current_hash under mutex_lock to prevent racing on it
+when set_curblock is hit concurrently.
 - Change default behaviour to submitting stale, removing the --submit-stale
 option and adding a --no-submit-stale option.
 - Make sure to start the getwork and submit threads when a pool is added on the

+ 1 - 1
configure.ac

@@ -2,7 +2,7 @@
 ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
 m4_define([v_maj], [2])
 m4_define([v_min], [3])
-m4_define([v_mic], [5])
+m4_define([v_mic], [6])
 ##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
 m4_define([v_ver], [v_maj.v_min.v_mic])
 m4_define([lt_rev], m4_eval(v_maj + v_min))

+ 15 - 10
miner.c

@@ -162,7 +162,9 @@ static pthread_mutex_t *stgd_lock;
 #ifdef HAVE_CURSES
 static pthread_mutex_t curses_lock;
 #endif
+static pthread_mutex_t ch_lock;
 static pthread_rwlock_t blk_lock;
+
 pthread_rwlock_t netacc_lock;
 
 double total_mhashes_done;
@@ -2156,13 +2158,13 @@ static void *submit_work_thread(void *userdata)
 
 		if (stale_work(work, true)) {
 			if (pool->submit_old)
-				applog(LOG_NOTICE, "Stale share detected, submitting as pool %d requested",
+				applog(LOG_NOTICE, "Stale share, submitting as pool %d requested",
 				       pool->pool_no);
 			else if (opt_submit_stale)
-				applog(LOG_NOTICE, "Stale share detected from pool %d, submitting as user requested",
+				applog(LOG_NOTICE, "Stale share from pool %d, submitting as user requested",
 					pool->pool_no);
 			else {
-				applog(LOG_NOTICE, "Stale share detected from pool %d, discarding",
+				applog(LOG_NOTICE, "Stale share from pool %d, discarding",
 					pool->pool_no);
 				sharelog("discard", work);
 				total_stale++;
@@ -2437,23 +2439,25 @@ static void restart_threads(void)
 static void set_curblock(char *hexstr, unsigned char *hash)
 {
 	unsigned char hash_swap[32];
-	char *old_hash = NULL;
 	struct timeval tv_now;
+	char *old_hash;
 
-	/* Don't free current_hash directly to avoid dereferencing it when
-	 * we might be accessing its data elsewhere */
-	if (current_hash)
-		old_hash = current_hash;
 	strcpy(current_block, hexstr);
 	gettimeofday(&tv_now, NULL);
 	get_timestamp(blocktime, &tv_now);
 	swap256(hash_swap, hash);
+
+	/* Don't free current_hash directly to avoid dereferencing when read
+	 * elsewhere */
+	mutex_lock(&ch_lock);
+	old_hash = current_hash;
 	current_hash = bin2hex(hash_swap, 16);
+	free(old_hash);
+	mutex_unlock(&ch_lock);
+
 	if (unlikely(!current_hash))
 		quit (1, "set_curblock OOM");
 	applog(LOG_INFO, "New block: %s...", current_hash);
-	if (old_hash)
-		free(old_hash);
 }
 
 /* Search to see if this string is from a block that has been seen before */
@@ -4768,6 +4772,7 @@ int main(int argc, char *argv[])
 #endif
 	mutex_init(&control_lock);
 	mutex_init(&sharelog_lock);
+	mutex_init(&ch_lock);
 	rwlock_init(&blk_lock);
 	rwlock_init(&netacc_lock);