Skip to content

Commit 2179045

Browse files
pcloudsgitster
authored andcommitted
Clean up pthread_create() error handling
Normally pthread_create() rarely fails. But with new pthreads wrapper, pthread_create() will return ENOSYS on a system without thread support. Threaded code _is_ protected by HAVE_THREADS and pthread_create() should never run in the first place. But the situation could change in the future and bugs may sneak in. Make sure that all pthread_create() reports the error cause. While at there, mark these strings for translation if they aren't. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f5c4a9a commit 2179045

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

name-hash.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ static inline void lazy_update_dir_ref_counts(
494494
static void threaded_lazy_init_name_hash(
495495
struct index_state *istate)
496496
{
497+
int err;
497498
int nr_each;
498499
int k_start;
499500
int t;
@@ -526,8 +527,9 @@ static void threaded_lazy_init_name_hash(
526527
if (k_start > istate->cache_nr)
527528
k_start = istate->cache_nr;
528529
td_dir_t->k_end = k_start;
529-
if (pthread_create(&td_dir_t->pthread, NULL, lazy_dir_thread_proc, td_dir_t))
530-
die("unable to create lazy_dir_thread");
530+
err = pthread_create(&td_dir_t->pthread, NULL, lazy_dir_thread_proc, td_dir_t);
531+
if (err)
532+
die(_("unable to create lazy_dir thread: %s"), strerror(err));
531533
}
532534
for (t = 0; t < lazy_nr_dir_threads; t++) {
533535
struct lazy_dir_thread_data *td_dir_t = td_dir + t;
@@ -547,13 +549,15 @@ static void threaded_lazy_init_name_hash(
547549
*/
548550
td_name->istate = istate;
549551
td_name->lazy_entries = lazy_entries;
550-
if (pthread_create(&td_name->pthread, NULL, lazy_name_thread_proc, td_name))
551-
die("unable to create lazy_name_thread");
552+
err = pthread_create(&td_name->pthread, NULL, lazy_name_thread_proc, td_name);
553+
if (err)
554+
die(_("unable to create lazy_name thread: %s"), strerror(err));
552555

553556
lazy_update_dir_ref_counts(istate, lazy_entries);
554557

555-
if (pthread_join(td_name->pthread, NULL))
556-
die("unable to join lazy_name_thread");
558+
err = pthread_join(td_name->pthread, NULL);
559+
if (err)
560+
die(_("unable to join lazy_name thread: %s"), strerror(err));
557561

558562
cleanup_dir_mutex();
559563

preload-index.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ static void preload_index(struct index_state *index,
121121

122122
for (i = 0; i < threads; i++) {
123123
struct thread_data *p = data+i;
124+
int err;
125+
124126
p->index = index;
125127
if (pathspec)
126128
copy_pathspec(&p->pathspec, pathspec);
@@ -129,8 +131,10 @@ static void preload_index(struct index_state *index,
129131
if (pd.progress)
130132
p->progress = &pd;
131133
offset += work;
132-
if (pthread_create(&p->pthread, NULL, preload_thread, p))
133-
die("unable to create threaded lstat");
134+
err = pthread_create(&p->pthread, NULL, preload_thread, p);
135+
136+
if (err)
137+
die(_("unable to create threaded lstat: %s"), strerror(err));
134138
}
135139
for (i = 0; i < threads; i++) {
136140
struct thread_data *p = data+i;

run-command.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ int start_async(struct async *async)
12131213
{
12141214
int err = pthread_create(&async->tid, NULL, run_thread, async);
12151215
if (err) {
1216-
error_errno("cannot create thread");
1216+
error(_("cannot create async thread: %s"), strerror(err));
12171217
goto error;
12181218
}
12191219
}

0 commit comments

Comments
 (0)