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>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2018-11-03 09:48:50 +01:00 committed by Junio C Hamano
parent f5c4a9af45
commit 2179045fd0
3 changed files with 17 additions and 9 deletions

View File

@ -494,6 +494,7 @@ static inline void lazy_update_dir_ref_counts(
static void threaded_lazy_init_name_hash( static void threaded_lazy_init_name_hash(
struct index_state *istate) struct index_state *istate)
{ {
int err;
int nr_each; int nr_each;
int k_start; int k_start;
int t; int t;
@ -526,8 +527,9 @@ static void threaded_lazy_init_name_hash(
if (k_start > istate->cache_nr) if (k_start > istate->cache_nr)
k_start = istate->cache_nr; k_start = istate->cache_nr;
td_dir_t->k_end = k_start; td_dir_t->k_end = k_start;
if (pthread_create(&td_dir_t->pthread, NULL, lazy_dir_thread_proc, td_dir_t)) err = pthread_create(&td_dir_t->pthread, NULL, lazy_dir_thread_proc, td_dir_t);
die("unable to create lazy_dir_thread"); if (err)
die(_("unable to create lazy_dir thread: %s"), strerror(err));
} }
for (t = 0; t < lazy_nr_dir_threads; t++) { for (t = 0; t < lazy_nr_dir_threads; t++) {
struct lazy_dir_thread_data *td_dir_t = td_dir + t; struct lazy_dir_thread_data *td_dir_t = td_dir + t;
@ -547,13 +549,15 @@ static void threaded_lazy_init_name_hash(
*/ */
td_name->istate = istate; td_name->istate = istate;
td_name->lazy_entries = lazy_entries; td_name->lazy_entries = lazy_entries;
if (pthread_create(&td_name->pthread, NULL, lazy_name_thread_proc, td_name)) err = pthread_create(&td_name->pthread, NULL, lazy_name_thread_proc, td_name);
die("unable to create lazy_name_thread"); if (err)
die(_("unable to create lazy_name thread: %s"), strerror(err));
lazy_update_dir_ref_counts(istate, lazy_entries); lazy_update_dir_ref_counts(istate, lazy_entries);
if (pthread_join(td_name->pthread, NULL)) err = pthread_join(td_name->pthread, NULL);
die("unable to join lazy_name_thread"); if (err)
die(_("unable to join lazy_name thread: %s"), strerror(err));
cleanup_dir_mutex(); cleanup_dir_mutex();

View File

@ -121,6 +121,8 @@ static void preload_index(struct index_state *index,
for (i = 0; i < threads; i++) { for (i = 0; i < threads; i++) {
struct thread_data *p = data+i; struct thread_data *p = data+i;
int err;
p->index = index; p->index = index;
if (pathspec) if (pathspec)
copy_pathspec(&p->pathspec, pathspec); copy_pathspec(&p->pathspec, pathspec);
@ -129,8 +131,10 @@ static void preload_index(struct index_state *index,
if (pd.progress) if (pd.progress)
p->progress = &pd; p->progress = &pd;
offset += work; offset += work;
if (pthread_create(&p->pthread, NULL, preload_thread, p)) err = pthread_create(&p->pthread, NULL, preload_thread, p);
die("unable to create threaded lstat");
if (err)
die(_("unable to create threaded lstat: %s"), strerror(err));
} }
for (i = 0; i < threads; i++) { for (i = 0; i < threads; i++) {
struct thread_data *p = data+i; struct thread_data *p = data+i;

View File

@ -1213,7 +1213,7 @@ int start_async(struct async *async)
{ {
int err = pthread_create(&async->tid, NULL, run_thread, async); int err = pthread_create(&async->tid, NULL, run_thread, async);
if (err) { if (err) {
error_errno("cannot create thread"); error(_("cannot create async thread: %s"), strerror(err));
goto error; goto error;
} }
} }