From 67a2f90c8b4519326955f387fa348c621767c5c8 Mon Sep 17 00:00:00 2001 From: nekobit Date: Wed, 24 Aug 2022 01:00:46 +0000 Subject: [PATCH] Add single-threaded NOOP FossilOrigin-Name: 706225b5257311abdb37ed19ee3d4da2b2fe9cbf1aa88841f6f91b4ce66a4490 --- src/global_perl.h | 6 ++++++ src/main.c | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/global_perl.h b/src/global_perl.h index f821af4..476f160 100644 --- a/src/global_perl.h +++ b/src/global_perl.h @@ -50,8 +50,14 @@ extern PerlInterpreter* my_perl; extern HV* template_files; extern pthread_mutex_t perllock_mutex; +#ifndef SINGLE_THREADED #define perl_lock() do { pthread_mutex_lock(&perllock_mutex); } while (0) #define perl_unlock() do { pthread_mutex_unlock(&perllock_mutex); } while (0) +#else +// NOOP +#define perl_lock() ;; +#define perl_unlock() ;; +#endif #define ARG_UNDEFINED() do { XPUSHs(&PL_sv_undef); } while (0) diff --git a/src/main.c b/src/main.c index 48416f3..c4ed041 100644 --- a/src/main.c +++ b/src/main.c @@ -200,6 +200,14 @@ static void* threaded_fcgi_start(void* arg) return NULL; } +#else +void cgi_start(mastodont_t* api) +{ + while (FCGI_Accept() >= 0) + { + application(api, NULL); + } +} #endif EXTERN_C void xs_init(pTHX) @@ -238,15 +246,17 @@ int main(int argc, char **argv, char **env) pthread_t id[THREAD_COUNT]; for (unsigned i = 0; i < THREAD_COUNT; ++i) - pthread_create(&id[i], NULL, cgi_start, &api); + pthread_create(&id[i], NULL, threaded_fcgi_start, &api); // Hell, let's not sit around here either -threaded_fcgi_start(&api); + threaded_fcgi_start(&api); FCGX_ShutdownPending(); for (unsigned i = 0; i < THREAD_COUNT; ++i) pthread_join(id[i], NULL); +#else + cgi_start(&api); #endif free_instance_info_cache();