xbps_array_foreach_cb_multi: error out if pthread_create(3) fails.

We do not want to continue processing more threads
if pthread_create(3) fails, rather return an error.

This is for #182 but not yet fixed, there might be a
memleak somewhere.
This commit is contained in:
Juan RP
2019-12-27 14:27:51 +01:00
parent 7a220b37db
commit 08a1c61a4d

View File

@ -102,7 +102,7 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp,
{ {
struct thread_data *thd; struct thread_data *thd;
unsigned int arraycount, slicecount; unsigned int arraycount, slicecount;
int rv = 0, maxthreads; int rv = 0, error = 0 , maxthreads;
unsigned int reserved; unsigned int reserved;
pthread_spinlock_t reserved_lock; pthread_spinlock_t reserved_lock;
@ -150,8 +150,11 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp,
thd[i].slicecount = slicecount; thd[i].slicecount = slicecount;
thd[i].arraycount = arraycount; thd[i].arraycount = arraycount;
pthread_create(&thd[i].thread, NULL, if ((rv = pthread_create(&thd[i].thread, NULL, array_foreach_thread, &thd[i])) != 0) {
array_foreach_thread, &thd[i]); error = rv;
break;
}
} }
/* wait for all threads */ /* wait for all threads */
for (int i = 0; i < maxthreads; i++) for (int i = 0; i < maxthreads; i++)
@ -160,7 +163,7 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp,
free(thd); free(thd);
pthread_spin_destroy(&reserved_lock); pthread_spin_destroy(&reserved_lock);
return rv; return error ? error : rv;
} }
int int