@@ -40,17 +40,13 @@ struct base_data {
40
40
int ofs_first , ofs_last ;
41
41
};
42
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
-
48
43
struct thread_local {
49
44
#ifndef NO_PTHREADS
50
45
pthread_t thread ;
51
46
#endif
52
47
struct base_data * base_cache ;
53
48
size_t base_cache_used ;
49
+ int pack_fd ;
54
50
};
55
51
56
52
/*
@@ -91,7 +87,8 @@ static off_t consumed_bytes;
91
87
static unsigned deepest_delta ;
92
88
static git_SHA_CTX input_ctx ;
93
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 ;
95
92
96
93
#ifndef NO_PTHREADS
97
94
@@ -134,18 +131,26 @@ static inline void unlock_mutex(pthread_mutex_t *mutex)
134
131
*/
135
132
static void init_thread (void )
136
133
{
134
+ int i ;
137
135
init_recursive_mutex (& read_mutex );
138
136
pthread_mutex_init (& counter_mutex , NULL );
139
137
pthread_mutex_init (& work_mutex , NULL );
140
138
if (show_stat )
141
139
pthread_mutex_init (& deepest_delta_mutex , NULL );
142
140
pthread_key_create (& key , NULL );
143
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
+
144
148
threads_active = 1 ;
145
149
}
146
150
147
151
static void cleanup_thread (void )
148
152
{
153
+ int i ;
149
154
if (!threads_active )
150
155
return ;
151
156
threads_active = 0 ;
@@ -154,6 +159,8 @@ static void cleanup_thread(void)
154
159
pthread_mutex_destroy (& work_mutex );
155
160
if (show_stat )
156
161
pthread_mutex_destroy (& deepest_delta_mutex );
162
+ for (i = 0 ; i < nr_threads ; i ++ )
163
+ close (thread_data [i ].pack_fd );
157
164
pthread_key_delete (key );
158
165
free (thread_data );
159
166
}
@@ -288,13 +295,13 @@ static const char *open_pack_file(const char *pack_name)
288
295
output_fd = open (pack_name , O_CREAT |O_EXCL |O_RDWR , 0600 );
289
296
if (output_fd < 0 )
290
297
die_errno (_ ("unable to create '%s'" ), pack_name );
291
- pack_fd = output_fd ;
298
+ nothread_data . pack_fd = output_fd ;
292
299
} else {
293
300
input_fd = open (pack_name , O_RDONLY );
294
301
if (input_fd < 0 )
295
302
die_errno (_ ("cannot open packfile '%s'" ), pack_name );
296
303
output_fd = -1 ;
297
- pack_fd = input_fd ;
304
+ nothread_data . pack_fd = input_fd ;
298
305
}
299
306
git_SHA1_Init (& input_ctx );
300
307
return pack_name ;
@@ -542,7 +549,7 @@ static void *unpack_data(struct object_entry *obj,
542
549
543
550
do {
544
551
ssize_t n = (len < 64 * 1024 ) ? len : 64 * 1024 ;
545
- n = xpread (pack_fd , inbuf , n , from );
552
+ n = xpread (get_thread_data () -> pack_fd , inbuf , n , from );
546
553
if (n < 0 )
547
554
die_errno (_ ("cannot pread pack file" ));
548
555
if (!n )
@@ -1490,7 +1497,7 @@ static void show_pack_info(int stat_only)
1490
1497
int cmd_index_pack (int argc , const char * * argv , const char * prefix )
1491
1498
{
1492
1499
int i , fix_thin_pack = 0 , verify = 0 , stat_only = 0 ;
1493
- const char * curr_pack , * curr_index ;
1500
+ const char * curr_index ;
1494
1501
const char * index_name = NULL , * pack_name = NULL ;
1495
1502
const char * keep_name = NULL , * keep_msg = NULL ;
1496
1503
char * index_name_buf = NULL , * keep_name_buf = NULL ;
0 commit comments