summaryrefslogtreecommitdiff
path: root/include/engine/threads.h
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-07-13 21:58:18 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-07-13 21:58:18 +0530
commitf8c0dc54e36cc201c657aa12e5a22029b092e1bc (patch)
treea0dd1a42c9681be98a7508c128db0dacacefc2e7 /include/engine/threads.h
parent2e8b78ab0ef01eaacd8094ff839ac93b4451e9c3 (diff)
restructed all the files + uci done now
also broke the symbol analyser in the process, i didn't help much, i had to pull out the pen & paper, but it made a cool graph never the less multithreading was a pain! but it got it in the end fixed the structs naming convention, if it's used outside by other files, it's typedeffed, otherwise it's not fixed the recursive imports issued i had in go_args*, where i was casting it to void* in uci to make it work now response.c doesn't deal with ipc, really happy with that change now every single thing has its own responsibility
Diffstat (limited to 'include/engine/threads.h')
-rw-r--r--include/engine/threads.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/include/engine/threads.h b/include/engine/threads.h
new file mode 100644
index 0000000..4815a4c
--- /dev/null
+++ b/include/engine/threads.h
@@ -0,0 +1,53 @@
+#ifndef ENGINE_THREADS_H
+#define ENGINE_THREADS_H
+
+#include <pthread.h>
+#include <stdatomic.h>
+
+#include "bitboard.h"
+#include "ipc/engine_message.h"
+#include "ipc/go_args.h"
+
+struct thread_args {
+ // signal sent by threads manager
+ atomic_int stop;
+
+ // signal sent by thread
+ atomic_int finished;
+
+ int id;
+ position_t *position;
+ go_args_t *go_args;
+ engine_message_handler_t *message;
+};
+
+struct threads {
+ pthread_t *threads;
+ struct thread_args *args;
+ size_t count;
+ size_t capacity;
+
+ int running_count;
+ engine_messages_t *engine_messages;
+ go_args_t *go_args;
+ position_t *position;
+};
+
+#ifdef ENGINE_THREADS_INTERNAL
+void __threads_args_init(
+ struct thread_args* args,
+ struct threads *handler,
+ int i
+);
+#endif
+void threads_init(struct threads *handler, size_t capacity);
+void threads_deinit(struct threads *handler);
+void threads_reserve(struct threads *handler, size_t capacity);
+void threads_go(struct threads *handler);
+bool threads_go_loop(struct threads *handler);
+bool threads_all_done(struct threads *handler);
+void threads_cleanup(struct threads *handler);
+
+void *engine_thread(void *args);
+
+#endif // ENGINE_THREADS_H