Mercurial
diff seobeo/README.md @ 250:745fd127b2a1
[seobeo] Add bounded worker interface
Co-authored-by: Copilot <[email protected]>
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Tue, 04 Aug 2026 06:23:37 -0700 |
| parents | b818a4561a3c |
| children | 609d3c6aff4e |
line wrap: on
line diff
--- a/seobeo/README.md Tue Aug 04 04:16:45 2026 -0700 +++ b/seobeo/README.md Tue Aug 04 06:23:37 2026 -0700 @@ -7,6 +7,7 @@ - HTTP/HTTPS client - SSL/TLS support - Async networking with libuv +- Joinable/detached tasks and bounded worker pools - Snapshot testing utilities ## Files @@ -19,6 +20,8 @@ | `s_network.c` | Network utilities | | `s_ssl.c` | SSL/TLS handling | | `s_logging.c` | Logging utilities | +| `s_worker.c` | Thread and worker-pool implementation | +| `seobeo_worker.h` | Public worker API | | `snapshot_creator.c/h` | Snapshot testing | | `docs/` | Documentation | | `examples/` | Usage examples | @@ -43,6 +46,48 @@ bazel test //seobeo:seobeo_test ``` +## Background workers + +Use a detached task for simple fire-and-forget work: + +```c +void Convert_Image(void *p_context) +{ + Conversion *p_conversion = p_context; + Run_FFmpeg(p_conversion); +} + +Seobeo_Worker_Result result = + Seobeo_Thread_Start_Detached( + Convert_Image, + p_conversion, + free); +if (result != SEOBEO_WORKER_OK) + free(p_conversion); +``` + +Use a bounded pool when requests can enqueue expensive work: + +```c +Seobeo_Worker_Pool *p_pool = + Seobeo_Worker_Pool_Create(2, 16); + +Seobeo_Worker_Result result = + Seobeo_Worker_Pool_Submit( + p_pool, + Convert_Image, + p_conversion, + free); + +Seobeo_Worker_Pool_Shutdown(p_pool, TRUE); +Seobeo_Worker_Pool_Destroy(p_pool); +``` + +Submitting transfers context ownership only when it returns +`SEOBEO_WORKER_OK`. Cleanup runs after successful work and for queued tasks +discarded by a non-draining shutdown. User callbacks never run while the pool +mutex is held. + ## Dependencies - libuv (via //third_party/libuv)