Browse Source

(Partial Cherrypick) Bugfix: Use clear_work and workdup everywhere work is copied around

Luke Dashjr 13 years ago
parent
commit
d193f06fe6
6 changed files with 15 additions and 10 deletions
  1. 6 3
      driver-icarus.c
  2. 2 1
      driver-modminer.c
  3. 2 1
      driver-opencl.c
  4. 1 1
      findnonce.c
  5. 2 4
      miner.c
  6. 2 0
      miner.h

+ 6 - 3
driver-icarus.c

@@ -871,7 +871,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;
 	}
 	}
 
 
@@ -879,7 +880,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)
@@ -903,7 +905,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

@@ -757,8 +757,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

@@ -1726,7 +1726,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);
 	}
 	}
 }
 }
 
 

+ 1 - 1
findnonce.c

@@ -179,7 +179,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)) {

+ 2 - 4
miner.c

@@ -2546,8 +2546,6 @@ static void get_benchmark_work(struct work *work)
 	calc_diff(work);
 	calc_diff(work);
 }
 }
 
 
-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;
@@ -2693,7 +2691,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;
@@ -3014,7 +3012,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));
 
 

+ 2 - 0
miner.h

@@ -949,6 +949,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,