Skip to content

Commit 0c45d25

Browse files
committed
pack-objects: set number of threads before checking and warning
Under NO_PTHREADS build, we warn when delta_search_threads is not set to 1, because that is the only sensible value on a single threaded build. However, the auto detection that kicks in when that variable is set to 0 (e.g. there is no configuration variable or command line option, or an explicit --threads=0 is given from the command line to override the pack.threads configuration to force auto-detection) was not done before the condition to issue this warning was tested. Move the auto-detection code and place it at an appropriate spot. Signed-off-by: Junio C Hamano <[email protected]>
1 parent e0e2128 commit 0c45d25

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

builtin/pack-objects.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,8 +1972,6 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
19721972

19731973
init_threaded_search();
19741974

1975-
if (!delta_search_threads) /* --threads=0 means autodetect */
1976-
delta_search_threads = online_cpus();
19771975
if (delta_search_threads <= 1) {
19781976
find_deltas(list, &list_size, window, depth, processed);
19791977
cleanup_threaded_search();
@@ -2685,6 +2683,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
26852683
pack_compression_level = Z_DEFAULT_COMPRESSION;
26862684
else if (pack_compression_level < 0 || pack_compression_level > Z_BEST_COMPRESSION)
26872685
die("bad pack compression level %d", pack_compression_level);
2686+
2687+
if (!delta_search_threads) /* --threads=0 means autodetect */
2688+
delta_search_threads = online_cpus();
2689+
26882690
#ifdef NO_PTHREADS
26892691
if (delta_search_threads != 1)
26902692
warning("no threads support, ignoring --threads");

thread-utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@
77
extern int online_cpus(void);
88
extern int init_recursive_mutex(pthread_mutex_t*);
99

10+
#else
11+
12+
#define online_cpus() 1
13+
1014
#endif
1115
#endif /* THREAD_COMPAT_H */

0 commit comments

Comments
 (0)