xbps_array_foreach_cb_multi: switch to a mutex.
There's no reason to use a spin lock.
This commit is contained in:
parent
8c930a47dd
commit
c460df6011
12
lib/plist.c
12
lib/plist.c
@ -40,7 +40,7 @@ struct thread_data {
|
|||||||
unsigned int start;
|
unsigned int start;
|
||||||
unsigned int arraycount;
|
unsigned int arraycount;
|
||||||
unsigned int *reserved;
|
unsigned int *reserved;
|
||||||
pthread_spinlock_t *reserved_lock;
|
pthread_mutex_t *reserved_lock;
|
||||||
unsigned int slicecount;
|
unsigned int slicecount;
|
||||||
int (*fn)(struct xbps_handle *, xbps_object_t, const char *, void *, bool *);
|
int (*fn)(struct xbps_handle *, xbps_object_t, const char *, void *, bool *);
|
||||||
void *fn_arg;
|
void *fn_arg;
|
||||||
@ -84,11 +84,11 @@ array_foreach_thread(void *arg)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Reserve more elements to compute */
|
/* Reserve more elements to compute */
|
||||||
pthread_spin_lock(thd->reserved_lock);
|
pthread_mutex_lock(thd->reserved_lock);
|
||||||
i = *thd->reserved;
|
i = *thd->reserved;
|
||||||
end = i + thd->slicecount;
|
end = i + thd->slicecount;
|
||||||
*thd->reserved = end;
|
*thd->reserved = end;
|
||||||
pthread_spin_unlock(thd->reserved_lock);
|
pthread_mutex_unlock(thd->reserved_lock);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp,
|
|||||||
unsigned int arraycount, slicecount;
|
unsigned int arraycount, slicecount;
|
||||||
int rv = 0, error = 0, i, maxthreads;
|
int rv = 0, error = 0, i, maxthreads;
|
||||||
unsigned int reserved;
|
unsigned int reserved;
|
||||||
pthread_spinlock_t reserved_lock;
|
pthread_mutex_t reserved_lock;
|
||||||
|
|
||||||
assert(fn != NULL);
|
assert(fn != NULL);
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp,
|
|||||||
if (maxthreads <= 1 || arraycount <= 1) /* use single threaded routine */
|
if (maxthreads <= 1 || arraycount <= 1) /* use single threaded routine */
|
||||||
return xbps_array_foreach_cb(xhp, array, dict, fn, arg);
|
return xbps_array_foreach_cb(xhp, array, dict, fn, arg);
|
||||||
|
|
||||||
if (pthread_spin_init(&reserved_lock, PTHREAD_PROCESS_PRIVATE) != 0)
|
if (pthread_mutex_init(&reserved_lock, PTHREAD_PROCESS_PRIVATE) != 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
thd = calloc(maxthreads, sizeof(*thd));
|
thd = calloc(maxthreads, sizeof(*thd));
|
||||||
@ -163,7 +163,7 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(thd);
|
free(thd);
|
||||||
pthread_spin_destroy(&reserved_lock);
|
pthread_mutex_destroy(&reserved_lock);
|
||||||
|
|
||||||
return error ? error : rv;
|
return error ? error : rv;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user