| 2109 | } |
| 2110 | |
| 2111 | static unsigned long load_cache_entries_threaded(struct index_state *istate, const char *mmap, size_t mmap_size, |
| 2112 | int nr_threads, struct index_entry_offset_table *ieot) |
| 2113 | { |
| 2114 | int i, offset, ieot_blocks, ieot_start, err; |
| 2115 | struct load_cache_entries_thread_data *data; |
| 2116 | unsigned long consumed = 0; |
| 2117 | |
| 2118 | /* a little sanity checking */ |
| 2119 | if (istate->name_hash_initialized) |
| 2120 | BUG("the name hash isn't thread safe"); |
| 2121 | |
| 2122 | istate->ce_mem_pool = xmalloc(sizeof(*istate->ce_mem_pool)); |
| 2123 | mem_pool_init(istate->ce_mem_pool, 0); |
| 2124 | |
| 2125 | /* ensure we have no more threads than we have blocks to process */ |
| 2126 | if (nr_threads > ieot->nr) |
| 2127 | nr_threads = ieot->nr; |
| 2128 | CALLOC_ARRAY(data, nr_threads); |
| 2129 | |
| 2130 | offset = ieot_start = 0; |
| 2131 | ieot_blocks = DIV_ROUND_UP(ieot->nr, nr_threads); |
| 2132 | for (i = 0; i < nr_threads; i++) { |
| 2133 | struct load_cache_entries_thread_data *p = &data[i]; |
| 2134 | int nr, j; |
| 2135 | |
| 2136 | if (ieot_start + ieot_blocks > ieot->nr) |
| 2137 | ieot_blocks = ieot->nr - ieot_start; |
| 2138 | |
| 2139 | p->istate = istate; |
| 2140 | p->offset = offset; |
| 2141 | p->mmap = mmap; |
| 2142 | p->ieot = ieot; |
| 2143 | p->ieot_start = ieot_start; |
| 2144 | p->ieot_blocks = ieot_blocks; |
| 2145 | |
| 2146 | /* create a mem_pool for each thread */ |
| 2147 | nr = 0; |
| 2148 | for (j = p->ieot_start; j < p->ieot_start + p->ieot_blocks; j++) |
| 2149 | nr += p->ieot->entries[j].nr; |
| 2150 | p->ce_mem_pool = xmalloc(sizeof(*istate->ce_mem_pool)); |
| 2151 | if (istate->version == 4) { |
| 2152 | mem_pool_init(p->ce_mem_pool, |
| 2153 | estimate_cache_size_from_compressed(nr)); |
| 2154 | } else { |
| 2155 | mem_pool_init(p->ce_mem_pool, |
| 2156 | estimate_cache_size(mmap_size, nr)); |
| 2157 | } |
| 2158 | |
| 2159 | err = pthread_create(&p->pthread, NULL, load_cache_entries_thread, p); |
| 2160 | if (err) |
| 2161 | die(_("unable to create load_cache_entries thread: %s"), strerror(err)); |
| 2162 | |
| 2163 | /* increment by the number of cache entries in the ieot block being processed */ |
| 2164 | for (j = 0; j < ieot_blocks; j++) |
| 2165 | offset += ieot->entries[ieot_start + j].nr; |
| 2166 | ieot_start += ieot_blocks; |
| 2167 | } |
| 2168 |
no test coverage detected