19 memset(pool, 0,
sizeof(*pool));
66 const char *thread_name) {
81 memset(entry, 0,
sizeof(*entry));
121 log_debug(
"Spawned thread '%s' (stop_id=%d) in pool '%s' (total_threads=%zu)", entry->
name, stop_id, pool->
name,
136 log_debug(
"Thread pool '%s' has no threads to stop", pool->
name);
149 log_warn(
"Failed to join thread '%s' in pool '%s'", entry->
name, pool->
name);
#define SAFE_STRNCPY(dst, src, size)
#define SAFE_MALLOC(size, cast)
#define SAFE_SNPRINTF(buffer, buffer_size,...)
#define SET_ERRNO(code, context_msg,...)
Set error code with custom context message and log it.
asciichat_error_t
Error and exit codes - unified status values (0-255)
#define log_warn(...)
Log a WARN message.
#define log_debug(...)
Log a DEBUG message.
๐ Logging API with multiple log levels and terminal output control
Thread pool entry (internal linked list node)
void *(* thread_func)(void *)
Thread function.
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.
mutex_t threads_mutex
Mutex protecting thread list.
thread_pool_entry_t * threads
Linked list of threads (sorted by stop_id)
size_t thread_count
Number of threads in pool.
char name[64]
Pool name for debugging.
void thread_pool_destroy(thread_pool_t *pool)
Destroy a thread pool.
thread_pool_t * thread_pool_create(const char *pool_name)
Create a new thread pool.
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.
๐งต Generic thread pool abstraction for managing worker threads
Common SIMD utilities and structures.