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
This commit is contained in:
Junio C Hamano 2014-10-24 14:59:10 -07:00
commit e4da4fbe0e
7 changed files with 58 additions and 12 deletions

View File

@ -391,7 +391,6 @@ static void clone_local(const char *src_repo, const char *dest_repo)
static const char *junk_work_tree;
static const char *junk_git_dir;
static pid_t junk_pid;
static enum {
JUNK_LEAVE_NONE,
JUNK_LEAVE_REPO,
@ -418,8 +417,6 @@ static void remove_junk(void)
break;
}
if (getpid() != junk_pid)
return;
if (junk_git_dir) {
strbuf_addstr(&sb, junk_git_dir);
remove_dir_recursively(&sb, 0);
@ -760,8 +757,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
struct refspec *refspec;
const char *fetch_pattern;
junk_pid = getpid();
packet_trace_identity("clone");
argc = parse_options(argc, argv, prefix, builtin_clone_options,
builtin_clone_usage, 0);

View File

@ -185,6 +185,9 @@ static void cleanup_thread(void)
#define deepest_delta_lock()
#define deepest_delta_unlock()
#define type_cas_lock()
#define type_cas_unlock()
#endif

View File

@ -1973,8 +1973,6 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
init_threaded_search();
if (!delta_search_threads) /* --threads=0 means autodetect */
delta_search_threads = online_cpus();
if (delta_search_threads <= 1) {
find_deltas(list, &list_size, window, depth, processed);
cleanup_threaded_search();
@ -2686,6 +2684,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
pack_compression_level = Z_DEFAULT_COMPRESSION;
else if (pack_compression_level < 0 || pack_compression_level > Z_BEST_COMPRESSION)
die("bad pack compression level %d", pack_compression_level);
if (!delta_search_threads) /* --threads=0 means autodetect */
delta_search_threads = online_cpus();
#ifdef NO_PTHREADS
if (delta_search_threads != 1)
warning("no threads support, ignoring --threads");

View File

@ -596,6 +596,11 @@ int inet_pton(int af, const char *src, void *dst);
const char *inet_ntop(int af, const void *src, char *dst, size_t size);
#endif
#ifdef NO_PTHREADS
#define atexit git_atexit
extern int git_atexit(void (*handler)(void));
#endif
extern void release_pack_memory(size_t);
typedef void (*try_to_free_t)(size_t);

View File

@ -626,6 +626,45 @@ static int async_die_is_recursing(void)
return ret != NULL;
}
#else
static struct {
void (**handlers)(void);
size_t nr;
size_t alloc;
} git_atexit_hdlrs;
static int git_atexit_installed;
static void git_atexit_dispatch()
{
size_t i;
for (i=git_atexit_hdlrs.nr ; i ; i--)
git_atexit_hdlrs.handlers[i-1]();
}
static void git_atexit_clear()
{
free(git_atexit_hdlrs.handlers);
memset(&git_atexit_hdlrs, 0, sizeof(git_atexit_hdlrs));
git_atexit_installed = 0;
}
#undef atexit
int git_atexit(void (*handler)(void))
{
ALLOC_GROW(git_atexit_hdlrs.handlers, git_atexit_hdlrs.nr + 1, git_atexit_hdlrs.alloc);
git_atexit_hdlrs.handlers[git_atexit_hdlrs.nr++] = handler;
if (!git_atexit_installed) {
if (atexit(&git_atexit_dispatch))
return -1;
git_atexit_installed = 1;
}
return 0;
}
#define atexit git_atexit
#endif
int start_async(struct async *async)
@ -684,6 +723,7 @@ int start_async(struct async *async)
close(fdin[1]);
if (need_out)
close(fdout[0]);
git_atexit_clear();
exit(!!async->proc(proc_in, proc_out, async->data));
}

View File

@ -227,7 +227,6 @@ static void remove_temporary_shallow_on_signal(int signo)
const char *setup_temporary_shallow(const struct sha1_array *extra)
{
static int installed_handler;
struct strbuf sb = STRBUF_INIT;
int fd;
@ -238,10 +237,8 @@ const char *setup_temporary_shallow(const struct sha1_array *extra)
strbuf_addstr(&temporary_shallow, git_path("shallow_XXXXXX"));
fd = xmkstemp(temporary_shallow.buf);
if (!installed_handler) {
atexit(remove_temporary_shallow);
sigchain_push_common(remove_temporary_shallow_on_signal);
}
atexit(remove_temporary_shallow);
sigchain_push_common(remove_temporary_shallow_on_signal);
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
die_errno("failed to write to %s",

View File

@ -7,5 +7,9 @@
extern int online_cpus(void);
extern int init_recursive_mutex(pthread_mutex_t*);
#else
#define online_cpus() 1
#endif
#endif /* THREAD_COMPAT_H */