Browse Source

Bugfix: Use clear_work and workdup everywhere work is copied around

Luke Dashjr 13 years ago
parent
commit
52e1b52902
7 changed files with 20 additions and 12 deletions
  1. 6 3
      driver-icarus.c
  2. 2 1
      driver-modminer.c
  3. 2 1
      driver-opencl.c
  4. 2 1
      driver-x6500.c
  5. 1 1
      findnonce.c
  6. 5 5
      miner.c
  7. 2 0
      miner.h

+ 6 - 3
driver-icarus.c

@@ -866,7 +866,8 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 
 
 	if (state->firstrun) {
 	if (state->firstrun) {
 		state->firstrun = false;
 		state->firstrun = false;
-		memcpy(&state->last_work, work, sizeof(state->last_work));
+		clear_work(&state->last_work);
+		workcpy(&state->last_work, work);
 		return 0;
 		return 0;
 	}
 	}
 
 
@@ -874,7 +875,8 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 
 
 	// aborted before becoming idle, get new work
 	// aborted before becoming idle, get new work
 	if (ret == ICA_GETS_TIMEOUT || ret == ICA_GETS_RESTART) {
 	if (ret == ICA_GETS_TIMEOUT || ret == ICA_GETS_RESTART) {
-		memcpy(&state->last_work, work, sizeof(state->last_work));
+		clear_work(&state->last_work);
+		workcpy(&state->last_work, work);
 		// ONLY up to just when it aborted
 		// ONLY up to just when it aborted
 		// We didn't read a reply so we don't subtract ICARUS_READ_TIME
 		// We didn't read a reply so we don't subtract ICARUS_READ_TIME
 		estimate_hashes = ((double)(elapsed.tv_sec)
 		estimate_hashes = ((double)(elapsed.tv_sec)
@@ -898,7 +900,8 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 	curr_hw_errors = icarus->hw_errors;
 	curr_hw_errors = icarus->hw_errors;
 	submit_nonce(thr, &state->last_work, nonce);
 	submit_nonce(thr, &state->last_work, nonce);
 	was_hw_error = (curr_hw_errors > icarus->hw_errors);
 	was_hw_error = (curr_hw_errors > icarus->hw_errors);
-	memcpy(&state->last_work, work, sizeof(state->last_work));
+	clear_work(&state->last_work);
+	workcpy(&state->last_work, work);
 
 
 	// Force a USB close/reopen on any hw error
 	// Force a USB close/reopen on any hw error
 	if (was_hw_error)
 	if (was_hw_error)

+ 2 - 1
driver-modminer.c

@@ -720,8 +720,9 @@ modminer_scanhash(struct thr_info*thr, struct work*work, int64_t __maybe_unused
 		state->work_running = true;
 		state->work_running = true;
 
 
 	if (startwork) {
 	if (startwork) {
+		clear_work(&state->last_work);
 		memcpy(&state->last_work, &state->running_work, sizeof(state->last_work));
 		memcpy(&state->last_work, &state->running_work, sizeof(state->last_work));
-		memcpy(&state->running_work, work, sizeof(state->running_work));
+		workcpy(&state->running_work, work);
 		if (!modminer_start_work(thr))
 		if (!modminer_start_work(thr))
 			return -1;
 			return -1;
 	}
 	}

+ 2 - 1
driver-opencl.c

@@ -1687,7 +1687,8 @@ static void opencl_free_work(struct thr_info *thr, struct work *work)
 
 
 	if (thrdata->res[FOUND]) {
 	if (thrdata->res[FOUND]) {
 		thrdata->last_work = &thrdata->_last_work;
 		thrdata->last_work = &thrdata->_last_work;
-		memcpy(thrdata->last_work, work, sizeof(*thrdata->last_work));
+		clear_work(thrdata->last_work);
+		workcpy(thrdata->last_work, work);
 	}
 	}
 }
 }
 
 

+ 2 - 1
driver-x6500.c

@@ -502,7 +502,8 @@ int64_t x6500_process_results(struct thr_info *thr, struct work *work)
 	dclk_preUpdate(&fpga->dclk);
 	dclk_preUpdate(&fpga->dclk);
 	dclk_updateFreq(&fpga->dclk, x6500_dclk_change_clock, thr);
 	dclk_updateFreq(&fpga->dclk, x6500_dclk_change_clock, thr);
 
 
-	memcpy(&fpga->prevwork, work, sizeof(fpga->prevwork));
+	clear_work(&fpga->prevwork);
+	workcpy(&fpga->prevwork, work);
 
 
 	return hashes;
 	return hashes;
 }
 }

+ 1 - 1
findnonce.c

@@ -180,7 +180,7 @@ void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t *res)
 	}
 	}
 
 
 	pcd->thr = thr;
 	pcd->thr = thr;
-	memcpy(&pcd->work, work, sizeof(struct work));
+	workcpy(&pcd->work, work);
 	memcpy(&pcd->res, res, BUFFERSIZE);
 	memcpy(&pcd->res, res, BUFFERSIZE);
 
 
 	if (pthread_create(&pcd->pth, NULL, postcalc_hash, (void *)pcd)) {
 	if (pthread_create(&pcd->pth, NULL, postcalc_hash, (void *)pcd)) {

+ 5 - 5
miner.c

@@ -2789,8 +2789,6 @@ static void get_benchmark_work(struct work *work)
 	calc_diff(work, 0);
 	calc_diff(work, 0);
 }
 }
 
 
-static void clear_work(struct work *);
-
 static char *prepare_rpc_req(struct work *work, enum pool_protocol proto, const char *lpid)
 static char *prepare_rpc_req(struct work *work, enum pool_protocol proto, const char *lpid)
 {
 {
 	char *rpc_req;
 	char *rpc_req;
@@ -2936,7 +2934,7 @@ static struct work *make_work(void)
 	return work;
 	return work;
 }
 }
 
 
-static void clear_work(struct work *work)
+void clear_work(struct work *work)
 {
 {
 	if (work->tmpl) {
 	if (work->tmpl) {
 		struct pool *pool = work->pool;
 		struct pool *pool = work->pool;
@@ -3292,7 +3290,7 @@ static void roll_work(struct work *work)
 	work->id = total_work++;
 	work->id = total_work++;
 }
 }
 
 
-static void workcpy(struct work *dest, const struct work *work)
+void workcpy(struct work *dest, const struct work *work)
 {
 {
 	memcpy(dest, work, sizeof(*dest));
 	memcpy(dest, work, sizeof(*dest));
 
 
@@ -3623,7 +3621,7 @@ next_submit:
 		char *noncehex;
 		char *noncehex;
 		char s[1024];
 		char s[1024];
 
 
-		memcpy(&sshare->work, work, sizeof(struct work));
+		workcpy(&sshare->work, work);
 		mutex_lock(&sshare_lock);
 		mutex_lock(&sshare_lock);
 		/* Give the stratum share a unique id */
 		/* Give the stratum share a unique id */
 		sshare->id = swork_id++;
 		sshare->id = swork_id++;
@@ -3648,6 +3646,7 @@ next_submit:
 			mutex_lock(&sshare_lock);
 			mutex_lock(&sshare_lock);
 			HASH_DEL(stratum_shares, sshare);
 			HASH_DEL(stratum_shares, sshare);
 			mutex_unlock(&sshare_lock);
 			mutex_unlock(&sshare_lock);
+			clear_work(&sshare->work);
 			free(sshare);
 			free(sshare);
 
 
 			if (!pool_tset(pool, &pool->submit_fail)) {
 			if (!pool_tset(pool, &pool->submit_fail)) {
@@ -5326,6 +5325,7 @@ static bool parse_stratum_response(char *s)
 		goto out;
 		goto out;
 	}
 	}
 	stratum_share_result(val, res_val, err_val, sshare);
 	stratum_share_result(val, res_val, err_val, sshare);
+	clear_work(&sshare->work);
 	free(sshare);
 	free(sshare);
 
 
 	ret = true;
 	ret = true;

+ 2 - 0
miner.h

@@ -1046,6 +1046,8 @@ struct work {
 };
 };
 
 
 extern void get_datestamp(char *, struct timeval *);
 extern void get_datestamp(char *, struct timeval *);
+extern void workcpy(struct work *dest, const struct work *src);
+extern void clear_work(struct work *);
 enum test_nonce2_result {
 enum test_nonce2_result {
 	TNR_GOOD,
 	TNR_GOOD,
 	TNR_HIGH,
 	TNR_HIGH,