Compare commits
4 Commits
78cf6b08d8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| daef211388 | |||
| 524371ced8 | |||
| c0a0878f47 | |||
| 79499d3061 |
+7
-7
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
static void *mpmc_worker(void *arg);
|
static void *mpmc_worker(void *arg);
|
||||||
|
|
||||||
int mpmc_init(mpmc_t *ctx, int n_workers, int buf_size, void (*consumer)(void *obj), const char *name) {
|
int mpmc_init(mpmc_t *ctx, const int n_workers, const int buf_size, void (*consumer)(void *), const char *name) {
|
||||||
ctx->alive = 1;
|
ctx->alive = 1;
|
||||||
ctx->n_workers = n_workers;
|
ctx->n_workers = n_workers;
|
||||||
ctx->size = buf_size, ctx->max_size = buf_size;
|
ctx->size = buf_size, ctx->max_size = buf_size;
|
||||||
@@ -35,7 +35,7 @@ int mpmc_init(mpmc_t *ctx, int n_workers, int buf_size, void (*consumer)(void *o
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(ctx->buffer, 0, ctx->size * sizeof(void *));
|
memset((void *)ctx->buffer, 0, ctx->size * sizeof(void *));
|
||||||
memset(ctx->workers, -1, ctx->n_workers * sizeof(pthread_t));
|
memset(ctx->workers, -1, ctx->n_workers * sizeof(pthread_t));
|
||||||
|
|
||||||
for (int i = 0; i < ctx->n_workers; i++) {
|
for (int i = 0; i < ctx->n_workers; i++) {
|
||||||
@@ -72,7 +72,7 @@ int mpmc_queue(mpmc_t *ctx, void *obj) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int p = ctx->wr;
|
const int p = ctx->wr;
|
||||||
ctx->wr = (ctx->wr + 1) % ctx->size;
|
ctx->wr = (ctx->wr + 1) % ctx->size;
|
||||||
|
|
||||||
// unlock wr field
|
// unlock wr field
|
||||||
@@ -121,7 +121,7 @@ static void *mpmc_worker(void *arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int p = ctx->rd;
|
const int p = ctx->rd;
|
||||||
ctx->rd = (ctx->rd + 1) % ctx->size;
|
ctx->rd = (ctx->rd + 1) % ctx->size;
|
||||||
|
|
||||||
// unlock rd field
|
// unlock rd field
|
||||||
@@ -143,9 +143,9 @@ void mpmc_stop(mpmc_t *ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mpmc_destroy(mpmc_t *ctx) {
|
void mpmc_destroy(mpmc_t *ctx) {
|
||||||
int e = errno;
|
const int e = errno;
|
||||||
|
|
||||||
// stop threads, if running
|
// stop threads if running
|
||||||
mpmc_stop(ctx);
|
mpmc_stop(ctx);
|
||||||
for (int i = 0; i < ctx->n_workers; i++) {
|
for (int i = 0; i < ctx->n_workers; i++) {
|
||||||
if (ctx->workers[i] == -1) break;
|
if (ctx->workers[i] == -1) break;
|
||||||
@@ -158,7 +158,7 @@ void mpmc_destroy(mpmc_t *ctx) {
|
|||||||
sem_destroy(&ctx->used);
|
sem_destroy(&ctx->used);
|
||||||
sem_destroy(&ctx->lck_rd);
|
sem_destroy(&ctx->lck_rd);
|
||||||
sem_destroy(&ctx->lck_wr);
|
sem_destroy(&ctx->lck_wr);
|
||||||
free(ctx->buffer);
|
free((void *)ctx->buffer);
|
||||||
free(ctx->workers);
|
free(ctx->workers);
|
||||||
|
|
||||||
// reset errno
|
// reset errno
|
||||||
|
|||||||
+4
-4
@@ -5,18 +5,18 @@
|
|||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned char alive;
|
volatile unsigned int alive:1;
|
||||||
int n_workers;
|
int n_workers;
|
||||||
int rd, wr;
|
volatile int rd, wr;
|
||||||
sem_t free, used, lck_rd, lck_wr;
|
sem_t free, used, lck_rd, lck_wr;
|
||||||
int size, max_size;
|
int size, max_size;
|
||||||
void **buffer;
|
void *volatile *buffer;
|
||||||
pthread_t *workers;
|
pthread_t *workers;
|
||||||
void (*consumer)(void *obj);
|
void (*consumer)(void *obj);
|
||||||
const char* name;
|
const char* name;
|
||||||
} mpmc_t;
|
} mpmc_t;
|
||||||
|
|
||||||
int mpmc_init(mpmc_t *ctx, int n_workers, int buf_size, void (*consumer)(void *obj), const char *name);
|
int mpmc_init(mpmc_t *ctx, int n_workers, int buf_size, void (*consumer)(void *), const char *name);
|
||||||
|
|
||||||
int mpmc_queue(mpmc_t *ctx, void *obj);
|
int mpmc_queue(mpmc_t *ctx, void *obj);
|
||||||
|
|
||||||
|
|||||||
+2
-5
@@ -12,8 +12,8 @@
|
|||||||
#include "worker/func.h"
|
#include "worker/func.h"
|
||||||
|
|
||||||
#define NUM_SOCKETS 2
|
#define NUM_SOCKETS 2
|
||||||
#define LISTEN_BACKLOG 16
|
#define LISTEN_BACKLOG 256
|
||||||
#define REQ_PER_CONNECTION 200
|
#define REQ_PER_CONNECTION 256
|
||||||
|
|
||||||
#define SOCKET_TIMEOUT 1
|
#define SOCKET_TIMEOUT 1
|
||||||
#define CLIENT_TIMEOUT 3600
|
#define CLIENT_TIMEOUT 3600
|
||||||
@@ -21,9 +21,6 @@
|
|||||||
#define SERVER_SOCKET_TIMEOUT_RES 60
|
#define SERVER_SOCKET_TIMEOUT_RES 60
|
||||||
#define SERVER_TIMEOUT 3600
|
#define SERVER_TIMEOUT 3600
|
||||||
|
|
||||||
#define CNX_HANDLER_WORKERS 8
|
|
||||||
#define REQ_HANDLER_WORKERS 16
|
|
||||||
|
|
||||||
void server_free_client(client_ctx_t *ctx);
|
void server_free_client(client_ctx_t *ctx);
|
||||||
|
|
||||||
#endif //SESIMOS_SERVER_H
|
#endif //SESIMOS_SERVER_H
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ void fastcgi_handler_func(client_ctx_t *ctx) {
|
|||||||
fastcgi_close(ctx->fcgi_ctx);
|
fastcgi_close(ctx->fcgi_ctx);
|
||||||
ctx->fcgi_ctx = NULL;
|
ctx->fcgi_ctx = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
request_complete(ctx);
|
||||||
|
handle_request(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fastcgi_handler_1(client_ctx_t *ctx) {
|
static int fastcgi_handler_1(client_ctx_t *ctx) {
|
||||||
|
|||||||
Reference in New Issue
Block a user