xbps_array_foreach_cb_multi: improve previous (v2).

As suggested by @CasperVector reuse the 'i' var to
wait for threads that were created successfully.
This commit is contained in:
Juan RP 2019-12-27 15:47:43 +01:00
parent a3a1c372cb
commit f5d93caf15
No known key found for this signature in database
GPG Key ID: AF19F6CB482F9368

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, error = 0 , maxthreads; int rv = 0, error = 0, i, maxthreads;
unsigned int reserved; unsigned int reserved;
pthread_spinlock_t reserved_lock; pthread_spinlock_t reserved_lock;
@ -138,7 +138,7 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp,
reserved = slicecount * maxthreads; reserved = slicecount * maxthreads;
for (int i = 0; i < maxthreads; i++) { for (i = 0; i < maxthreads; i++) {
thd[i].array = array; thd[i].array = array;
thd[i].dict = dict; thd[i].dict = dict;
thd[i].xhp = xhp; thd[i].xhp = xhp;
@ -156,9 +156,11 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp,
} }
} }
/* wait for all threads */ /* wait for all threads that were created successfully */
for (int i = 0; i < maxthreads; i++) for (int c = 0; c < i; c++) {
rv = pthread_join(thd[i].thread, NULL); if ((rv = pthread_join(thd[c].thread, NULL)) != 0)
error = rv;
}
out: out:
free(thd); free(thd);