34#include "xbps_api_impl.h" 
   39        xbps_dictionary_t dict;
 
   40        struct xbps_handle *xhp;
 
   42        unsigned int arraycount;
 
   43        unsigned int *reserved;
 
   44        pthread_mutex_t *reserved_lock;
 
   45        unsigned int slicecount;
 
   46        int (*fn)(
struct xbps_handle *, xbps_object_t, 
const char *, 
void *, 
bool *);
 
   60array_foreach_thread(
void *arg)
 
   62        xbps_object_t obj, pkgd;
 
   63        struct thread_data *thd = arg;
 
   66        bool loop_done = 
false;
 
   67        unsigned i = thd->start;
 
   68        unsigned int end = i + thd->slicecount;
 
   70        while(i < thd->arraycount) {
 
   72                for (; i < end && i < thd->arraycount; i++) {
 
   73                        obj = xbps_array_get(thd->array, i);
 
   74                        if (xbps_object_type(thd->dict) == XBPS_TYPE_DICTIONARY) {
 
   75                                pkgd = xbps_dictionary_get_keysym(thd->dict, obj);
 
   76                                key = xbps_dictionary_keysym_cstring_nocopy(obj);
 
   78                                if (strncmp(key, 
"_XBPS_", 6) == 0)
 
   84                        r = (*thd->fn)(thd->xhp, pkgd, key, thd->fn_arg, &loop_done);
 
   85                        if (r != 0 || loop_done) {
 
   91                pthread_mutex_lock(thd->reserved_lock);
 
   93                end = i + thd->slicecount;
 
   95                pthread_mutex_unlock(thd->reserved_lock);
 
  103        xbps_dictionary_t dict,
 
  104        int (*fn)(
struct xbps_handle *, xbps_object_t, 
const char *, 
void *, 
bool *),
 
  107        struct thread_data *thd;
 
  108        unsigned int arraycount, slicecount;
 
  109        int r, error = 0, i, maxthreads;
 
  110        unsigned int reserved;
 
  111        pthread_mutex_t reserved_lock = PTHREAD_MUTEX_INITIALIZER;
 
  115        if (xbps_object_type(array) != XBPS_TYPE_ARRAY)
 
  118        arraycount = xbps_array_count(array);
 
  122        maxthreads = (int)sysconf(_SC_NPROCESSORS_ONLN);
 
  123        if (maxthreads <= 1 || arraycount <= 1) 
 
  126        thd = calloc(maxthreads, 
sizeof(*thd));
 
  131        if((
unsigned int)maxthreads >= arraycount) {
 
  132                maxthreads = arraycount;
 
  135                slicecount = arraycount / maxthreads;
 
  136                if (slicecount > 32) {
 
  141        reserved = slicecount * maxthreads;
 
  143        for (i = 0; i < maxthreads; i++) {
 
  144                thd[i].array = array;
 
  149                thd[i].start = i * slicecount;
 
  150                thd[i].reserved = &reserved;
 
  151                thd[i].reserved_lock = &reserved_lock;
 
  152                thd[i].slicecount = slicecount;
 
  153                thd[i].arraycount = arraycount;
 
  155                r = -pthread_create(&thd[i].thread, NULL, array_foreach_thread, &thd[i]);
 
  158                            "failed to create thread: %s\n", strerror(-r));
 
  165                pthread_mutex_destroy(&reserved_lock);
 
  171        for (
int c = 0; c < i; c++) {
 
  172                r = -pthread_join(thd[c].thread, NULL);
 
  175                            "failed to wait on thread: %s\n", strerror(-r));
 
  180        pthread_mutex_destroy(&reserved_lock);
 
  188        for (
int j = 0; j < i; j++) {
 
 
  202        xbps_dictionary_t dict,
 
  203        int (*fn)(
struct xbps_handle *, xbps_object_t, 
const char *, 
void *, 
bool *),
 
  206        xbps_dictionary_t pkgd;
 
  210        bool loop_done = 
false;
 
  212        for (
unsigned int i = 0; i < xbps_array_count(array); i++) {
 
  213                obj = xbps_array_get(array, i);
 
  214                if (xbps_object_type(dict) == XBPS_TYPE_DICTIONARY) {
 
  215                        pkgd = xbps_dictionary_get_keysym(dict, obj);
 
  216                        key = xbps_dictionary_keysym_cstring_nocopy(obj);
 
  218                        if (strncmp(key, 
"_XBPS_", 6) == 0)
 
  224                r = (*fn)(xhp, pkgd, key, arg, &loop_done);
 
  225                if (r != 0 || loop_done)
 
 
  231xbps_object_iterator_t
 
  236        assert(xbps_object_type(dict) == XBPS_TYPE_DICTIONARY);
 
  239        array = xbps_dictionary_get(dict, key);
 
  240        if (xbps_object_type(array) != XBPS_TYPE_ARRAY) {
 
  245        return xbps_array_iterator(array);
 
 
  249array_replace_dict(xbps_array_t array,
 
  250                   xbps_dictionary_t dict,
 
  255        const char *pkgver, *pkgname;
 
  257        assert(xbps_object_type(array) == XBPS_TYPE_ARRAY);
 
  258        assert(xbps_object_type(dict) == XBPS_TYPE_DICTIONARY);
 
  261        for (
unsigned int i = 0; i < xbps_array_count(array); i++) {
 
  262                obj = xbps_array_get(array, i);
 
  266                if (!xbps_dictionary_get_cstring_nocopy(obj, 
"pkgver", &pkgver)) {
 
  272                                if (!xbps_array_set(array, i, dict)) {
 
  279                        xbps_dictionary_get_cstring_nocopy(obj, 
"pkgname", &pkgname);
 
  280                        if (strcmp(pkgname, str) == 0) {
 
  281                                if (!xbps_array_set(array, i, dict)) {
 
  293xbps_array_replace_dict_by_name(xbps_array_t array,
 
  294                                xbps_dictionary_t dict,
 
  297        return array_replace_dict(array, dict, pkgver, 
false);
 
  301xbps_array_replace_dict_by_pattern(xbps_array_t array,
 
  302                                   xbps_dictionary_t dict,
 
  305        return array_replace_dict(array, dict, pattern, 
true);
 
Generic XBPS structure handler for initialization.
 
#define xbps_error_oom()
Log out of memory condition.
 
void xbps_error_printf(const char *fmt,...)
Prints error messages to stderr.
 
xbps_object_iterator_t xbps_array_iter_from_dict(xbps_dictionary_t dict, const char *key)
 
int xbps_array_foreach_cb_multi(struct xbps_handle *xhp, xbps_array_t array, xbps_dictionary_t dict, int(*fn)(struct xbps_handle *, xbps_object_t, const char *, void *, bool *), void *arg)
 
int xbps_array_foreach_cb(struct xbps_handle *xhp, xbps_array_t array, xbps_dictionary_t dict, int(*fn)(struct xbps_handle *, xbps_object_t, const char *, void *, bool *), void *arg)
 
int xbps_pkgpattern_match(const char *pkgver, const char *pattern)