/* This software was written by Dirk Engling It is considered beerware. Prost. Skol. Cheers or whatever. $id$ */ #ifndef OT_WORKER_H__ #define OT_WORKER_H__ #include #include #include #include "trackerlogic.h" struct ot_worker; /* What a worker does between being started and being told to stop. It reads worker->sock and works out of worker->ws; everything around it, from the buffers to the counters to saying goodbye, is handled here. */ typedef void (*ot_worker_run)(struct ot_worker *worker); /* A thread that serves requests on a socket of its own, with the buffers and counters it needs. Each is allocated on its own, so taking on another one never moves the record a running worker holds. */ struct ot_worker { pthread_t thread; _Atomic int left; int64_t sock; ot_worker_run run; struct ot_workstruct ws; }; /* Start one. Returns -1 if it could not be started. */ int worker_start(ot_worker_run run, int64_t sock); /* Wake every worker until it has left, then join it */ void worker_stop_all(void); #endif