X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-pack-objects.c;h=a15906bdb2021e68a014344cad4e73e9de3367ca;hb=e5f4e214636f9c9bd36c2897634108d5ad5587a1;hp=b13558ee7ea2623d426bc4af7787e3e488990dda;hpb=59921b4b3f24b19e2593085ee27d5e1f2448c6bb;p=git.git diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index b13558ee7..a15906bdb 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -24,7 +24,7 @@ git-pack-objects [{ -q | --progress | --all-progress }] \n\ [--max-pack-size=N] [--local] [--incremental] \n\ [--window=N] [--window-memory=N] [--depth=N] \n\ [--no-reuse-delta] [--no-reuse-object] [--delta-base-offset] \n\ - [--non-empty] [--revs [--unpacked | --all]*] [--reflog] \n\ + [--threads=N] [--non-empty] [--revs [--unpacked | --all]*] [--reflog] \n\ [--stdout | base-name] [delta_size = delta_size; trg->depth = src->depth + 1; + /* + * Handle memory allocation outside of the cache + * accounting lock. Compiler will optimize the strangeness + * away when THREADED_DELTA_SEARCH is not defined. + */ + if (trg_entry->delta_data) + free(trg_entry->delta_data); + cache_lock(); if (trg_entry->delta_data) { delta_cache_size -= trg_entry->delta_size; - free(trg_entry->delta_data); trg_entry->delta_data = NULL; } - if (delta_cacheable(src_size, trg_size, delta_size)) { - trg_entry->delta_data = xrealloc(delta_buf, delta_size); delta_cache_size += trg_entry->delta_size; - } else + cache_unlock(); + trg_entry->delta_data = xrealloc(delta_buf, delta_size); + } else { + cache_unlock(); free(delta_buf); + } + return 1; } @@ -1596,6 +1613,7 @@ static void *threaded_find_deltas(void *arg) data_requester = me; pthread_mutex_unlock(&data_provider); pthread_mutex_lock(&data_ready); + pthread_mutex_unlock(&data_request); if (!me->list_size) return NULL; @@ -1605,19 +1623,22 @@ static void *threaded_find_deltas(void *arg) } } -#define NR_THREADS 4 - static void ll_find_deltas(struct object_entry **list, unsigned list_size, int window, int depth, unsigned *processed) { - struct thread_params p[NR_THREADS]; + struct thread_params *target, p[delta_search_threads]; int i, ret; unsigned chunk_size; + if (delta_search_threads <= 1) { + find_deltas(list, list_size, window, depth, processed); + return; + } + pthread_mutex_lock(&data_provider); pthread_mutex_lock(&data_ready); - for (i = 0; i < NR_THREADS; i++) { + for (i = 0; i < delta_search_threads; i++) { p[i].window = window; p[i].depth = depth; p[i].processed = processed; @@ -1641,17 +1662,17 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size, sublist_size++; pthread_mutex_lock(&data_provider); - data_requester->list = list; - data_requester->list_size = sublist_size; + target = data_requester; + target->list = list; + target->list_size = sublist_size; pthread_mutex_unlock(&data_ready); list += sublist_size; list_size -= sublist_size; if (!sublist_size) { - pthread_join(data_requester->thread, NULL); + pthread_join(target->thread, NULL); i--; } - pthread_mutex_unlock(&data_request); } while (i); } @@ -1741,6 +1762,17 @@ static int git_pack_config(const char *k, const char *v) cache_max_small_delta_size = git_config_int(k, v); return 0; } + if (!strcmp(k, "pack.threads")) { + delta_search_threads = git_config_int(k, v); + if (delta_search_threads < 1) + die("invalid number of threads specified (%d)", + delta_search_threads); +#ifndef THREADED_DELTA_SEARCH + if (delta_search_threads > 1) + warning("no threads support, ignoring %s", k); +#endif + return 0; + } return git_default_config(k, v); } @@ -1900,6 +1932,18 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) usage(pack_usage); continue; } + if (!prefixcmp(arg, "--threads=")) { + char *end; + delta_search_threads = strtoul(arg+10, &end, 0); + if (!arg[10] || *end || delta_search_threads < 1) + usage(pack_usage); +#ifndef THREADED_DELTA_SEARCH + if (delta_search_threads > 1) + warning("no threads support, " + "ignoring %s", arg); +#endif + continue; + } if (!prefixcmp(arg, "--depth=")) { char *end; depth = strtoul(arg+8, &end, 0);