1 From c80892f17e44331206c8318d53b63bb6a99554d0 Mon Sep 17 00:00:00 2001
2 From: Alexander Kanavin <alex.kanavin@gmail.com>
3 Date: Tue, 30 May 2017 13:58:30 +0300
4 Subject: [PATCH 3/4] rpmstrpool.c: make operations over string pools
7 Otherwise multithreaded rpm building explodes in various ways due
10 Upstream-Status: Submitted [https://github.com/rpm-software-management/rpm/pull/226]
11 Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
14 rpmio/rpmstrpool.c | 56 +++++++++++++++++++++++++++++++++++++++++++++---------
15 1 file changed, 47 insertions(+), 9 deletions(-)
17 diff --git a/rpmio/rpmstrpool.c b/rpmio/rpmstrpool.c
18 index 30a57eb10..58ba95a02 100644
19 --- a/rpmio/rpmstrpool.c
20 +++ b/rpmio/rpmstrpool.c
21 @@ -113,6 +113,8 @@ static poolHash poolHashCreate(int numBuckets)
25 +static const char * rpmstrPoolStrNoLock(rpmstrPool pool, rpmsid sid);
27 static void poolHashResize(rpmstrPool pool, int numBuckets)
29 poolHash ht = pool->hash;
30 @@ -120,7 +122,7 @@ static void poolHashResize(rpmstrPool pool, int numBuckets)
32 for (int i=0; i<ht->numBuckets; i++) {
33 if (!ht->buckets[i].keyid) continue;
34 - unsigned int keyHash = rstrhash(rpmstrPoolStr(pool, ht->buckets[i].keyid));
35 + unsigned int keyHash = rstrhash(rpmstrPoolStrNoLock(pool, ht->buckets[i].keyid));
36 for (unsigned int j=0;;j++) {
37 unsigned int hash = hashbucket(keyHash, j) % numBuckets;
38 if (!buckets[hash].keyid) {
39 @@ -149,7 +151,7 @@ static void poolHashAddHEntry(rpmstrPool pool, const char * key, unsigned int ke
40 ht->buckets[hash].keyid = keyid;
43 - } else if (!strcmp(rpmstrPoolStr(pool, ht->buckets[hash].keyid), key)) {
44 + } else if (!strcmp(rpmstrPoolStrNoLock(pool, ht->buckets[hash].keyid), key)) {
48 @@ -191,7 +193,7 @@ static void poolHashPrintStats(rpmstrPool pool)
49 int maxcollisions = 0;
51 for (i=0; i<ht->numBuckets; i++) {
52 - unsigned int keyHash = rstrhash(rpmstrPoolStr(pool, ht->buckets[i].keyid));
53 + unsigned int keyHash = rstrhash(rpmstrPoolStrNoLock(pool, ht->buckets[i].keyid));
54 for (unsigned int j=0;;j++) {
55 unsigned int hash = hashbucket(keyHash, i) % ht->numBuckets;
57 @@ -221,7 +223,7 @@ static void rpmstrPoolRehash(rpmstrPool pool)
59 pool->hash = poolHashCreate(sizehint);
60 for (int i = 1; i <= pool->offs_size; i++)
61 - poolHashAddEntry(pool, rpmstrPoolStr(pool, i), i);
62 + poolHashAddEntry(pool, rpmstrPoolStrNoLock(pool, i), i);
65 rpmstrPool rpmstrPoolCreate(void)
66 @@ -245,6 +247,8 @@ rpmstrPool rpmstrPoolCreate(void)
68 rpmstrPool rpmstrPoolFree(rpmstrPool pool)
70 + #pragma omp critical(rpmstrpool)
73 if (pool->nrefs > 1) {
75 @@ -260,18 +264,24 @@ rpmstrPool rpmstrPoolFree(rpmstrPool pool)
83 rpmstrPool rpmstrPoolLink(rpmstrPool pool)
85 + #pragma omp critical(rpmstrpool)
93 void rpmstrPoolFreeze(rpmstrPool pool, int keephash)
95 + #pragma omp critical(rpmstrpool)
97 if (pool && !pool->frozen) {
99 pool->hash = poolHashFree(pool->hash);
100 @@ -281,16 +291,20 @@ void rpmstrPoolFreeze(rpmstrPool pool, int keephash)
101 pool->offs_alloced * sizeof(*pool->offs));
107 void rpmstrPoolUnfreeze(rpmstrPool pool)
109 + #pragma omp critical(rpmstrpool)
112 if (pool->hash == NULL) {
113 rpmstrPoolRehash(pool);
120 static rpmsid rpmstrPoolPut(rpmstrPool pool, const char *s, size_t slen, unsigned int hash)
121 @@ -350,7 +364,7 @@ static rpmsid rpmstrPoolGet(rpmstrPool pool, const char * key, size_t keylen,
125 - s = rpmstrPoolStr(pool, ht->buckets[hash].keyid);
126 + s = rpmstrPoolStrNoLock(pool, ht->buckets[hash].keyid);
127 /* pool string could be longer than keylen, require exact matche */
128 if (strncmp(s, key, keylen) == 0 && s[keylen] == '\0')
129 return ht->buckets[hash].keyid;
130 @@ -373,27 +387,31 @@ static inline rpmsid strn2id(rpmstrPool pool, const char *s, size_t slen,
131 rpmsid rpmstrPoolIdn(rpmstrPool pool, const char *s, size_t slen, int create)
135 + #pragma omp critical(rpmstrpool)
138 unsigned int hash = rstrnhash(s, slen);
139 sid = strn2id(pool, s, slen, hash, create);
145 rpmsid rpmstrPoolId(rpmstrPool pool, const char *s, int create)
149 + #pragma omp critical(rpmstrpool)
153 unsigned int hash = rstrlenhash(s, &slen);
154 sid = strn2id(pool, s, slen, hash, create);
160 -const char * rpmstrPoolStr(rpmstrPool pool, rpmsid sid)
161 +static const char * rpmstrPoolStrNoLock(rpmstrPool pool, rpmsid sid)
163 const char *s = NULL;
164 if (pool && sid > 0 && sid <= pool->offs_size)
165 @@ -401,12 +419,25 @@ const char * rpmstrPoolStr(rpmstrPool pool, rpmsid sid)
169 +const char * rpmstrPoolStr(rpmstrPool pool, rpmsid sid)
171 + const char *s = NULL;
172 + #pragma omp critical(rpmstrpool)
174 + s = rpmstrPoolStrNoLock(pool, sid);
179 size_t rpmstrPoolStrlen(rpmstrPool pool, rpmsid sid)
182 + #pragma omp critical(rpmstrpool)
184 if (pool && sid > 0 && sid <= pool->offs_size) {
185 slen = strlen(pool->offs[sid]);
191 @@ -421,5 +452,12 @@ int rpmstrPoolStreq(rpmstrPool poolA, rpmsid sidA,
193 rpmsid rpmstrPoolNumStr(rpmstrPool pool)
195 - return (pool != NULL) ? pool->offs_size : 0;
197 + #pragma omp critical(rpmstrpool)
200 + id = pool->offs_size;