diff options
Diffstat (limited to 'src/core/wrdp_thpool_internals.h')
-rw-r--r-- | src/core/wrdp_thpool_internals.h | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/core/wrdp_thpool_internals.h b/src/core/wrdp_thpool_internals.h new file mode 100644 index 0000000..b37e2d3 --- /dev/null +++ b/src/core/wrdp_thpool_internals.h @@ -0,0 +1,113 @@ +/* BSD-2-Clause license + * + * Copyright (c) 2018-2023 NST <www.newinfosec.ru>, sss <sss at dark-alexandr dot net>. + * + */ + +#pragma once + +#include "wrdp_thpool.h" + +struct wrdp_thpool_task_s +{ + + /* Pass any user specified data pointer. */ + void *userdata; + + //thread owning task + wrdp_thpool_thread *thread; + + /* Task callbacks */ + + /* Task entry point callback */ + void (*run_task)(wrdp_thpool_task *task, void *userdata); + + /* callback used to stop task before moving to another thread */ + void (*stop_task)(wrdp_thpool_task *task, void *userdata); + + /* function called just before adding task to thread, + * may be used to do additional task initialization + * userdata is user specified data passed to "wrdp_thread_pool_add_task" + */ + void (*task_init_cb)(wrdp_thpool_task *task, void *userdata); +}; + +struct wrdp_thpool_thread_s +{ + + //per thread libev based event loop + struct ev_loop *ev_th_loop; + + ev_io ev_pipe_readable; + + pthread_t thread; + + wrdp_thpool_task **tasks; + + uint64_t running_task_count; + uint16_t thread_id; + + int pipe_fds[2]; + + //pool owning thread + wrdp_thpool *pool; +}; + +struct wrdp_thpool_s +{ + wrdp_thpool_thread *threads; + /* worker threads count */ + uint16_t thread_count; + + /* dynamic variable holding number of threads were task count check is + * already done + */ + uint16_t checked_threads_tasks; + + /* maximum tasks per thread */ + uint64_t max_tasks; + + /* buffer to hold tasks count for each thread */ + uint64_t *tasks_per_thread; + + /* internal messageing pipe */ + int pipe_fds[2]; + + ev_io ev_pipe_readable; + + /* data assigned by user */ + void *userdata; + + /* additional api callbacks */ + + /* function called in each thread to do additional initialization + * of user_pool_data + */ + void (*custom_thread_init)(void *user_pool_data, wrdp_thpool_thread *t); + + /* function called in each thread to do additional cleanup of + * user_pool_data + */ + void (*custom_thread_deinit)( + void *user_pool_data, wrdp_thpool_thread *t); + + /* function called in wrdp_thpool_create to do additional initialization + * of user_pool_data + */ + void (*custom_pool_create)(void *user_pool_data); + + /* function called in wrdp_thpool_destroy to do additional cleanup of + * user_pool_data + */ + void (*custom_pool_destroy)(void *user_pool_data); + + /* function called on incomming mesdage with "void *user_data" directed + * to pool + */ + void (*pool_message_handler)(void *user_data); + + /* function called on incomming message with "void *user_data" directed + * to thread + */ + void (*thread_message_handler)(void *user_data); +}; |