summaryrefslogtreecommitdiff
path: root/src/ot_worker.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/ot_worker.h')
-rw-r--r--src/ot_worker.h37
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
13struct 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. */
18typedef 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. */
23struct 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. */
32int worker_start(ot_worker_run run, int64_t sock);
33
34/* Wake every worker until it has left, then join it */
35void worker_stop_all(void);
36
37#endif