Remove MULTITHREADING

FossilOrigin-Name: 17eba667d38eb39c68d2dc452ceeb0866086ff70a99fc3a62c0d75355c66f369
This commit is contained in:
nekobit 2022-10-31 12:13:02 +00:00
parent eaf8771f45
commit 7124bb35ca
7 changed files with 28 additions and 45 deletions

View File

@ -99,10 +99,9 @@ void render_base_page(struct base_page* page, FCGX_Request* req, struct session*
void send_result(FCGX_Request* req, char* status, char* content_type, char* data, size_t data_len)
{
if (data_len == 0) data_len = strlen(data);
#ifdef SINGLE_THREADED
#ifdef CGI_MODE
printf(
#else
pthread_mutex_lock(&print_mutex);
FCGX_FPrintF(req->out,
#endif
"Status: %s\r\n"
@ -111,10 +110,9 @@ void send_result(FCGX_Request* req, char* status, char* content_type, char* data
status ? status : "200 OK",
content_type ? content_type : "text/html",
data_len);
#ifdef SINGLE_THREADED
#ifdef CGI_MODE
puts(data);
#else
FCGX_PutStr(data, data_len, req->out);
pthread_mutex_unlock(&print_mutex);
#endif
}

View File

@ -19,7 +19,7 @@
#ifndef ENV_H
#define ENV_H
#ifdef SINGLE_THREADED
#ifdef CGI_MODE
#define GET_ENV(var, reqp) getenv(var)
#else
#define GET_ENV(var, reqp) FCGX_GetParam(var, req->envp)

View File

@ -69,7 +69,7 @@ extern PerlInterpreter* my_perl;
extern HV* template_files;
extern pthread_mutex_t perllock_mutex;
#ifndef SINGLE_THREADED
#ifdef MULTI_THREADED
#define perl_lock() do { pthread_mutex_lock(&perllock_mutex); } while (0)
#define perl_unlock() do { pthread_mutex_unlock(&perllock_mutex); } while (0)
#else

View File

@ -47,8 +47,6 @@
#include "request.h"
#include "cgi.h"
#define THREAD_COUNT 20
// Allow dynamic loading for Perl
static void xs_init (pTHX);
void boot_DynaLoader (pTHX_ CV* cv);
@ -190,34 +188,32 @@ static void application(mastodont_t* api, REQUEST_T req)
cleanup_media_storages(&ssn, attachments);
}
#ifndef SINGLE_THREADED
static void* threaded_fcgi_start(void* arg)
#ifndef CGI_MODE
static void fcgi_start(mastodont_t* api)
{
mastodont_t* api = arg;
int rc;
FCGX_Request req;
FCGX_InitRequest(&req, 0, 0);
while (1)
{
static pthread_mutex_t accept_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&accept_mutex);
rc = FCGX_Accept_r(&req);
pthread_mutex_unlock(&accept_mutex);
if (rc < 0) break;
application(api, &req);
FCGX_Finish_r(&req);
}
return NULL;
}
#else
void cgi_start(mastodont_t* api)
{
while (FCGI_Accept() >= 0 && quit == 0)
while (FCGI_Accept() >= 0
#ifdef DEBUG
&& quit == 0)
#else
)
#endif
{
application(api, NULL);
}
@ -237,7 +233,7 @@ int main(int argc, char **argv, char **env)
{
// Global init
mstdnt_global_curl_init();
#ifndef SINGLE_THREADED
#ifndef CGI_MODE
FCGX_Init();
#endif
@ -255,10 +251,8 @@ int main(int argc, char **argv, char **env)
init_template_files(aTHX);
// Setup mstdnt hooks to use Perl functions
struct mstdnt_hooks hooks = {
.malloc = tb_malloc,
// Not sure how this differs from tb_free? That's undefined... (but used elsewhere in the code just fine)
.free = tb_free,
.calloc = tb_calloc,
.realloc = tb_realloc,
@ -271,20 +265,12 @@ int main(int argc, char **argv, char **env)
// Fetch information about the current instance
// load_instance_info_cache(&api);
#ifndef SINGLE_THREADED
// Start thread pool
pthread_t id[THREAD_COUNT];
for (unsigned i = 0; i < THREAD_COUNT; ++i)
pthread_create(&id[i], NULL, threaded_fcgi_start, &api);
#ifndef CGI_MODE
// Hell, let's not sit around here either
threaded_fcgi_start(&api);
fcgi_start(&api);
// Blocks
FCGX_ShutdownPending();
for (unsigned i = 0; i < THREAD_COUNT; ++i)
pthread_join(id[i], NULL);
#else
cgi_start(&api);
#endif

View File

@ -143,7 +143,7 @@ char* read_post_data(REQUEST_T req, struct post_values* post)
}
// fread should be a macro to FCGI_fread, which is set by FCGI_Accept in previous definitions
#ifndef SINGLE_THREADED
#ifndef CGI_MODE
size_t len = FCGX_GetStr(post_query, content_length, req->in);
#else
size_t len = fread(post_query, 1, content_length, stdin);
@ -218,7 +218,7 @@ char* parse_query(char* begin, struct http_query_info* info)
char* try_handle_post(REQUEST_T req, void (*call)(struct http_query_info*, void*), void* arg)
{
char* request_method = GET_ENV("REQUEST_METHOD", req);
char* request_method = GET_ENV("REQUEST_ETHOD", req);
char* post_query = NULL, * p_query_read;
struct http_query_info info;
@ -232,7 +232,7 @@ char* try_handle_post(REQUEST_T req, void (*call)(struct http_query_info*, void*
puts("Malloc error!");
return NULL;
}
#ifdef SINGLE_THREADED
#ifdef CGI_MODE
int size = read(STDIN_FILENO, post_query, content_length);
#else
int size = FCGX_GetStr(post_query, content_length, req->in);

View File

@ -20,19 +20,13 @@
#define REQUEST_H
#include <pthread.h>
extern pthread_mutex_t print_mutex;
#ifdef SINGLE_THREADED
#ifdef CGI_MODE
#define PRINTF(str, ...) printf(str, __VA_ARGS__)
#define PUT(str) printf(str)
#define REQUEST_T void*
#else
#define PRINTF(str, ...) do { pthread_mutex_lock(&print_mutex); \
FCGX_FPrintF(req->out, str, __VA_ARGS__); \
pthread_mutex_unlock(&print_mutex); } while (0);
#define PUT(str) do { pthread_mutex_lock(&print_mutex); \
FCGX_FPrintF(req->out, str); \
pthread_mutex_unlock(&print_mutex); } while (0);
#define PRINTF(str, ...) do { FCGX_FPrintF(req->out, str, __VA_ARGS__); } while (0);
#define PUT(str) do { FCGX_FPrintF(req->out, str); } while (0);
#define REQUEST_T FCGX_Request*
#endif

View File

@ -137,6 +137,11 @@ void tl_direct(REQUEST_T req, struct session* ssn, mastodont_t* api)
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_DIRECT, "Direct", 0, 0);
}
static void request_cb_tl_public(mstdnt_request_cb_data_t data, void* args)
{
}
void tl_public(REQUEST_T req, struct session* ssn, mastodont_t* api, int local, enum base_category cat)
{
struct mstdnt_args m_args = { 0 };
@ -162,7 +167,7 @@ void tl_public(REQUEST_T req, struct session* ssn, mastodont_t* api, int local,
try_post_status(ssn, api);
mstdnt_timeline_public(api, &m_args, NULL, NULL, &args, &storage, &statuses, &statuses_len);
mstdnt_timeline_public(api, &m_args, request_cb_tl_public, ssn, &args, &storage, &statuses, &statuses_len);
content_timeline(req, ssn, api, &storage, statuses, statuses_len, cat, NULL, 1, 0);
}