OBS-URL: https://build.opensuse.org/package/show/Base:System/rpm?expand=0&rev=678
69 lines
2.1 KiB
Diff
69 lines
2.1 KiB
Diff
--- rpmio/rpmio.c.orig 2024-10-07 09:35:46.000000000 +0000
|
|
+++ rpmio/rpmio.c 2024-12-16 09:42:02.197155600 +0000
|
|
@@ -8,6 +8,7 @@
|
|
#include <ctype.h>
|
|
#include <dirent.h>
|
|
#include <fcntl.h>
|
|
+#include <pthread.h>
|
|
#include <sys/resource.h>
|
|
|
|
#include <rpm/rpmlog.h>
|
|
@@ -996,6 +997,7 @@ const FDIO_t lzdio = &lzdio_s;
|
|
/* Support for ZSTD library. */
|
|
#ifdef HAVE_ZSTD
|
|
|
|
+#define ZSTD_STATIC_LINKING_ONLY
|
|
#include <zstd.h>
|
|
|
|
typedef struct rpmzstd_s {
|
|
@@ -1013,6 +1015,29 @@ typedef struct rpmzstd_s {
|
|
ZSTD_outBuffer zob; /*!< ZSTD_outBuffer */
|
|
} * rpmzstd;
|
|
|
|
+#if ZSTD_VERSION_NUMBER >= 10407
|
|
+
|
|
+static pthread_once_t zstdThreadPoolCreated = PTHREAD_ONCE_INIT;
|
|
+static ZSTD_threadPool *zstdThreadPool;
|
|
+static int zstdThreadPoolThreads;
|
|
+
|
|
+static void zstdCreateThreadPool(void)
|
|
+{
|
|
+ int numthreads = rpmExpandNumeric("%{?_zstd_pool_threads}%{?!_zstd_pool_threads:-1}");
|
|
+ if (numthreads == 0)
|
|
+ numthreads = rpmExpandNumeric("%{getncpus:thread}");
|
|
+ if (numthreads > 0) {
|
|
+ zstdThreadPoolThreads = numthreads;
|
|
+ zstdThreadPool = ZSTD_createThreadPool(numthreads);
|
|
+ if (!zstdThreadPool)
|
|
+ rpmlog(RPMLOG_WARNING, "Could not create zstd thread pool for %d threads\n", numthreads);
|
|
+ else
|
|
+ rpmlog(RPMLOG_DEBUG, "Created zstd thread pool for %d threads\n", numthreads);
|
|
+ }
|
|
+}
|
|
+
|
|
+#endif
|
|
+
|
|
static rpmzstd rpmzstdNew(int fdno, const char *fmode)
|
|
{
|
|
rpmzstd zstd = NULL;
|
|
@@ -1119,8 +1144,18 @@ static rpmzstd rpmzstdNew(int fdno, cons
|
|
}
|
|
|
|
if (threads > 0) {
|
|
- if (ZSTD_isError (ZSTD_CCtx_setParameter(zstd->stream.c, ZSTD_c_nbWorkers, threads)))
|
|
+ if (ZSTD_isError (ZSTD_CCtx_setParameter(zstd->stream.c, ZSTD_c_nbWorkers, threads))) {
|
|
rpmlog(RPMLOG_DEBUG, "zstd library does not support multi-threading\n");
|
|
+ } else {
|
|
+#if ZSTD_VERSION_NUMBER >= 10407
|
|
+ pthread_once(&zstdThreadPoolCreated, zstdCreateThreadPool);
|
|
+ if (zstdThreadPool) {
|
|
+ if (threads > zstdThreadPoolThreads)
|
|
+ ZSTD_CCtx_setParameter(zstd->stream.c, ZSTD_c_nbWorkers, zstdThreadPoolThreads);
|
|
+ ZSTD_CCtx_refThreadPool(zstd->stream.c, zstdThreadPool);
|
|
+ }
|
|
+#endif
|
|
+ }
|
|
}
|
|
|
|
nb = ZSTD_CStreamOutSize();
|