From 052e4c5e5d488df4b20e78d390c19cbac806a255 Mon Sep 17 00:00:00 2001 From: tidwall Date: Mon, 13 May 2024 05:55:58 -0700 Subject: [PATCH] Fix worker test Github actions were running low on memory causing ENOMEM errors when running the test_work test. This commit lowers the number of background coroutines in hopes to alleviate the memory pressure. --- deps/worker.c | 9 +++++++++ neco.c | 19 ++++++++++++++++++- tests/test_work.c | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/deps/worker.c b/deps/worker.c index 4b8af23..1697a89 100644 --- a/deps/worker.c +++ b/deps/worker.c @@ -12,6 +12,12 @@ #include #include +#ifdef WORKER_STATIC +#define WORKER_API static +#else +#define WORKER_API +#endif + #define WORKER_DEF_TIMEOUT INT64_C(1000000000) // one second #define WORKER_DEF_MAX_THREADS 2 #define WORKER_DEF_MAX_THREAD_ENTRIES 32 @@ -46,6 +52,7 @@ struct worker { void (*free)(void*); }; +WORKER_API void worker_free(struct worker *worker) { if (worker) { if (worker->threads) { @@ -70,6 +77,7 @@ void worker_free(struct worker *worker) { } } +WORKER_API struct worker *worker_new(struct worker_opts *opts) { // Load options int nthreads = opts ? opts->max_threads : 0; @@ -164,6 +172,7 @@ static void *worker_entry(void *arg) { /// @param udata any user data /// @return true for success or false if no worker is available. /// @return false for invalid arguments. Worker and work must no be null. +WORKER_API bool worker_submit(struct worker *worker, int64_t pin, void(*work)(void *udata), void *udata) { diff --git a/neco.c b/neco.c index fb36106..2114c2b 100644 --- a/neco.c +++ b/neco.c @@ -97,8 +97,15 @@ NECO_NOWRITEWORKERS // Disable all write workers #undef NECO_BURST #define NECO_BURST 1 #endif +#if NECO_MAXWORKERS > 8 +#undef NECO_MAXWORKERS +#define NECO_MAXWORKERS 8 +#endif +#if NECO_MAXRINGSIZE > 4 +#undef NECO_MAXRINGSIZE +#define NECO_MAXRINGSIZE 4 +#endif #endif - // The following is only needed when LLCO_NOASM or LLCO_STACKJMP is defined. // This same block is duplicated in the llco.c block below. @@ -137,6 +144,7 @@ NECO_NOWRITEWORKERS // Disable all write workers #define SCO_STATIC #define STACK_STATIC +#define WORKER_STATIC #if defined(__GNUC__) #pragma GCC diagnostic push @@ -2623,6 +2631,12 @@ void *stack_addr(struct stack *stack) { #include #include +#ifdef WORKER_STATIC +#define WORKER_API static +#else +#define WORKER_API +#endif + #define WORKER_DEF_TIMEOUT INT64_C(1000000000) // one second #define WORKER_DEF_MAX_THREADS 2 #define WORKER_DEF_MAX_THREAD_ENTRIES 32 @@ -2657,6 +2671,7 @@ struct worker { void (*free)(void*); }; +WORKER_API void worker_free(struct worker *worker) { if (worker) { if (worker->threads) { @@ -2681,6 +2696,7 @@ void worker_free(struct worker *worker) { } } +WORKER_API struct worker *worker_new(struct worker_opts *opts) { // Load options int nthreads = opts ? opts->max_threads : 0; @@ -2775,6 +2791,7 @@ static void *worker_entry(void *arg) { /// @param udata any user data /// @return true for success or false if no worker is available. /// @return false for invalid arguments. Worker and work must no be null. +WORKER_API bool worker_submit(struct worker *worker, int64_t pin, void(*work)(void *udata), void *udata) { diff --git a/tests/test_work.c b/tests/test_work.c index 909b174..2c11f50 100644 --- a/tests/test_work.c +++ b/tests/test_work.c @@ -15,7 +15,7 @@ void co_work_runner(int argc, void *argv[]) { void co_work(int argc, void *argv[]) { (void)argc; (void)argv; - for (int i = 0; i < 10000; i++) { + for (int i = 0; i < 100; i++) { expect(neco_start(co_work_runner, 1, &i), NECO_OK); } }