| 225 | } |
| 226 | |
| 227 | static void start_threads(struct grep_opt *opt) |
| 228 | { |
| 229 | int i; |
| 230 | |
| 231 | pthread_mutex_init(&grep_mutex, NULL); |
| 232 | pthread_mutex_init(&grep_attr_mutex, NULL); |
| 233 | pthread_cond_init(&cond_add, NULL); |
| 234 | pthread_cond_init(&cond_write, NULL); |
| 235 | pthread_cond_init(&cond_result, NULL); |
| 236 | grep_use_locks = 1; |
| 237 | enable_obj_read_lock(); |
| 238 | |
| 239 | for (i = 0; i < ARRAY_SIZE(todo); i++) { |
| 240 | strbuf_init(&todo[i].out, 0); |
| 241 | } |
| 242 | |
| 243 | CALLOC_ARRAY(threads, num_threads); |
| 244 | for (i = 0; i < num_threads; i++) { |
| 245 | int err; |
| 246 | struct grep_opt *o = grep_opt_dup(opt); |
| 247 | o->output = strbuf_out; |
| 248 | compile_grep_patterns(o); |
| 249 | err = pthread_create(&threads[i], NULL, run, o); |
| 250 | |
| 251 | if (err) |
| 252 | die(_("grep: failed to create thread: %s"), |
| 253 | strerror(err)); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | static int wait_all(void) |
| 258 | { |
no test coverage detected