Skip to content

Commit e4da4fb

Browse files
committed
Merge branch 'eb/no-pthreads'
Allow us build with NO_PTHREADS=NoThanks compilation option. * eb/no-pthreads: Handle atexit list internaly for unthreaded builds pack-objects: set number of threads before checking and warning index-pack: fix compilation with NO_PTHREADS
2 parents bb8caad + 0f4b6db commit e4da4fb

File tree

7 files changed

+58
-12
lines changed

7 files changed

+58
-12
lines changed

builtin/clone.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ static void clone_local(const char *src_repo, const char *dest_repo)
391391

392392
static const char *junk_work_tree;
393393
static const char *junk_git_dir;
394-
static pid_t junk_pid;
395394
static enum {
396395
JUNK_LEAVE_NONE,
397396
JUNK_LEAVE_REPO,
@@ -418,8 +417,6 @@ static void remove_junk(void)
418417
break;
419418
}
420419

421-
if (getpid() != junk_pid)
422-
return;
423420
if (junk_git_dir) {
424421
strbuf_addstr(&sb, junk_git_dir);
425422
remove_dir_recursively(&sb, 0);
@@ -760,8 +757,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
760757
struct refspec *refspec;
761758
const char *fetch_pattern;
762759

763-
junk_pid = getpid();
764-
765760
packet_trace_identity("clone");
766761
argc = parse_options(argc, argv, prefix, builtin_clone_options,
767762
builtin_clone_usage, 0);

builtin/index-pack.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ static void cleanup_thread(void)
185185
#define deepest_delta_lock()
186186
#define deepest_delta_unlock()
187187

188+
#define type_cas_lock()
189+
#define type_cas_unlock()
190+
188191
#endif
189192

190193

builtin/pack-objects.c

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

19741974
init_threaded_search();
19751975

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

git-compat-util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,11 @@ int inet_pton(int af, const char *src, void *dst);
596596
const char *inet_ntop(int af, const void *src, char *dst, size_t size);
597597
#endif
598598

599+
#ifdef NO_PTHREADS
600+
#define atexit git_atexit
601+
extern int git_atexit(void (*handler)(void));
602+
#endif
603+
599604
extern void release_pack_memory(size_t);
600605

601606
typedef void (*try_to_free_t)(size_t);

run-command.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,45 @@ static int async_die_is_recursing(void)
626626
return ret != NULL;
627627
}
628628

629+
#else
630+
631+
static struct {
632+
void (**handlers)(void);
633+
size_t nr;
634+
size_t alloc;
635+
} git_atexit_hdlrs;
636+
637+
static int git_atexit_installed;
638+
639+
static void git_atexit_dispatch()
640+
{
641+
size_t i;
642+
643+
for (i=git_atexit_hdlrs.nr ; i ; i--)
644+
git_atexit_hdlrs.handlers[i-1]();
645+
}
646+
647+
static void git_atexit_clear()
648+
{
649+
free(git_atexit_hdlrs.handlers);
650+
memset(&git_atexit_hdlrs, 0, sizeof(git_atexit_hdlrs));
651+
git_atexit_installed = 0;
652+
}
653+
654+
#undef atexit
655+
int git_atexit(void (*handler)(void))
656+
{
657+
ALLOC_GROW(git_atexit_hdlrs.handlers, git_atexit_hdlrs.nr + 1, git_atexit_hdlrs.alloc);
658+
git_atexit_hdlrs.handlers[git_atexit_hdlrs.nr++] = handler;
659+
if (!git_atexit_installed) {
660+
if (atexit(&git_atexit_dispatch))
661+
return -1;
662+
git_atexit_installed = 1;
663+
}
664+
return 0;
665+
}
666+
#define atexit git_atexit
667+
629668
#endif
630669

631670
int start_async(struct async *async)
@@ -684,6 +723,7 @@ int start_async(struct async *async)
684723
close(fdin[1]);
685724
if (need_out)
686725
close(fdout[0]);
726+
git_atexit_clear();
687727
exit(!!async->proc(proc_in, proc_out, async->data));
688728
}
689729

shallow.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ static void remove_temporary_shallow_on_signal(int signo)
227227

228228
const char *setup_temporary_shallow(const struct sha1_array *extra)
229229
{
230-
static int installed_handler;
231230
struct strbuf sb = STRBUF_INIT;
232231
int fd;
233232

@@ -238,10 +237,8 @@ const char *setup_temporary_shallow(const struct sha1_array *extra)
238237
strbuf_addstr(&temporary_shallow, git_path("shallow_XXXXXX"));
239238
fd = xmkstemp(temporary_shallow.buf);
240239

241-
if (!installed_handler) {
242-
atexit(remove_temporary_shallow);
243-
sigchain_push_common(remove_temporary_shallow_on_signal);
244-
}
240+
atexit(remove_temporary_shallow);
241+
sigchain_push_common(remove_temporary_shallow_on_signal);
245242

246243
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
247244
die_errno("failed to write to %s",

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)