Browse code

Store choices on job struct

John Hawthorn authored on 08/01/2017 09:04:34
Showing 1 changed files

... ...
@@ -139,12 +139,12 @@ size_t choices_available(choices_t *c) {
139 139
 }
140 140
 
141 141
 struct search_job {
142
+	choices_t *choices;
142 143
 	const char *search;
143 144
 };
144 145
 
145 146
 struct worker {
146 147
 	pthread_t thread_id;
147
-	choices_t *choices;
148 148
 	struct search_job *job;
149 149
 	size_t worker_num;
150 150
 	struct scored_result *results;
... ...
@@ -154,7 +154,7 @@ struct worker {
154 154
 static void *choices_search_worker(void *data) {
155 155
 	struct worker *w = (struct worker *)data;
156 156
 	struct search_job *job = w->job;
157
-	const choices_t *c = w->choices;
157
+	const choices_t *c = job->choices;
158 158
 
159 159
 	size_t start = (w->worker_num) * c->size / c->worker_count;
160 160
 	size_t end = (w->worker_num + 1) * c->size / c->worker_count;
... ...
@@ -175,6 +175,7 @@ void choices_search(choices_t *c, const char *search) {
175 175
 
176 176
 	struct search_job *job = calloc(1, sizeof(struct search_job));
177 177
 	job->search = search;
178
+	job->choices = c;
178 179
 
179 180
 	/* allocate storage for our results */
180 181
 	c->results = malloc(c->size * sizeof(struct scored_result));
... ...
@@ -185,7 +186,6 @@ void choices_search(choices_t *c, const char *search) {
185 186
 
186 187
 	struct worker *workers = calloc(c->worker_count, sizeof(struct worker));
187 188
 	for (unsigned int i = 0; i < c->worker_count; i++) {
188
-		workers[i].choices = c;
189 189
 		workers[i].job = job;
190 190
 		workers[i].worker_num = i;
191 191
 		workers[i].results = malloc(c->size * sizeof(struct scored_result)); /* FIXME: This is overkill */