Clearly delineate the cpus from the gpus for their local data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
diff --git a/cpu-miner.c b/cpu-miner.c
index 5777bce..0428610 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -1277,9 +1277,10 @@ int main (int argc, char *argv[])
struct thr_info *thr;
unsigned int i;
char name[32];
+ struct cgpu_info *gpus, *cpus;
#ifdef WIN32
- opt_n_threads = 1;
+ opt_n_threads = num_processors = 1;
#else
num_processors = sysconf(_SC_NPROCESSORS_ONLN);
opt_n_threads = num_processors;
@@ -1376,22 +1377,30 @@ int main (int argc, char *argv[])
gettimeofday(&total_tv_start, NULL);
gettimeofday(&total_tv_end, NULL);
+ if (opt_n_threads ) {
+ cpus = calloc(num_processors, sizeof(struct cgpu_info));
+ if (unlikely(!cpus)) {
+ applog(LOG_ERR, "Failed to calloc cpus");
+ return 1;
+ }
+ }
+ if (gpu_threads) {
+ gpus = calloc(nDevs, sizeof(struct cgpu_info));
+ if (unlikely(!gpus)) {
+ applog(LOG_ERR, "Failed to calloc gpus");
+ return 1;
+ }
+ }
+
/* start GPU mining threads */
for (i = 0; i < gpu_threads; i++) {
int gpu = gpu_from_thr_id(i);
thr = &thr_info[i];
thr->id = i;
- if (!thr->cgpu) {
- thr->cgpu = calloc(1, sizeof(struct cgpu_info));
- if (unlikely(!thr->cgpu)) {
- applog(LOG_ERR, "Failed to calloc cgpu_info");
- return 1;
- }
- thr->cgpu->is_gpu = 1;
- thr->cgpu->cpu_gpu = gpu;
- } else
- thr->cgpu = thr_info[gpu].cgpu;
+ gpus[gpu].is_gpu = 1;
+ gpus[gpu].cpu_gpu = gpu;
+ thr->cgpu = &gpus[gpu];
thr->q = tq_new();
if (!thr->q) {
@@ -1423,15 +1432,8 @@ int main (int argc, char *argv[])
thr = &thr_info[i];
thr->id = i;
- if (!thr->cgpu) {
- thr->cgpu = calloc(1, sizeof(struct cgpu_info));
- if (unlikely(!thr->cgpu)) {
- applog(LOG_ERR, "Failed to calloc cgpu_info");
- return 1;
- }
- thr->cgpu->cpu_gpu = cpu;
- } else
- thr->cgpu = thr_info[cpu].cgpu;
+ cpus[cpu].cpu_gpu = cpu;
+ thr->cgpu = &cpus[cpu];
thr->q = tq_new();
if (!thr->q) {
@@ -1463,6 +1465,10 @@ int main (int argc, char *argv[])
/* main loop - simply wait for workio thread to exit */
pthread_join(thr_info[work_thr_id].pth, NULL);
curl_global_cleanup();
+ if (gpu_threads)
+ free(gpus);
+ if (opt_n_threads)
+ free(cpus);
applog(LOG_INFO, "workio thread dead, exiting.");