Mercurial
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 249:c5129452493e | 250:745fd127b2a1 |
|---|---|
| 5 ## Features | 5 ## Features |
| 6 | 6 |
| 7 - HTTP/HTTPS client | 7 - HTTP/HTTPS client |
| 8 - SSL/TLS support | 8 - SSL/TLS support |
| 9 - Async networking with libuv | 9 - Async networking with libuv |
| 10 - Joinable/detached tasks and bounded worker pools | |
| 10 - Snapshot testing utilities | 11 - Snapshot testing utilities |
| 11 | 12 |
| 12 ## Files | 13 ## Files |
| 13 | 14 |
| 14 | File | Description | | 15 | File | Description | |
| 17 | `seobeo_internal.h` | Internal declarations | | 18 | `seobeo_internal.h` | Internal declarations | |
| 18 | `s_http_client.c` | HTTP client implementation | | 19 | `s_http_client.c` | HTTP client implementation | |
| 19 | `s_network.c` | Network utilities | | 20 | `s_network.c` | Network utilities | |
| 20 | `s_ssl.c` | SSL/TLS handling | | 21 | `s_ssl.c` | SSL/TLS handling | |
| 21 | `s_logging.c` | Logging utilities | | 22 | `s_logging.c` | Logging utilities | |
| 23 | `s_worker.c` | Thread and worker-pool implementation | | |
| 24 | `seobeo_worker.h` | Public worker API | | |
| 22 | `snapshot_creator.c/h` | Snapshot testing | | 25 | `snapshot_creator.c/h` | Snapshot testing | |
| 23 | `docs/` | Documentation | | 26 | `docs/` | Documentation | |
| 24 | `examples/` | Usage examples | | 27 | `examples/` | Usage examples | |
| 25 | `tests/` | Unit tests | | 28 | `tests/` | Unit tests | |
| 26 | `os/` | OS-specific code | | 29 | `os/` | OS-specific code | |
| 41 ```bash | 44 ```bash |
| 42 bazel build //seobeo:seobeo | 45 bazel build //seobeo:seobeo |
| 43 bazel test //seobeo:seobeo_test | 46 bazel test //seobeo:seobeo_test |
| 44 ``` | 47 ``` |
| 45 | 48 |
| 49 ## Background workers | |
| 50 | |
| 51 Use a detached task for simple fire-and-forget work: | |
| 52 | |
| 53 ```c | |
| 54 void Convert_Image(void *p_context) | |
| 55 { | |
| 56 Conversion *p_conversion = p_context; | |
| 57 Run_FFmpeg(p_conversion); | |
| 58 } | |
| 59 | |
| 60 Seobeo_Worker_Result result = | |
| 61 Seobeo_Thread_Start_Detached( | |
| 62 Convert_Image, | |
| 63 p_conversion, | |
| 64 free); | |
| 65 if (result != SEOBEO_WORKER_OK) | |
| 66 free(p_conversion); | |
| 67 ``` | |
| 68 | |
| 69 Use a bounded pool when requests can enqueue expensive work: | |
| 70 | |
| 71 ```c | |
| 72 Seobeo_Worker_Pool *p_pool = | |
| 73 Seobeo_Worker_Pool_Create(2, 16); | |
| 74 | |
| 75 Seobeo_Worker_Result result = | |
| 76 Seobeo_Worker_Pool_Submit( | |
| 77 p_pool, | |
| 78 Convert_Image, | |
| 79 p_conversion, | |
| 80 free); | |
| 81 | |
| 82 Seobeo_Worker_Pool_Shutdown(p_pool, TRUE); | |
| 83 Seobeo_Worker_Pool_Destroy(p_pool); | |
| 84 ``` | |
| 85 | |
| 86 Submitting transfers context ownership only when it returns | |
| 87 `SEOBEO_WORKER_OK`. Cleanup runs after successful work and for queued tasks | |
| 88 discarded by a non-draining shutdown. User callbacks never run while the pool | |
| 89 mutex is held. | |
| 90 | |
| 46 ## Dependencies | 91 ## Dependencies |
| 47 | 92 |
| 48 - libuv (via //third_party/libuv) | 93 - libuv (via //third_party/libuv) |
| 49 - OpenSSL | 94 - OpenSSL |