KEEL 1.0.0
Minimal C11 HTTP client/server library built on epoll/kqueue/io_uring/poll
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
thread_pool.h File Reference
#include <keel/allocator.h>
Include dependency graph for thread_pool.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  KlWorkItem
 Work item — passed by pointer to kl_thread_pool_submit. Copied into the internal queue (caller can stack-allocate). More...
 
struct  KlThreadPoolConfig
 Thread pool configuration. All fields have sensible defaults when set to 0/NULL. More...
 

Typedefs

typedef struct KlEventCtx KlEventCtx
 
typedef void(* KlWorkFn) (void *user_data)
 Work function — runs on a worker thread.
 
typedef void(* KlWorkDoneFn) (void *user_data)
 Done function — runs on the event loop thread after work completes.
 
typedef void(* KlWorkCancelFn) (void *user_data)
 Cancel function — runs on shutdown if work item never started.
 
typedef struct KlWorkItem KlWorkItem
 Work item — passed by pointer to kl_thread_pool_submit. Copied into the internal queue (caller can stack-allocate).
 
typedef struct KlThreadPoolConfig KlThreadPoolConfig
 Thread pool configuration. All fields have sensible defaults when set to 0/NULL.
 
typedef struct KlThreadPool KlThreadPool
 

Functions

KlThreadPoolkl_thread_pool_create (KlEventCtx *ctx, const KlThreadPoolConfig *cfg)
 Create pool, start worker threads, register pipe watcher with ctx.
 
int kl_thread_pool_submit (KlThreadPool *pool, const KlWorkItem *item)
 Submit work. Copies *item into the internal queue.
 
void kl_thread_pool_free (KlThreadPool *pool)
 Drain queue, join threads, remove watcher, free.
 

Typedef Documentation

◆ KlEventCtx

typedef struct KlEventCtx KlEventCtx

◆ KlWorkFn

typedef void(* KlWorkFn) (void *user_data)

Work function — runs on a worker thread.

◆ KlWorkDoneFn

typedef void(* KlWorkDoneFn) (void *user_data)

Done function — runs on the event loop thread after work completes.

◆ KlWorkCancelFn

typedef void(* KlWorkCancelFn) (void *user_data)

Cancel function — runs on shutdown if work item never started.

◆ KlWorkItem

typedef struct KlWorkItem KlWorkItem

Work item — passed by pointer to kl_thread_pool_submit. Copied into the internal queue (caller can stack-allocate).

◆ KlThreadPoolConfig

Thread pool configuration. All fields have sensible defaults when set to 0/NULL.

◆ KlThreadPool

typedef struct KlThreadPool KlThreadPool

Function Documentation

◆ kl_thread_pool_create()

KlThreadPool * kl_thread_pool_create ( KlEventCtx ctx,
const KlThreadPoolConfig cfg 
)

Create pool, start worker threads, register pipe watcher with ctx.

Parameters
ctxEvent context (for event loop + allocator).
cfgConfiguration (NULL = all defaults).
Returns
Pool on success, NULL on failure.

◆ kl_thread_pool_submit()

int kl_thread_pool_submit ( KlThreadPool pool,
const KlWorkItem item 
)

Submit work. Copies *item into the internal queue.

Parameters
poolThread pool.
itemWork item (copied — caller can stack-allocate).
Returns
0 on success, -1 if queue full (backpressure).

◆ kl_thread_pool_free()

void kl_thread_pool_free ( KlThreadPool pool)

Drain queue, join threads, remove watcher, free.