Browse Source

Move cgpu_info and thr_info initialization to main, and ensure all get initialized before starting any threads

Luke Dashjr 13 years ago
parent
commit
cba42369d9
1 changed files with 12 additions and 8 deletions
  1. 12 8
      miner.c

+ 12 - 8
miner.c

@@ -6747,13 +6747,6 @@ void *miner_thread(void *userdata)
 	snprintf(threadname, 20, "miner_%s", cgpu->proc_repr_ns);
 	snprintf(threadname, 20, "miner_%s", cgpu->proc_repr_ns);
 	RenameThread(threadname);
 	RenameThread(threadname);
 
 
-	// FIXME: initialize all cgpus and virtual threads
-	cgpu->max_hashes = 0;
-	mythr->scanhash_working = true;
-	mythr->hashes_done = 0;
-	timerclear(&mythr->tv_hashes_done);
-	gettimeofday(&mythr->tv_lastupdate, NULL);
-
 	if (api->thread_init && !api->thread_init(mythr)) {
 	if (api->thread_init && !api->thread_init(mythr)) {
 		// FIXME: Should affect all processors managed
 		// FIXME: Should affect all processors managed
 		dev_error(cgpu, REASON_THREAD_FAIL_INIT);
 		dev_error(cgpu, REASON_THREAD_FAIL_INIT);
@@ -8294,7 +8287,7 @@ begin_bench:
 		localtime_r(&miner_started.tv_sec, &schedstop .tm);
 		localtime_r(&miner_started.tv_sec, &schedstop .tm);
 	get_datestamp(datestamp, &total_tv_start);
 	get_datestamp(datestamp, &total_tv_start);
 
 
-	// Start threads
+	// Initialise processors and threads
 	k = 0;
 	k = 0;
 	for (i = 0; i < total_devices; ++i) {
 	for (i = 0; i < total_devices; ++i) {
 		struct cgpu_info *cgpu = devices[i];
 		struct cgpu_info *cgpu = devices[i];
@@ -8302,6 +8295,8 @@ begin_bench:
 		cgpu->thr[cgpu->threads] = NULL;
 		cgpu->thr[cgpu->threads] = NULL;
 		cgpu->status = LIFE_INIT;
 		cgpu->status = LIFE_INIT;
 
 
+		cgpu->max_hashes = 0;
+
 		// Setup thread structs before starting any of the threads, in case they try to interact
 		// Setup thread structs before starting any of the threads, in case they try to interact
 		for (j = 0; j < cgpu->threads; ++j, ++k) {
 		for (j = 0; j < cgpu->threads; ++j, ++k) {
 			thr = &thr_info[k];
 			thr = &thr_info[k];
@@ -8310,6 +8305,11 @@ begin_bench:
 			thr->device_thread = j;
 			thr->device_thread = j;
 			thr->work_restart_fd = thr->_work_restart_fd_w = -1;
 			thr->work_restart_fd = thr->_work_restart_fd_w = -1;
 
 
+			thr->scanhash_working = true;
+			thr->hashes_done = 0;
+			timerclear(&thr->tv_hashes_done);
+			gettimeofday(&thr->tv_lastupdate, NULL);
+
 			thr->q = tq_new();
 			thr->q = tq_new();
 			if (!thr->q)
 			if (!thr->q)
 				quit(1, "tq_new failed in starting %"PRIpreprv" mining thread (#%d)", cgpu->proc_repr, i);
 				quit(1, "tq_new failed in starting %"PRIpreprv" mining thread (#%d)", cgpu->proc_repr, i);
@@ -8324,7 +8324,11 @@ begin_bench:
 
 
 			cgpu->thr[j] = thr;
 			cgpu->thr[j] = thr;
 		}
 		}
+	}
 
 
+	// Start threads
+	for (i = 0; i < total_devices; ++i) {
+		struct cgpu_info *cgpu = devices[i];
 		for (j = 0; j < cgpu->threads; ++j) {
 		for (j = 0; j < cgpu->threads; ++j) {
 			thr = cgpu->thr[j];
 			thr = cgpu->thr[j];