diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-02 20:50:24 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-02 21:14:02 +0100 |
| commit | ad541c67761b8aa6da1566802c347cac4018d0c2 (patch) | |
| tree | a9166fa9d349911d69a6948e53b05344dcc348a0 /src/ot_worker.h | |
| parent | c679ff8a3b1418a5960cc49ba6458a0007df54fa (diff) | |
Move the build sources into src/
Diffstat (limited to 'src/ot_worker.h')
| -rw-r--r-- | src/ot_worker.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/ot_worker.h b/src/ot_worker.h new file mode 100644 index 0000000..4954773 --- /dev/null +++ b/src/ot_worker.h | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | /* This software was written by Dirk Engling <erdgeist@erdgeist.org> | ||
| 2 | It is considered beerware. Prost. Skol. Cheers or whatever. */ | ||
| 3 | |||
| 4 | #ifndef OT_WORKER_H__ | ||
| 5 | #define OT_WORKER_H__ | ||
| 6 | |||
| 7 | #include <pthread.h> | ||
| 8 | #include <stdatomic.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | |||
| 11 | #include "trackerlogic.h" | ||
| 12 | |||
| 13 | struct ot_worker; | ||
| 14 | |||
| 15 | /* What a worker does between being started and being told to stop. It reads | ||
| 16 | worker->sock and works out of worker->ws; everything around it, from the | ||
| 17 | buffers to the counters to saying goodbye, is handled here. */ | ||
| 18 | typedef void (*ot_worker_run)(struct ot_worker *worker); | ||
| 19 | |||
| 20 | /* A thread that serves requests on a socket of its own, with the buffers and | ||
| 21 | counters it needs. Each is allocated on its own, so taking on another one | ||
| 22 | never moves the record a running worker holds. */ | ||
| 23 | struct ot_worker { | ||
| 24 | pthread_t thread; | ||
| 25 | _Atomic int left; | ||
| 26 | int64_t sock; | ||
| 27 | ot_worker_run run; | ||
| 28 | struct ot_workstruct ws; | ||
| 29 | }; | ||
| 30 | |||
| 31 | /* Start one. Returns -1 if it could not be started. */ | ||
| 32 | int worker_start(ot_worker_run run, int64_t sock); | ||
| 33 | |||
| 34 | /* Wake every worker until it has left, then join it */ | ||
| 35 | void worker_stop_all(void); | ||
| 36 | |||
| 37 | #endif | ||
