Browse code

Use threading when matching/scoring

John Hawthorn authored on 23/06/2016 04:43:37
Showing 1 changed files

... ...
@@ -1,6 +1,7 @@
1 1
 #include <stdlib.h>
2 2
 #include <stdio.h>
3 3
 #include <string.h>
4
+#include <pthread.h>
4 5
 
5 6
 #include "choices.h"
6 7
 #include "match.h"
... ...
@@ -134,8 +135,6 @@ size_t choices_available(choices_t *c) {
134 135
 	return c->available;
135 136
 }
136 137
 
137
-#include <pthread.h>
138
-
139 138
 struct worker {
140 139
 	pthread_t thread_id;
141 140
 	choices_t *choices;
... ...
@@ -182,8 +181,7 @@ void choices_search(choices_t *c, const char *search) {
182 181
 		workers[i].worker_count = worker_count;
183 182
 		workers[i].worker_num = i;
184 183
 		workers[i].results = malloc(c->size * sizeof(struct scored_result)); /* FIXME: This is overkill */
185
-		int ret = pthread_create(&workers[i].thread_id, NULL, &choices_search_worker, &workers[i]);
186
-		if (ret != 0) {
184
+		if (pthread_create(&workers[i].thread_id, NULL, &choices_search_worker, &workers[i])) {
187 185
 			perror("pthread_create");
188 186
 			exit(EXIT_FAILURE);
189 187
 		}
... ...
@@ -192,8 +190,7 @@ void choices_search(choices_t *c, const char *search) {
192 190
 	for (int i = 0; i < worker_count; i++) {
193 191
 		struct worker *w = &workers[i];
194 192
 
195
-		int ret = pthread_join(w->thread_id, NULL);
196
-		if (ret != 0) {
193
+		if (pthread_join(w->thread_id, NULL)) {
197 194
 			perror("pthread_join");
198 195
 			exit(EXIT_FAILURE);
199 196
 		}