diff options
| author | Aargh Rai <aargh.rai+git@gmail.com> | 2026-07-13 21:58:18 +0530 |
|---|---|---|
| committer | Aargh Rai <aargh.rai+git@gmail.com> | 2026-07-13 21:58:18 +0530 |
| commit | f8c0dc54e36cc201c657aa12e5a22029b092e1bc (patch) | |
| tree | a0dd1a42c9681be98a7508c128db0dacacefc2e7 /src/main.c | |
| parent | 2e8b78ab0ef01eaacd8094ff839ac93b4451e9c3 (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/main.c')
| -rw-r--r-- | src/main.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..d71585b --- /dev/null +++ b/src/main.c @@ -0,0 +1,90 @@ +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <pthread.h> +#include "fcntl.h" + +#include "ipc/state.h" +#include "ipc/threads.h" +#include "ipc/uci.h" + +void *uci_thread_func(void* data) { + ipc_state_t *state = (ipc_state_t*)data; + return uci(state); +} + +int main(int argc, char** argv) { + ipc_state_t ipc_state; + ipc_state_init(&ipc_state); + + pthread_t uci_thread; + pthread_create(&uci_thread, NULL, uci_thread_func, (void*)&ipc_state); + + struct threads engine_threads = {0}; + threads_init(&engine_threads, ipc_state.uci_state.threads); + threads_link(&engine_threads, &ipc_state); + + engine_messages_init(&ipc_state.engine_messages); + goto skip_refresh; +waiting_for_go: + engine_messages_refresh(&ipc_state.engine_messages); +skip_refresh: + ipc_state_wait_for_event(&ipc_state, EVENT_ENGINE_GO); + + engine_threads.running_count = ipc_state.uci_state.threads; + ipc_state.engine_messages.count = ipc_state.uci_state.threads; + threads_reserve(&engine_threads, ipc_state.uci_state.threads); + threads_go(&engine_threads); + + ipc_state_set_event(&ipc_state, EVENT_UCI_RUNNING); + + bool is_stop; + while (1) { + while ( + !ipc_state_is_event(&ipc_state, EVENT_ENGINE_RUNNING) && + !(is_stop = ipc_state_is_event(&ipc_state, EVENT_ENGINE_STOP)) + ); + if (is_stop) { + printf("ENDED\n"); + threads_cleanup(&engine_threads); + ipc_state_set_event(&ipc_state, EVENT_UCI_RUNNING); + goto waiting_for_go; + } + threads_go_loop(&engine_threads); + ipc_state_set_event(&ipc_state, EVENT_UCI_RUNNING); + // if (atomic_load(&ipc_state->state.quit)) break; + // if (atomic_load(&ipc_state->state.cleanup)) { + // set_threads(&engine_threads, 0); + // for (int i = 0; i < engine_threads.count; i++) { + // engine_threads.args[i].stop = -1; + // } + // } + // if (atomic_load(&ipc_state->state.go)) { + // printf("going\n"); + // engine_threads.sharing_position = ipc_state->state.position; + // engine_threads.go_args = (struct go_args*)ipc_state->state.go_args; + // set_threads(&engine_threads, ipc_state->state.threads); + // atomic_store(&ipc_state->state.go, 0); + // atomic_store(&ipc_state->state.go_ready_receive, 1); + // } + // if (atomic_load(&ipc_state->state.stop)) { + // printf("stopping\n"); + // send_stop_signal(&engine_threads); + // if (!all_stopped(&engine_threads)) continue; + // set_threads(&engine_threads, 0); + // for (int i = 0; i < engine_threads.count; i++) { + // engine_threads.args[i].stop = -1; + // } + // atomic_store(&ipc_state->state.stop, 0); + // } + } + + ipc_state_deinit(&ipc_state); + pthread_cancel(uci_thread); + threads_deinit(&engine_threads); + return 0; +} + +#include "fen.c" +#include "bitboard.c" |
