xbps_array_foreach_cb_multi: remove useless mutex.

This commit is contained in:
Juan RP 2013-12-08 08:07:45 +01:00
parent 2c9ab6a1f2
commit d95d5ba113

View File

@ -34,7 +34,6 @@
struct thread_data { struct thread_data {
pthread_t thread; pthread_t thread;
pthread_mutex_t *mtx;
xbps_array_t array; xbps_array_t array;
xbps_dictionary_t dict; xbps_dictionary_t dict;
struct xbps_handle *xhp; struct xbps_handle *xhp;
@ -63,9 +62,6 @@ array_foreach_thread(void *arg)
/* process pkgs from start until end */ /* process pkgs from start until end */
for (unsigned int i = thd->start; i < thd->end; i++) { for (unsigned int i = thd->start; i < thd->end; i++) {
if (thd->mtx)
pthread_mutex_lock(thd->mtx);
obj = xbps_array_get(thd->array, i); obj = xbps_array_get(thd->array, i);
if (xbps_object_type(thd->dict) == XBPS_TYPE_DICTIONARY) { if (xbps_object_type(thd->dict) == XBPS_TYPE_DICTIONARY) {
pkgd = xbps_dictionary_get_keysym(thd->dict, obj); pkgd = xbps_dictionary_get_keysym(thd->dict, obj);
@ -74,9 +70,6 @@ array_foreach_thread(void *arg)
pkgd = obj; pkgd = obj;
key = NULL; key = NULL;
} }
if (thd->mtx)
pthread_mutex_unlock(thd->mtx);
rv = (*thd->fn)(thd->xhp, pkgd, key, thd->fn_arg, &loop_done); rv = (*thd->fn)(thd->xhp, pkgd, key, thd->fn_arg, &loop_done);
if (rv != 0 || loop_done) if (rv != 0 || loop_done)
break; break;
@ -92,7 +85,6 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp,
void *arg) void *arg)
{ {
struct thread_data *thd; struct thread_data *thd;
pthread_mutex_t mtx;
unsigned int arraycount, slicecount, pkgcount; unsigned int arraycount, slicecount, pkgcount;
int rv = 0, maxthreads; int rv = 0, maxthreads;
@ -113,10 +105,8 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp,
assert(thd); assert(thd);
slicecount = arraycount / maxthreads; slicecount = arraycount / maxthreads;
pkgcount = 0; pkgcount = 0;
pthread_mutex_init(&mtx, NULL);
for (int i = 0; i < maxthreads; i++) { for (int i = 0; i < maxthreads; i++) {
thd[i].mtx = &mtx;
thd[i].array = array; thd[i].array = array;
thd[i].dict = dict; thd[i].dict = dict;
thd[i].xhp = xhp; thd[i].xhp = xhp;
@ -135,7 +125,6 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp,
for (int i = 0; i < maxthreads; i++) for (int i = 0; i < maxthreads; i++)
rv = pthread_join(thd[i].thread, NULL); rv = pthread_join(thd[i].thread, NULL);
pthread_mutex_destroy(&mtx);
free(thd); free(thd);
return rv; return rv;