read-cache.c: remove #ifdef NO_PTHREADS

This is a faithful conversion with no attempt to clean up whatsoever. Code indentation is left broken. There will be another commit to clean it up and un-indent if we just indent now. It's just more code noise. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Nov 3, 2018 at 09:48 UTC 62e5ee81a39dff5d69992b669f7896b6dc31bfd5
1 file changed +10 -24
read-cache.c
+10 -24
@@ -1920,19 +1920,15 @@ struct index_entry_offset_table
1920 struct index_entry_offset entries[FLEX_ARRAY];
1921 };
1922
1923 -#ifndef NO_PTHREADS
1923 static struct index_entry_offset_table *read_ieot_extension(const char *mmap, size_t mmap_size, size_t offset);
1924 static void write_ieot_extension(struct strbuf *sb, struct index_entry_offset_table *ieot);
1926 -#endif
1925
1926 static size_t read_eoie_extension(const char *mmap, size_t mmap_size);
1927 static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context, size_t offset);
1928
1929 struct load_index_extensions
1930 {
1933 -#ifndef NO_PTHREADS
1931 pthread_t pthread;
1935 -#endif
1932 struct index_state *istate;
1933 const char *mmap;
1934 size_t mmap_size;
@@ -2010,8 +2006,6 @@ static unsigned long load_all_cache_entries(struct index_state *istate,
2006 return consumed;
2007 }
2008
2013 -#ifndef NO_PTHREADS
2014 -
2009 /*
2010 * Mostly randomly chosen maximum thread counts: we
2011 * cap the parallelism to online_cpus() threads, and we want
@@ -2122,7 +2116,6 @@ static unsigned long load_cache_entries_threaded(struct index_state *istate, con
2116
2117 return consumed;
2118 }
2125 -#endif
2119
2120 /* remember to discard_cache() before reading a different cache! */
2121 int do_read_index(struct index_state *istate, const char *path, int must_exist)
@@ -2135,10 +2128,8 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
2128 size_t mmap_size;
2129 struct load_index_extensions p;
2130 size_t extension_offset = 0;
2138 -#ifndef NO_PTHREADS
2131 int nr_threads, cpus;
2132 struct index_entry_offset_table *ieot = NULL;
2141 -#endif
2133
2134 if (istate->initialized)
2135 return istate->cache_nr;
@@ -2181,7 +2172,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
2172
2173 src_offset = sizeof(*hdr);
2174
2184 -#ifndef NO_PTHREADS
2175 + if (HAVE_THREADS) {
2176 nr_threads = git_config_get_index_threads();
2177
2178 /* TODO: does creating more threads than cores help? */
@@ -2219,21 +2210,19 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
2210 } else {
2211 src_offset += load_all_cache_entries(istate, mmap, mmap_size, src_offset);
2212 }
2222 -#else
2223 - src_offset += load_all_cache_entries(istate, mmap, mmap_size, src_offset);
2224 -#endif
2213 + } else {
2214 + src_offset += load_all_cache_entries(istate, mmap, mmap_size, src_offset);
2215 + }
2216
2217 istate->timestamp.sec = st.st_mtime;
2218 istate->timestamp.nsec = ST_MTIME_NSEC(st);
2219
2220 /* if we created a thread, join it otherwise load the extensions on the primary thread */
2230 -#ifndef NO_PTHREADS
2231 - if (extension_offset) {
2221 + if (HAVE_THREADS && extension_offset) {
2222 int ret = pthread_join(p.pthread, NULL);
2223 if (ret)
2224 die(_("unable to join load_index_extensions thread: %s"), strerror(ret));
2225 }
2236 -#endif
2226 if (!extension_offset) {
2227 p.src_offset = src_offset;
2228 load_index_extensions(&p);
@@ -2756,8 +2745,9 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
2745 if (ce_write(&c, newfd, &hdr, sizeof(hdr)) < 0)
2746 return -1;
2747
2759 -#ifndef NO_PTHREADS
2760 - nr_threads = git_config_get_index_threads();
2748 + if (HAVE_THREADS) {
2749 + nr_threads = git_config_get_index_threads();
2750 +
2751 if (nr_threads != 1) {
2752 int ieot_blocks, cpus;
2753
@@ -2787,7 +2777,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
2777 ieot_entries = DIV_ROUND_UP(entries, ieot_blocks);
2778 }
2779 }
2790 -#endif
2780 + }
2781
2782 offset = lseek(newfd, 0, SEEK_CUR);
2783 if (offset < 0) {
@@ -2871,8 +2861,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
2861 * strip_extensions parameter as we need it when loading the shared
2862 * index.
2863 */
2874 -#ifndef NO_PTHREADS
2875 - if (ieot) {
2864 + if (HAVE_THREADS && ieot) {
2865 struct strbuf sb = STRBUF_INIT;
2866
2867 write_ieot_extension(&sb, ieot);
@@ -2883,7 +2872,6 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
2872 if (err)
2873 return -1;
2874 }
2886 -#endif
2875
2876 if (!strip_extensions && istate->split_index) {
2877 struct strbuf sb = STRBUF_INIT;
@@ -3469,7 +3457,6 @@ static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context,
3457 strbuf_add(sb, hash, the_hash_algo->rawsz);
3458 }
3459
3472 -#ifndef NO_PTHREADS
3460 #define IEOT_VERSION (1)
3461
3462 static struct index_entry_offset_table *read_ieot_extension(const char *mmap, size_t mmap_size, size_t offset)
@@ -3542,4 +3529,3 @@ static void write_ieot_extension(struct strbuf *sb, struct index_entry_offset_ta
3529 strbuf_add(sb, &buffer, sizeof(uint32_t));
3530 }
3531 }
3545 -#endif