bin/xbps-fbulk: port to uthash

This commit is contained in:
Duncan Overbruck 2020-02-22 15:51:07 +01:00 committed by Juan RP
parent c3830670f8
commit b8e611a149

View File

@ -65,6 +65,7 @@
#include <getopt.h> #include <getopt.h>
#include <xbps.h> #include <xbps.h>
#include "uthash.h"
struct item; struct item;
@ -75,7 +76,6 @@ struct depn {
struct item { struct item {
enum { XWAITING, XDEPFAIL, XBUILD, XRUN, XDONE, XBROKEN } status; enum { XWAITING, XDEPFAIL, XBUILD, XRUN, XDONE, XBROKEN } status;
struct item *hnext; /* ItemHash next */
struct item *bnext; /* BuildList/RunList next */ struct item *bnext; /* BuildList/RunList next */
struct depn *dbase; /* packages depending on us */ struct depn *dbase; /* packages depending on us */
char *pkgn; /* package name */ char *pkgn; /* package name */
@ -83,12 +83,10 @@ struct item {
int dcount; /* build completion for our dependencies */ int dcount; /* build completion for our dependencies */
int xcode; /* exit code from build */ int xcode; /* exit code from build */
pid_t pid; /* running build */ pid_t pid; /* running build */
UT_hash_handle hh;
}; };
#define ITHSIZE 1024 static struct item *hashtab = NULL;
#define ITHMASK (ITHSIZE - 1)
static struct item *ItemHash[ITHSIZE];
static struct item *BuildList; static struct item *BuildList;
static struct item **BuildListP = &BuildList; static struct item **BuildListP = &BuildList;
static struct item *RunList; static struct item *RunList;
@ -99,52 +97,33 @@ int NRunning;
char *LogDir; char *LogDir;
char *TargetArch; char *TargetArch;
/*
* Item hashing and dependency helper routines, called during the
* directory scan.
*/
static int
itemhash(const char *pkgn)
{
int hv = 0xA1B5F342;
int i;
assert(pkgn);
for (i = 0; pkgn[i]; ++i)
hv = (hv << 5) ^ (hv >> 23) ^ pkgn[i];
return hv & ITHMASK;
}
static struct item * static struct item *
lookupItem(const char *pkgn) lookupItem(const char *pkgn)
{ {
struct item *item; struct item *item = NULL;
assert(pkgn); assert(pkgn);
for (item = ItemHash[itemhash(pkgn)]; item; item = item->hnext) { HASH_FIND_STR(hashtab, pkgn, item);
if (strcmp(pkgn, item->pkgn) == 0) return item;
return item;
}
return NULL;
} }
static struct item * static struct item *
addItem(const char *pkgn) addItem(const char *pkgn)
{ {
struct item **itemp; struct item *item = calloc(1, sizeof (struct item));
struct item *item = calloc(sizeof(*item), 1);
assert(pkgn); assert(pkgn);
assert(item); if (item == NULL)
return NULL;
itemp = &ItemHash[itemhash(pkgn)];
item->status = XWAITING; item->status = XWAITING;
item->hnext = *itemp;
item->pkgn = strdup(pkgn); item->pkgn = strdup(pkgn);
*itemp = item; if (item->pkgn == NULL) {
free(item);
return NULL;
}
HASH_ADD_KEYPTR(hh, hashtab, item->pkgn, strlen(item->pkgn), item);
return item; return item;
} }