40
int ofs_first, ofs_last;
41
};
42
43
-#if !defined(NO_PTHREADS) && defined(NO_THREAD_SAFE_PREAD)
44
-/* pread() emulation is not thread-safe. Disable threading. */
45
-#define NO_PTHREADS
46
-#endif
47
-
43
struct thread_local {
44
#ifndef NO_PTHREADS
45
pthread_t thread;
46
#endif
47
struct base_data *base_cache;
48
size_t base_cache_used;
49
+ int pack_fd;
50
};
51
52
/*
87
static unsigned deepest_delta;
88
static git_SHA_CTX input_ctx;
89
static uint32_t input_crc32;
94
-static int input_fd, output_fd, pack_fd;
90
+static int input_fd, output_fd;
91
+static const char *curr_pack;
92
93
#ifndef NO_PTHREADS
94
131
*/
132
static void init_thread(void)
133
{
134
+ int i;
135
init_recursive_mutex(&read_mutex);
136
pthread_mutex_init(&counter_mutex, NULL);
137
pthread_mutex_init(&work_mutex, NULL);
139
pthread_mutex_init(&deepest_delta_mutex, NULL);
140
pthread_key_create(&key, NULL);
141
thread_data = xcalloc(nr_threads, sizeof(*thread_data));
142
+ for (i = 0; i < nr_threads; i++) {
143
+ thread_data[i].pack_fd = open(curr_pack, O_RDONLY);
144
+ if (thread_data[i].pack_fd == -1)
145
+ die_errno(_("unable to open %s"), curr_pack);
146
+ }
147
+
148
threads_active = 1;
149
}
150
151
static void cleanup_thread(void)
152
{
153
+ int i;
154
if (!threads_active)
155
return;
156
threads_active = 0;
159
pthread_mutex_destroy(&work_mutex);
160
if (show_stat)
161
pthread_mutex_destroy(&deepest_delta_mutex);
162
+ for (i = 0; i < nr_threads; i++)
163
+ close(thread_data[i].pack_fd);
164
pthread_key_delete(key);
165
free(thread_data);
166
}
295
output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
296
if (output_fd < 0)
297
die_errno(_("unable to create '%s'"), pack_name);
291
- pack_fd = output_fd;
298
+ nothread_data.pack_fd = output_fd;
299
} else {
300
input_fd = open(pack_name, O_RDONLY);
301
if (input_fd < 0)
302
die_errno(_("cannot open packfile '%s'"), pack_name);
303
output_fd = -1;
297
- pack_fd = input_fd;
304
+ nothread_data.pack_fd = input_fd;
305
}
306
git_SHA1_Init(&input_ctx);
307
return pack_name;
549
550
do {
551
ssize_t n = (len < 64*1024) ? len : 64*1024;
545
- n = pread(pack_fd, inbuf, n, from);
552
+ n = pread(get_thread_data()->pack_fd, inbuf, n, from);
553
if (n < 0)
554
die_errno(_("cannot pread pack file"));
555
if (!n)
1497
int cmd_index_pack(int argc, const char **argv, const char *prefix)
1498
{
1499
int i, fix_thin_pack = 0, verify = 0, stat_only = 0;
1493
- const char *curr_pack, *curr_index;
1500
+ const char *curr_index;
1501
const char *index_name = NULL, *pack_name = NULL;
1502
const char *keep_name = NULL, *keep_msg = NULL;
1503
char *index_name_buf = NULL, *keep_name_buf = NULL;