index-pack: remove #ifdef NO_PTHREADS
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
2094c5e582507c6bb03d4489ba4a603e3f5fc57e
1 file changed
+14
-49
builtin/index-pack.c
+14
-49
@@ -42,9 +42,7 @@ struct base_data {
42
};
43
44
struct thread_local {
45
-#ifndef NO_PTHREADS
45
pthread_t thread;
47
-#endif
46
struct base_data *base_cache;
47
size_t base_cache_used;
48
int pack_fd;
@@ -98,8 +96,6 @@ static uint32_t input_crc32;
96
static int input_fd, output_fd;
97
static const char *curr_pack;
98
101
-#ifndef NO_PTHREADS
102
-
99
static struct thread_local *thread_data;
100
static int nr_dispatched;
101
static int threads_active;
@@ -179,26 +175,6 @@ static void cleanup_thread(void)
175
free(thread_data);
176
}
177
182
-#else
183
-
184
-#define read_lock()
185
-#define read_unlock()
186
-
187
-#define counter_lock()
188
-#define counter_unlock()
189
-
190
-#define work_lock()
191
-#define work_unlock()
192
-
193
-#define deepest_delta_lock()
194
-#define deepest_delta_unlock()
195
-
196
-#define type_cas_lock()
197
-#define type_cas_unlock()
198
-
199
-#endif
200
-
201
-
178
static int mark_link(struct object *obj, int type, void *data, struct fsck_options *options)
179
{
180
if (!obj)
@@ -364,22 +340,20 @@ static NORETURN void bad_object(off_t offset, const char *format, ...)
340
341
static inline struct thread_local *get_thread_data(void)
342
{
367
-#ifndef NO_PTHREADS
368
- if (threads_active)
369
- return pthread_getspecific(key);
370
- assert(!threads_active &&
371
- "This should only be reached when all threads are gone");
372
-#endif
343
+ if (HAVE_THREADS) {
344
+ if (threads_active)
345
+ return pthread_getspecific(key);
346
+ assert(!threads_active &&
347
+ "This should only be reached when all threads are gone");
348
+ }
349
return ¬hread_data;
350
}
351
376
-#ifndef NO_PTHREADS
352
static void set_thread_data(struct thread_local *data)
353
{
354
if (threads_active)
355
pthread_setspecific(key, data);
356
}
382
-#endif
357
358
static struct base_data *alloc_base_data(void)
359
{
@@ -1092,7 +1066,6 @@ static void resolve_base(struct object_entry *obj)
1066
find_unresolved_deltas(base_obj);
1067
}
1068
1095
-#ifndef NO_PTHREADS
1069
static void *threaded_second_pass(void *data)
1070
{
1071
set_thread_data(data);
@@ -1116,7 +1089,6 @@ static void *threaded_second_pass(void *data)
1089
}
1090
return NULL;
1091
}
1119
-#endif
1092
1093
/*
1094
* First pass:
@@ -1213,7 +1185,6 @@ static void resolve_deltas(void)
1185
progress = start_progress(_("Resolving deltas"),
1186
nr_ref_deltas + nr_ofs_deltas);
1187
1216
-#ifndef NO_PTHREADS
1188
nr_dispatched = 0;
1189
if (nr_threads > 1 || getenv("GIT_FORCE_THREADS")) {
1190
init_thread();
@@ -1229,7 +1200,6 @@ static void resolve_deltas(void)
1200
cleanup_thread();
1201
return;
1202
}
1232
-#endif
1203
1204
for (i = 0; i < nr_objects; i++) {
1205
struct object_entry *obj = &objects[i];
@@ -1531,11 +1501,10 @@ static int git_index_pack_config(const char *k, const char *v, void *cb)
1501
if (nr_threads < 0)
1502
die(_("invalid number of threads specified (%d)"),
1503
nr_threads);
1534
-#ifdef NO_PTHREADS
1535
- if (nr_threads != 1)
1504
+ if (!HAVE_THREADS && nr_threads != 1) {
1505
warning(_("no threads support, ignoring %s"), k);
1537
- nr_threads = 1;
1538
-#endif
1506
+ nr_threads = 1;
1507
+ }
1508
return 0;
1509
}
1510
return git_default_config(k, v, cb);
@@ -1723,12 +1692,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1692
nr_threads = strtoul(arg+10, &end, 0);
1693
if (!arg[10] || *end || nr_threads < 0)
1694
usage(index_pack_usage);
1726
-#ifdef NO_PTHREADS
1727
- if (nr_threads != 1)
1728
- warning(_("no threads support, "
1729
- "ignoring %s"), arg);
1730
- nr_threads = 1;
1731
-#endif
1695
+ if (!HAVE_THREADS && nr_threads != 1) {
1696
+ warning(_("no threads support, ignoring %s"), arg);
1697
+ nr_threads = 1;
1698
+ }
1699
} else if (starts_with(arg, "--pack_header=")) {
1700
struct pack_header *hdr;
1701
char *c;
@@ -1791,14 +1758,12 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1758
if (strict)
1759
opts.flags |= WRITE_IDX_STRICT;
1760
1794
-#ifndef NO_PTHREADS
1795
- if (!nr_threads) {
1761
+ if (HAVE_THREADS && !nr_threads) {
1762
nr_threads = online_cpus();
1763
/* An experiment showed that more threads does not mean faster */
1764
if (nr_threads > 3)
1765
nr_threads = 3;
1766
}
1801
-#endif
1767
1768
curr_pack = open_pack_file(pack_name);
1769
parse_pack_header();