grep: remove #ifdef NO_PTHREADS
This is a faithful conversion without attempting to improve anything. That comes later. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Nov 3, 2018 at 09:48 UTC
4002e87cb254298fa2f44b98ee1b618bda0e8b59
3 files changed
+22
-49
builtin/grep.c
+22
-37
@@ -34,7 +34,6 @@ static int recurse_submodules;
34
#define GREP_NUM_THREADS_DEFAULT 8
35
static int num_threads;
36
37
-#ifndef NO_PTHREADS
37
static pthread_t *threads;
38
39
/* We use one producer thread and THREADS consumer
@@ -234,6 +233,9 @@ static int wait_all(void)
233
int hit = 0;
234
int i;
235
236
+ if (!HAVE_THREADS)
237
+ return 0;
238
+
239
grep_lock();
240
all_work_added = 1;
241
@@ -265,13 +267,6 @@ static int wait_all(void)
267
268
return hit;
269
}
268
-#else /* !NO_PTHREADS */
269
-
270
-static int wait_all(void)
271
-{
272
- return 0;
273
-}
274
-#endif
270
271
static int grep_cmd_config(const char *var, const char *value, void *cb)
272
{
@@ -284,8 +279,7 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
279
if (num_threads < 0)
280
die(_("invalid number of threads specified (%d) for %s"),
281
num_threads, var);
287
-#ifdef NO_PTHREADS
288
- else if (num_threads && num_threads != 1) {
282
+ else if (!HAVE_THREADS && num_threads && num_threads != 1) {
283
/*
284
* TRANSLATORS: %s is the configuration
285
* variable for tweaking threads, currently
@@ -294,7 +288,6 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
288
warning(_("no threads support, ignoring %s"), var);
289
num_threads = 0;
290
}
297
-#endif
291
}
292
293
if (!strcmp(var, "submodule.recurse"))
@@ -330,17 +323,14 @@ static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
323
grep_source_init(&gs, GREP_SOURCE_OID, pathbuf.buf, path, oid);
324
strbuf_release(&pathbuf);
325
333
-#ifndef NO_PTHREADS
334
- if (num_threads) {
326
+ if (HAVE_THREADS && num_threads) {
327
/*
328
* add_work() copies gs and thus assumes ownership of
329
* its fields, so do not call grep_source_clear()
330
*/
331
add_work(opt, &gs);
332
return 0;
341
- } else
342
-#endif
343
- {
333
+ } else {
334
int hit;
335
336
hit = grep_source(opt, &gs);
@@ -363,17 +353,14 @@ static int grep_file(struct grep_opt *opt, const char *filename)
353
grep_source_init(&gs, GREP_SOURCE_FILE, buf.buf, filename, filename);
354
strbuf_release(&buf);
355
366
-#ifndef NO_PTHREADS
367
- if (num_threads) {
356
+ if (HAVE_THREADS && num_threads) {
357
/*
358
* add_work() copies gs and thus assumes ownership of
359
* its fields, so do not call grep_source_clear()
360
*/
361
add_work(opt, &gs);
362
return 0;
374
- } else
375
-#endif
376
- {
363
+ } else {
364
int hit;
365
366
hit = grep_source(opt, &gs);
@@ -1038,20 +1025,20 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1025
pathspec.recursive = 1;
1026
pathspec.recurse_submodules = !!recurse_submodules;
1027
1041
-#ifndef NO_PTHREADS
1042
- if (list.nr || cached || show_in_pager)
1043
- num_threads = 0;
1044
- else if (num_threads == 0)
1045
- num_threads = GREP_NUM_THREADS_DEFAULT;
1046
- else if (num_threads < 0)
1047
- die(_("invalid number of threads specified (%d)"), num_threads);
1048
- if (num_threads == 1)
1028
+ if (HAVE_THREADS) {
1029
+ if (list.nr || cached || show_in_pager)
1030
+ num_threads = 0;
1031
+ else if (num_threads == 0)
1032
+ num_threads = GREP_NUM_THREADS_DEFAULT;
1033
+ else if (num_threads < 0)
1034
+ die(_("invalid number of threads specified (%d)"), num_threads);
1035
+ if (num_threads == 1)
1036
+ num_threads = 0;
1037
+ } else {
1038
+ if (num_threads)
1039
+ warning(_("no threads support, ignoring --threads"));
1040
num_threads = 0;
1050
-#else
1051
- if (num_threads)
1052
- warning(_("no threads support, ignoring --threads"));
1053
- num_threads = 0;
1054
-#endif
1041
+ }
1042
1043
if (!num_threads)
1044
/*
@@ -1062,15 +1049,13 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1049
*/
1050
compile_grep_patterns(&opt);
1051
1065
-#ifndef NO_PTHREADS
1066
- if (num_threads) {
1052
+ if (HAVE_THREADS && num_threads) {
1053
if (!(opt.name_only || opt.unmatch_name_only || opt.count)
1054
&& (opt.pre_context || opt.post_context ||
1055
opt.file_break || opt.funcbody))
1056
skip_first_line = 1;
1057
start_threads(&opt);
1058
}
1073
-#endif
1059
1060
if (show_in_pager && (cached || list.nr))
1061
die(_("--open-files-in-pager only works on the worktree"));
grep.c
-6
@@ -1513,7 +1513,6 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
1513
}
1514
}
1515
1516
-#ifndef NO_PTHREADS
1516
int grep_use_locks;
1517
1518
/*
@@ -1539,11 +1538,6 @@ static inline void grep_attr_unlock(void)
1538
*/
1539
pthread_mutex_t grep_read_mutex;
1540
1542
-#else
1543
-#define grep_attr_lock()
1544
-#define grep_attr_unlock()
1545
-#endif
1546
-
1541
static int match_funcname(struct grep_opt *opt, struct grep_source *gs, char *bol, char *eol)
1542
{
1543
xdemitconf_t *xecfg = opt->priv;
grep.h
-6
@@ -229,7 +229,6 @@ int grep_source(struct grep_opt *opt, struct grep_source *gs);
229
extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt);
230
extern int grep_threads_ok(const struct grep_opt *opt);
231
232
-#ifndef NO_PTHREADS
232
/*
233
* Mutex used around access to the attributes machinery if
234
* opt->use_threads. Must be initialized/destroyed by callers!
@@ -250,9 +249,4 @@ static inline void grep_read_unlock(void)
249
pthread_mutex_unlock(&grep_read_mutex);
250
}
251
253
-#else
254
-#define grep_read_lock()
255
-#define grep_read_unlock()
256
-#endif
257
-
252
#endif