aboutsummaryrefslogtreecommitdiff
path: root/tpool.h
diff options
context:
space:
mode:
authorGuangxiong Lin <[email protected]>2022-12-09 16:46:49 +0800
committerGuangxiong Lin <[email protected]>2022-12-09 19:39:08 +0800
commit49839c88a98d3798f7b18c58f54f26f36cacff38 (patch)
tree5cb4ee13f9bdb0ef25e39a07a628f6f16da18e87 /tpool.h
parent0457119acb36b89b6f2f4534fe8ad94b19540bbd (diff)
downloadtinyserver-49839c88a98d3798f7b18c58f54f26f36cacff38.tar.gz
tinyserver-49839c88a98d3798f7b18c58f54f26f36cacff38.tar.bz2
tinyserver-49839c88a98d3798f7b18c58f54f26f36cacff38.zip
Implement a simple thread pool and refactor
Refactor
Diffstat (limited to 'tpool.h')
-rw-r--r--tpool.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/tpool.h b/tpool.h
new file mode 100644
index 0000000..e1079ef
--- /dev/null
+++ b/tpool.h
@@ -0,0 +1,20 @@
+#include <stdbool.h>
+#include <stdlib.h>
+
+#ifndef __TPOOL_H
+#define __TPOOL_H
+
+struct tpool;
+typedef struct tpool tpool_t;
+
+extern tpool_t *tpool;
+
+typedef void (*thread_func_t)(void *arg);
+
+tpool_t *tpool_create(size_t num);
+void tpool_destroy(tpool_t *tp);
+
+bool tpool_add_work(tpool_t *tp, thread_func_t func, void *arg);
+void tpool_wait(tpool_t *tp);
+
+#endif