ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
thread_pool.h
Go to the documentation of this file.
1#pragma once
2
73#include <stdint.h>
74#include <stdbool.h>
75#include "common.h"
77
78// Forward declaration
81
87typedef struct thread_pool_work_entry {
88 void *(*work_func)(void *);
89 void *work_arg;
92
102 void *(*thread_func)(void *);
104 char name[64];
106};
107
132
145thread_pool_t *thread_pool_create(const char *pool_name);
146
163thread_pool_t *thread_pool_create_with_workers(const char *pool_name, size_t num_workers);
164
175
193asciichat_error_t thread_pool_queue_work(const char *name, thread_pool_t *pool, void *(*work_func)(void *), void *work_arg);
194
222asciichat_error_t thread_pool_spawn(thread_pool_t *pool, void *(*thread_func)(void *), void *thread_arg, int stop_id,
223 const char *thread_name);
224
244
254
264
Platform abstraction layer umbrella header providing unified cross-platform API.
buffer_pool_t * pool
asciichat_error_t
Error and exit codes - unified status values (0-255)
Definition error_codes.h:49
void * asciichat_thread_t
ClangTool/LibTooling compatibility shim for stdbool.h.
Condition variable type (POSIX: pthread_cond_t with debug tracking)
Definition cond.h:63
Mutex type (POSIX: pthread_mutex_t with debug tracking)
Thread pool entry (internal linked list node)
Definition thread_pool.h:99
void * thread_arg
Thread argument.
asciichat_thread_t thread
Thread handle.
struct thread_pool_entry * next
Linked list next pointer.
int stop_id
Cleanup order (lower = stop first, -1 = unordered)
char name[64]
Thread name for debugging.
Work queue entry for task-based thread pools.
Definition thread_pool.h:87
void * work_arg
Argument passed to work function.
Definition thread_pool.h:89
struct thread_pool_work_entry * next
Linked list next pointer.
Definition thread_pool.h:90
Thread pool structure.
mutex_t threads_mutex
Mutex protecting thread list.
bool is_work_queue_mode
True if using work queue mode.
thread_pool_entry_t * threads
Linked list of threads (sorted by stop_id)
cond_t work_available
Condition variable for workers to wait on.
bool shutdown_requested
Signal workers to exit.
thread_pool_work_entry_t * work_queue
Queue of pending work.
size_t thread_count
Number of threads in pool.
size_t num_workers
Number of pre-created worker threads.
mutex_t work_queue_mutex
Mutex protecting work queue.
char name[64]
Pool name for debugging.
void thread_pool_t
void thread_pool_destroy(thread_pool_t *pool)
Destroy a thread pool.
asciichat_error_t thread_pool_queue_work(const char *name, thread_pool_t *pool, void *(*work_func)(void *), void *work_arg)
Queue a named work item to a work queue pool.
asciichat_error_t thread_pool_interrupt_all(thread_pool_t *pool, int sig)
Send a signal to all threads in the pool.
thread_pool_t * thread_pool_create(const char *pool_name)
Create a new thread pool (long-lived threads mode)
Definition thread_pool.c:89
struct thread_pool_work_entry thread_pool_work_entry_t
Work queue entry for task-based thread pools.
size_t thread_pool_get_count(const thread_pool_t *pool)
Get thread count in the pool.
bool thread_pool_has_threads(const thread_pool_t *pool)
Check if pool has any threads.
asciichat_error_t thread_pool_spawn(thread_pool_t *pool, void *(*thread_func)(void *), void *thread_arg, int stop_id, const char *thread_name)
Spawn a worker thread in the pool.
asciichat_error_t thread_pool_stop_all(thread_pool_t *pool)
Stop all threads in the pool in stop_id order.
thread_pool_t * thread_pool_create_with_workers(const char *pool_name, size_t num_workers)
Create a new thread pool in work queue mode.
ARM NEON-accelerated ASCII rendering utilities (declarations)