#ifndef THREAD_POOL_H #define THREAD_POOL_H #include #include #ifdef __cplusplus extern "C" { #endif typedef enum { THREAD_POOL_JOB_REQ_QUERY = 0, THREAD_POOL_JOB_COUNT_QUERY, THREAD_POOL_JOB_STORE_EVENT, THREAD_POOL_JOB_DELETE_EVENT, THREAD_POOL_JOB_LOG_SUB_CREATED, THREAD_POOL_JOB_LOG_SUB_CLOSED, THREAD_POOL_JOB_LOG_SUB_DISCONNECTED, THREAD_POOL_JOB_UPDATE_SUB_EVENTS_SENT, THREAD_POOL_JOB_IP_BAN_SAVE, THREAD_POOL_JOB_WAL_CHECKPOINT, THREAD_POOL_JOB_CUSTOM } thread_pool_job_type_t; typedef enum { THREAD_POOL_STATUS_OK = 0, THREAD_POOL_STATUS_NOT_IMPLEMENTED, THREAD_POOL_STATUS_QUEUE_FULL, THREAD_POOL_STATUS_SHUTTING_DOWN, THREAD_POOL_STATUS_INTERNAL_ERROR } thread_pool_status_t; typedef struct { uint64_t job_id; thread_pool_job_type_t type; thread_pool_status_t status; void* session; void* result_data; size_t result_size; const char* message; } thread_pool_result_t; typedef void (*thread_pool_result_cb)(const thread_pool_result_t* result, void* user_ctx); typedef void (*thread_pool_payload_free_cb)(void* payload); typedef void (*thread_pool_wake_loop_cb)(void* wake_ctx); typedef struct { thread_pool_job_type_t type; void* session; void* payload; size_t payload_size; thread_pool_payload_free_cb payload_free; thread_pool_result_cb result_cb; void* result_cb_ctx; } thread_pool_job_t; typedef struct { int reader_threads; int max_queue_depth; const char* db_path; thread_pool_wake_loop_cb wake_loop_cb; void* wake_loop_ctx; } thread_pool_config_t; typedef struct { char* sql; char** bind_params; int bind_param_count; } thread_pool_count_payload_t; typedef struct { char* sql; char** bind_params; int bind_param_count; int row_limit; } thread_pool_req_payload_t; typedef struct { char* id; char* pubkey; long long created_at; int kind; char* event_type; char* content; char* sig; char* tags_json; char* event_json; } thread_pool_store_event_payload_t; typedef struct { int count; } thread_pool_count_result_t; typedef struct { char** event_json_rows; int row_count; } thread_pool_req_result_t; typedef struct { int step_rc; int extended_errcode; } thread_pool_store_event_result_t; typedef struct { char* sub_id; char* wsi_ptr; char* client_ip; char* filter_json; } thread_pool_sub_log_created_payload_t; typedef struct { char* sub_id; char* client_ip; } thread_pool_sub_log_closed_payload_t; typedef struct { char* client_ip; } thread_pool_sub_log_disconnected_payload_t; typedef struct { char* sub_id; int events_sent; } thread_pool_sub_update_events_payload_t; int thread_pool_init(const thread_pool_config_t* config); void thread_pool_shutdown(void); int thread_pool_is_running(void); thread_pool_status_t thread_pool_submit_read(const thread_pool_job_t* job, uint64_t* out_job_id); thread_pool_status_t thread_pool_submit_write(const thread_pool_job_t* job, uint64_t* out_job_id); int thread_pool_submit_wal_checkpoint(void); int thread_pool_execute_count_sync(const char* sql, const char** bind_params, int bind_param_count, int* out_count); int thread_pool_execute_req_sync(const char* sql, const char** bind_params, int bind_param_count, int row_limit, thread_pool_req_result_t** out_result); void thread_pool_free_req_result(thread_pool_req_result_t* result); int thread_pool_execute_store_event_sync(const thread_pool_store_event_payload_t* payload, thread_pool_store_event_result_t* out_result); #ifdef __cplusplus } #endif #endif // THREAD_POOL_H