update myclib

This commit is contained in:
2025-08-03 20:23:05 +02:00
parent 17e0622e56
commit 4d8d901bd3
11 changed files with 532 additions and 65 deletions

View File

@@ -0,0 +1,34 @@
#ifndef CWS_THREADPOOL_H
#define CWS_THREADPOOL_H
#include "myclib/hashmap/myhashmap.h"
#include "server.h"
#include "utils/config.h"
#define CWS_MAX_QUEUE_TASKS 16
#define CWS_MAX_THREADS 16
typedef struct cws_task_t {
int client_fd;
int epfd;
mcl_hashmap *clients;
cws_config *config;
} cws_task;
typedef struct cws_threadpool_t {
cws_task queue[CWS_MAX_QUEUE_TASKS];
int front, rear;
pthread_mutex_t lock;
pthread_cond_t cond;
pthread_t threads[CWS_MAX_THREADS];
int shutdown;
} cws_threadpool;
cws_threadpool *cws_threadpool_init();
cws_server_ret cws_threadpool_add_task(cws_threadpool *pool, cws_task *task);
cws_server_ret cws_threadpool_worker(cws_threadpool *pool);
cws_server_ret cws_threadpool_destroy(cws_threadpool *pool);
#endif