commit f3e6eba1bbc7acf9c85000cee78b7d185113a82d
parent 73ed90984d8397b63748aedd161adc5dff8570d9
Author: Remy Noulin <loader2x@gmail.com>
Date: Fri, 28 Feb 2025 08:34:02 +0200
Add a function to initialize libsheepy without the thread pool
initLibsheepy(ARGV[0]); initializes libsheepy with the thread pool.
To initialize without the thread pool, do like this:
initLibsheepyF(ARGV[0], initLibsheepyObjectWithoutTpool);
release/libsheepy.h | 2 +-
release/libsheepyObject.h | 1 +
src/json/libsheepyObject.c | 22 ++++++++++++++--------
src/libsheepy.h | 2 +-
src/libsheepyObject.h | 1 +
5 files changed, 18 insertions(+), 10 deletions(-)
Diffstat:
5 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/release/libsheepy.h b/release/libsheepy.h
@@ -98,7 +98,7 @@
// version accoring to the version package: Release.Major.minor.patch
// https://noulin.net/version/file/README.md.html
-#define LIBSHEEPY_VERSION "2.2.16.3"
+#define LIBSHEEPY_VERSION "2.2.17"
#ifndef SH_PREFIX
#define SH_PREFIX(NAME) NAME
diff --git a/release/libsheepyObject.h b/release/libsheepyObject.h
@@ -11114,6 +11114,7 @@ void finalizeLibsheepyAtExit(void);
* start the thread pool
*/
void initLibsheepyObject(void);
+void initLibsheepyObjectWithoutTpool(void);
#undef initLibsheepy
#define initLibsheepy(progPath) initLibsheepyF(progPath, initLibsheepyObject)
diff --git a/src/json/libsheepyObject.c b/src/json/libsheepyObject.c
@@ -490,6 +490,7 @@ void finalizeLibsheepyAtExit(void);
#if (__APPLE__ || __FreeBSD__ || __TERMUX__ || __OpenBSD__ || __DragonFly__ || MUSL_LIBC || __sun__ || __HAIKU__)
void initLibsheepyObject(void);
void initLibsheepyObject(void);
+void initLibsheepyObjectWithoutTpool(void);
#endif
/** \file
@@ -5668,6 +5669,19 @@ void initLibsheepyObject(void) {
#else // #if (__APPLE__ || __FreeBSD__ || __TERMUX__ || __OpenBSD__ || __DragonFly__ || MUSL_LIBC || __sun__ || __HAIKU__)
void initLibsheepyObject(void) {
+ initLibsheepyObjectWithoutTpool();
+
+ int numberOfOnlineProcs = (int)sysconf(_SC_NPROCESSORS_ONLN);
+ tpool = tpool_init(numberOfOnlineProcs);
+
+ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+ range(i, tpoolLockCount) {
+ tpoolLocks[i] = mutex;
+ }
+}
+
+void initLibsheepyObjectWithoutTpool(void) {
+
dArrayInit(&finalizeRecycleContainersFuncs);
registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallArray);
registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallBool);
@@ -5680,14 +5694,6 @@ void initLibsheepyObject(void) {
registerFinalizeRecycleContainersInThreadPool(finalizeRecycleSmallString);
registerFinalizeRecycleContainersInThreadPool(finalizeRecycleUndefined);
- int numberOfOnlineProcs = (int)sysconf(_SC_NPROCESSORS_ONLN);
- tpool = tpool_init(numberOfOnlineProcs);
-
- pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
- range(i, tpoolLockCount) {
- tpoolLocks[i] = mutex;
- }
-
// register %m type specifiers in printf for baset objects
register_printf_specifier('m', print_m, print_m_arginfo); {
diff --git a/src/libsheepy.h b/src/libsheepy.h
@@ -98,7 +98,7 @@
// version accoring to the version package: Release.Major.minor.patch
// https://noulin.net/version/file/README.md.html
-#define LIBSHEEPY_VERSION "2.2.16.3"
+#define LIBSHEEPY_VERSION "2.2.17"
#ifndef SH_PREFIX
#define SH_PREFIX(NAME) NAME
diff --git a/src/libsheepyObject.h b/src/libsheepyObject.h
@@ -11114,6 +11114,7 @@ void finalizeLibsheepyAtExit(void);
* start the thread pool
*/
void initLibsheepyObject(void);
+void initLibsheepyObjectWithoutTpool(void);
#undef initLibsheepy
#define initLibsheepy(progPath) initLibsheepyF(progPath, initLibsheepyObject)