Merge branch 'nd/pthreads'
The codebase has been cleaned up to reduce "#ifndef NO_PTHREADS". * nd/pthreads: Clean up pthread_create() error handling read-cache.c: initialize copy_len to shut up gcc 8 read-cache.c: reduce branching based on HAVE_THREADS read-cache.c: remove #ifdef NO_PTHREADS pack-objects: remove #ifdef NO_PTHREADS preload-index.c: remove #ifdef NO_PTHREADS grep: clean up num_threads handling grep: remove #ifdef NO_PTHREADS attr.c: remove #ifdef NO_PTHREADS name-hash.c: remove #ifdef NO_PTHREADS index-pack: remove #ifdef NO_PTHREADS send-pack.c: move async's #ifdef NO_PTHREADS back to run-command.c run-command.h: include thread-utils.h instead of pthread.h thread-utils: macros to unconditionally compile pthreads API
This commit is contained in:
@ -34,7 +34,6 @@ static int recurse_submodules;
|
||||
#define GREP_NUM_THREADS_DEFAULT 8
|
||||
static int num_threads;
|
||||
|
||||
#ifndef NO_PTHREADS
|
||||
static pthread_t *threads;
|
||||
|
||||
/* We use one producer thread and THREADS consumer
|
||||
@ -70,13 +69,11 @@ static pthread_mutex_t grep_mutex;
|
||||
|
||||
static inline void grep_lock(void)
|
||||
{
|
||||
assert(num_threads);
|
||||
pthread_mutex_lock(&grep_mutex);
|
||||
}
|
||||
|
||||
static inline void grep_unlock(void)
|
||||
{
|
||||
assert(num_threads);
|
||||
pthread_mutex_unlock(&grep_mutex);
|
||||
}
|
||||
|
||||
@ -234,6 +231,9 @@ static int wait_all(void)
|
||||
int hit = 0;
|
||||
int i;
|
||||
|
||||
if (!HAVE_THREADS)
|
||||
BUG("Never call this function unless you have started threads");
|
||||
|
||||
grep_lock();
|
||||
all_work_added = 1;
|
||||
|
||||
@ -265,13 +265,6 @@ static int wait_all(void)
|
||||
|
||||
return hit;
|
||||
}
|
||||
#else /* !NO_PTHREADS */
|
||||
|
||||
static int wait_all(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int grep_cmd_config(const char *var, const char *value, void *cb)
|
||||
{
|
||||
@ -284,17 +277,15 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
|
||||
if (num_threads < 0)
|
||||
die(_("invalid number of threads specified (%d) for %s"),
|
||||
num_threads, var);
|
||||
#ifdef NO_PTHREADS
|
||||
else if (num_threads && num_threads != 1) {
|
||||
else if (!HAVE_THREADS && num_threads > 1) {
|
||||
/*
|
||||
* TRANSLATORS: %s is the configuration
|
||||
* variable for tweaking threads, currently
|
||||
* grep.threads
|
||||
*/
|
||||
warning(_("no threads support, ignoring %s"), var);
|
||||
num_threads = 0;
|
||||
num_threads = 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!strcmp(var, "submodule.recurse"))
|
||||
@ -330,17 +321,14 @@ static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
|
||||
grep_source_init(&gs, GREP_SOURCE_OID, pathbuf.buf, path, oid);
|
||||
strbuf_release(&pathbuf);
|
||||
|
||||
#ifndef NO_PTHREADS
|
||||
if (num_threads) {
|
||||
if (num_threads > 1) {
|
||||
/*
|
||||
* add_work() copies gs and thus assumes ownership of
|
||||
* its fields, so do not call grep_source_clear()
|
||||
*/
|
||||
add_work(opt, &gs);
|
||||
return 0;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
} else {
|
||||
int hit;
|
||||
|
||||
hit = grep_source(opt, &gs);
|
||||
@ -363,17 +351,14 @@ static int grep_file(struct grep_opt *opt, const char *filename)
|
||||
grep_source_init(&gs, GREP_SOURCE_FILE, buf.buf, filename, filename);
|
||||
strbuf_release(&buf);
|
||||
|
||||
#ifndef NO_PTHREADS
|
||||
if (num_threads) {
|
||||
if (num_threads > 1) {
|
||||
/*
|
||||
* add_work() copies gs and thus assumes ownership of
|
||||
* its fields, so do not call grep_source_clear()
|
||||
*/
|
||||
add_work(opt, &gs);
|
||||
return 0;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
} else {
|
||||
int hit;
|
||||
|
||||
hit = grep_source(opt, &gs);
|
||||
@ -1049,39 +1034,35 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
|
||||
pathspec.recursive = 1;
|
||||
pathspec.recurse_submodules = !!recurse_submodules;
|
||||
|
||||
#ifndef NO_PTHREADS
|
||||
if (list.nr || cached || show_in_pager)
|
||||
num_threads = 0;
|
||||
else if (num_threads == 0)
|
||||
num_threads = GREP_NUM_THREADS_DEFAULT;
|
||||
else if (num_threads < 0)
|
||||
die(_("invalid number of threads specified (%d)"), num_threads);
|
||||
if (num_threads == 1)
|
||||
num_threads = 0;
|
||||
#else
|
||||
if (num_threads)
|
||||
if (list.nr || cached || show_in_pager) {
|
||||
if (num_threads > 1)
|
||||
warning(_("invalid option combination, ignoring --threads"));
|
||||
num_threads = 1;
|
||||
} else if (!HAVE_THREADS && num_threads > 1) {
|
||||
warning(_("no threads support, ignoring --threads"));
|
||||
num_threads = 0;
|
||||
#endif
|
||||
num_threads = 1;
|
||||
} else if (num_threads < 0)
|
||||
die(_("invalid number of threads specified (%d)"), num_threads);
|
||||
else if (num_threads == 0)
|
||||
num_threads = HAVE_THREADS ? GREP_NUM_THREADS_DEFAULT : 1;
|
||||
|
||||
if (!num_threads)
|
||||
/*
|
||||
* The compiled patterns on the main path are only
|
||||
* used when not using threading. Otherwise
|
||||
* start_threads() below calls compile_grep_patterns()
|
||||
* for each thread.
|
||||
*/
|
||||
compile_grep_patterns(&opt);
|
||||
|
||||
#ifndef NO_PTHREADS
|
||||
if (num_threads) {
|
||||
if (num_threads > 1) {
|
||||
if (!HAVE_THREADS)
|
||||
BUG("Somebody got num_threads calculation wrong!");
|
||||
if (!(opt.name_only || opt.unmatch_name_only || opt.count)
|
||||
&& (opt.pre_context || opt.post_context ||
|
||||
opt.file_break || opt.funcbody))
|
||||
skip_first_line = 1;
|
||||
start_threads(&opt);
|
||||
} else {
|
||||
/*
|
||||
* The compiled patterns on the main path are only
|
||||
* used when not using threading. Otherwise
|
||||
* start_threads() above calls compile_grep_patterns()
|
||||
* for each thread.
|
||||
*/
|
||||
compile_grep_patterns(&opt);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (show_in_pager && (cached || list.nr))
|
||||
die(_("--open-files-in-pager only works on the worktree"));
|
||||
@ -1132,7 +1113,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
|
||||
hit = grep_objects(&opt, &pathspec, &list);
|
||||
}
|
||||
|
||||
if (num_threads)
|
||||
if (num_threads > 1)
|
||||
hit |= wait_all();
|
||||
if (hit && show_in_pager)
|
||||
run_pager(&opt, prefix);
|
||||
|
Reference in New Issue
Block a user