diff options
-rw-r--r-- | src/choices.c | 6 | ||||
-rw-r--r-- | src/options.c | 10 | ||||
-rw-r--r-- | src/options.h | 1 |
3 files changed, 15 insertions, 2 deletions
diff --git a/src/choices.c b/src/choices.c index 01480cb..64f9a8b 100644 --- a/src/choices.c +++ b/src/choices.c @@ -107,7 +107,11 @@ void choices_init(choices_t *c, options_t *options) { c->capacity = c->size = 0; choices_resize(c, INITIAL_CHOICE_CAPACITY); - c->worker_count = (int)sysconf(_SC_NPROCESSORS_ONLN); + if (options->workers) { + c->worker_count = options->workers; + } else { + c->worker_count = (int)sysconf(_SC_NPROCESSORS_ONLN); + } choices_reset_search(c); } diff --git a/src/options.c b/src/options.c index 41dbba1..1ef1550 100644 --- a/src/options.c +++ b/src/options.c @@ -15,6 +15,7 @@ static const char *usage_str = " -e, --show-matches=QUERY Output the sorted matches of QUERY\n" " -t, --tty=TTY Specify file to use as TTY device (default /dev/tty)\n" " -s, --show-scores Show the scores of each match\n" + " -j, --workers NUM Use NUM workers for searching. (default is number of CPU threads)\n" " -h, --help Display this help and exit\n" " -v, --version Output version information and exit\n"; @@ -44,13 +45,14 @@ void options_init(options_t *options) { options->num_lines = 10; options->scrolloff = 1; options->prompt = "> "; + options->workers = 0; } void options_parse(options_t *options, int argc, char *argv[]) { options_init(options); int c; - while ((c = getopt_long(argc, argv, "vhse:q:l:t:p:", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "vhse:q:l:t:p:j:", longopts, NULL)) != -1) { switch (c) { case 'v': printf("%s " VERSION " (c) 2014 John Hawthorn\n", argv[0]); @@ -80,6 +82,12 @@ void options_parse(options_t *options, int argc, char *argv[]) { case 'p': options->prompt = optarg; break; + case 'j': + if (sscanf(optarg, "%u", &options->workers) != 1) { + usage(argv[0]); + exit(EXIT_FAILURE); + } + break; case 'l': { int l; if (!strcmp(optarg, "max")) { diff --git a/src/options.h b/src/options.h index f8a44a0..01a43fd 100644 --- a/src/options.h +++ b/src/options.h @@ -10,6 +10,7 @@ typedef struct { unsigned int num_lines; unsigned int scrolloff; const char *prompt; + unsigned int workers; } options_t; void options_init(options_t *options); |