summaryrefslogtreecommitdiff
path: root/src/ipc/state.c
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 /src/ipc/state.c
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 'src/ipc/state.c')
-rw-r--r--src/ipc/state.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/ipc/state.c b/src/ipc/state.c
new file mode 100644
index 0000000..02ba38b
--- /dev/null
+++ b/src/ipc/state.c
@@ -0,0 +1,41 @@
+#include <string.h>
+#include <assert.h>
+
+#define IPC_INTERNAL
+#include "ipc/state.h"
+
+void ipc_state_init(ipc_state_t *state) {
+ // done by main.c in the loop
+ // engine_messages_init(&state->engine_messages);
+ uci_state_init(&state->uci_state);
+ state->from_position = (position_t) {0};
+ ipc_moves_init(&state->moves);
+ state->uci_state.moves = &state->moves;
+ atomic_init(&state->event, EVENT_INIT);
+}
+
+void ipc_state_deinit(ipc_state_t *state) {
+ engine_messages_deinit(&state->engine_messages);
+ uci_state_deinit(&state->uci_state);
+ ipc_moves_deinit(&state->moves);
+}
+
+void ipc_state_game_reset(ipc_state_t *state) {
+ state->from_position = (position_t) {0};
+ state->moves.count = 0;
+}
+
+void ipc_state_wait_for_event(ipc_state_t *state, size_t event) {
+ assert(event < EVENTS_COUNT);
+ while (!ipc_state_is_event(state, event));
+}
+
+bool ipc_state_is_event(ipc_state_t *state, size_t event) {
+ assert(event < EVENTS_COUNT);
+ return atomic_load(&state->event) == event;
+}
+
+void ipc_state_set_event(ipc_state_t *state, size_t event) {
+ assert(event < EVENTS_COUNT);
+ atomic_store(&state->event, event);
+}