xbps_array_foreach_cb_multi: fix incorrect array counter.

This fixes some races that could be seen when there's a
determined number of pkgs and CPU threads.
This commit is contained in:
Juan RP 2019-04-19 16:50:22 +02:00 committed by Duncaen
parent 580a5ba29b
commit 08aa44602f

View File

@ -111,10 +111,12 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp,
if (xbps_object_type(array) != XBPS_TYPE_ARRAY)
return 0;
arraycount = xbps_array_count(array);
if (arraycount == 0)
if (!xbps_array_count(array))
return 0;
/* - 1 because there's a private dict used internally */
arraycount = xbps_array_count(array) - 1;
maxthreads = (int)sysconf(_SC_NPROCESSORS_ONLN);
if (maxthreads <= 1 || arraycount <= 1) /* use single threaded routine */
return xbps_array_foreach_cb(xhp, array, dict, fn, arg);