Introduce xbps_{array,pkgdb}_foreach_cb_multi() and use it where appropiate.
In some tasks the single threaded implementation outperms the multithreaded one. Use it where it really makes a difference. The _multi() routines do not spawn any thread if _SC_NPROCESSORS_ONLN == 1. Bump XBPS_API_VERSION.
This commit is contained in:
@@ -215,7 +215,7 @@ find_longest_pkgver(struct xbps_handle *xhp, xbps_object_t o)
|
||||
_find_longest_pkgver_cb, &ffl);
|
||||
xbps_object_release(array);
|
||||
} else {
|
||||
(void)xbps_pkgdb_foreach_cb(xhp,
|
||||
(void)xbps_pkgdb_foreach_cb_multi(xhp,
|
||||
_find_longest_pkgver_cb, &ffl);
|
||||
}
|
||||
|
||||
|
@@ -31,13 +31,11 @@
|
||||
#include <fnmatch.h>
|
||||
#include <dirent.h>
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <xbps.h>
|
||||
#include "defs.h"
|
||||
|
||||
struct ffdata {
|
||||
pthread_mutex_t mtx;
|
||||
int npatterns;
|
||||
char **patterns;
|
||||
const char *repouri;
|
||||
@@ -102,8 +100,6 @@ ownedby_pkgdb_cb(struct xbps_handle *xhp,
|
||||
|
||||
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
|
||||
pthread_mutex_lock(&ffd->mtx);
|
||||
|
||||
pkgmetad = xbps_pkgdb_get_pkg_metadata(xhp, pkgver);
|
||||
assert(pkgmetad);
|
||||
|
||||
@@ -115,8 +111,6 @@ ownedby_pkgdb_cb(struct xbps_handle *xhp,
|
||||
xbps_object_release(pkgmetad);
|
||||
xbps_object_release(files_keys);
|
||||
|
||||
pthread_mutex_unlock(&ffd->mtx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -128,7 +122,6 @@ ownedby(struct xbps_handle *xhp, int npatterns, char **patterns)
|
||||
|
||||
ffd.npatterns = npatterns;
|
||||
ffd.patterns = patterns;
|
||||
pthread_mutex_init(&ffd.mtx, NULL);
|
||||
|
||||
for (int i = 0; i < npatterns; i++) {
|
||||
rfile = realpath(patterns[i], NULL);
|
||||
@@ -189,7 +182,6 @@ repo_ownedby(struct xbps_handle *xhp, int npatterns, char **patterns)
|
||||
char *rfile;
|
||||
int rv;
|
||||
|
||||
pthread_mutex_init(&ffd.mtx, NULL);
|
||||
ffd.npatterns = npatterns;
|
||||
ffd.patterns = patterns;
|
||||
|
||||
@@ -199,7 +191,6 @@ repo_ownedby(struct xbps_handle *xhp, int npatterns, char **patterns)
|
||||
patterns[i] = rfile;
|
||||
}
|
||||
rv = xbps_rpool_foreach(xhp, repo_ownedby_cb, &ffd);
|
||||
pthread_mutex_destroy(&ffd.mtx);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@@ -40,7 +40,6 @@
|
||||
#include <libgen.h>
|
||||
#include <fnmatch.h>
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <xbps.h>
|
||||
#include "defs.h"
|
||||
@@ -49,7 +48,6 @@ struct search_data {
|
||||
int npatterns;
|
||||
char **patterns;
|
||||
int maxcols;
|
||||
pthread_mutex_t mtx;
|
||||
xbps_array_t results;
|
||||
};
|
||||
|
||||
@@ -119,10 +117,8 @@ search_array_cb(struct xbps_handle *xhp _unused,
|
||||
if ((xbps_pkgpattern_match(pkgver, sd->patterns[x])) ||
|
||||
(strcasestr(pkgver, sd->patterns[x])) ||
|
||||
(strcasestr(desc, sd->patterns[x])) || vpkgfound) {
|
||||
pthread_mutex_lock(&sd->mtx);
|
||||
xbps_array_add_cstring_nocopy(sd->results, pkgver);
|
||||
xbps_array_add_cstring_nocopy(sd->results, desc);
|
||||
pthread_mutex_unlock(&sd->mtx);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -135,9 +131,6 @@ search_pkgs_cb(struct xbps_repo *repo, void *arg, bool *done _unused)
|
||||
struct search_data *sd = arg;
|
||||
int rv;
|
||||
|
||||
if (repo->idx == NULL)
|
||||
return 0;
|
||||
|
||||
allkeys = xbps_dictionary_all_keys(repo->idx);
|
||||
rv = xbps_array_foreach_cb(repo->xhp, allkeys, repo->idx, search_array_cb, sd);
|
||||
xbps_object_release(allkeys);
|
||||
@@ -151,7 +144,6 @@ repo_search(struct xbps_handle *xhp, int npatterns, char **patterns)
|
||||
struct search_data sd;
|
||||
int rv;
|
||||
|
||||
pthread_mutex_init(&sd.mtx, NULL);
|
||||
sd.npatterns = npatterns;
|
||||
sd.patterns = patterns;
|
||||
sd.maxcols = get_maxcols();
|
||||
@@ -166,7 +158,6 @@ repo_search(struct xbps_handle *xhp, int npatterns, char **patterns)
|
||||
print_results(xhp, &sd);
|
||||
xbps_object_release(sd.results);
|
||||
}
|
||||
pthread_mutex_destroy(&sd.mtx);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
Reference in New Issue
Block a user