diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-09-29 13:11:00 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-09-29 13:11:00 +0200 |
| commit | 37cbaef9ceb828c667da8f398027ba5415ee7475 (patch) | |
| tree | 6103e92a9030766e78a35df00f7a1155d0d0ecf5 /liblangdet/threadpool.h | |
| parent | cf7d8169ec12cb3adf90d4ff78b3257e74985302 (diff) | |
| download | langdet-37cbaef9ceb828c667da8f398027ba5415ee7475.tar.gz langdet-37cbaef9ceb828c667da8f398027ba5415ee7475.zip | |
Rename CPU library API and sources to langdet
Diffstat (limited to 'liblangdet/threadpool.h')
| -rw-r--r-- | liblangdet/threadpool.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/liblangdet/threadpool.h b/liblangdet/threadpool.h new file mode 100644 index 0000000..f9739a1 --- /dev/null +++ b/liblangdet/threadpool.h @@ -0,0 +1,30 @@ +#ifndef TP_THREADPOOL_H +#define TP_THREADPOOL_H + +/* Persistent worker pool for CPU kernels. + * Uses a fixed thread set that sleeps until parallel_for() gives it a callback. + * Also provides the cgroup-quota-aware CPU-count helper used to size the pool. + * + * Kept separate from the kernels so they depend only on parallel_for and + * tp_num_threads, not pool internals. + * + * kernels.h includes this, so kernel callers need no extra include. */ + +/* Worker callback: (thread index, total threads, user arg). */ +typedef void (*parallel_fn_t)(int tid, int n_threads, void *arg); + +/* Set the persistent pool size (default 1). Creates/rebuilds the pool; call + * before inference. */ +void tp_set_threads(int n); + +/* Available CPU cores, capped to a cgroup CPU quota when one is tighter. */ +int tp_get_num_cpus(void); + +/* Current pool size (1 == serial). Kernels gate parallelism on this. */ +int tp_num_threads(void); + +/* Run fn across the pool; the calling thread participates as tid 0. Blocks + * until every worker has finished. */ +void parallel_for(parallel_fn_t fn, void *arg); + +#endif /* TP_THREADPOOL_H */ |
