#ifndef ENGINE_THREADS_H #define ENGINE_THREADS_H #include #include #include "bitboard.h" #include "engine/ttable.h" #include "ipc/engine_message.h" #include "ipc/go_args.h" enum { SPLITPOINT_STATE_FREE, SPLITPOINT_STATE_ACTIVE }; enum { NODE_PV, NODE_CUT, NODE_ALL }; typedef struct split_point { atomic_int state; atomic_int next_move_idx; atomic_int alpha, beta; atomic_int best_score; atomic_int workers; move_t best_score; struct split_point *parent; int ply; int node_type; int confidence; position_t position_snapshot; moves_t moves; } split_point_t; struct child_thread_args { // signal sent by threads manager atomic_int stop; // signal sent by thread atomic_int finished; int id; go_args_t *go_args; position_t position; int sp_stack; int }; struct root_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; }; typedef union { struct child_thread_args child_thread_args; struct root_thread_args root_thread_args; } thread_args_t; struct threads { pthread_t *threads; thread_args_t *args; size_t count; size_t capacity; int running_count; engine_messages_t *engine_messages; go_args_t *go_args; position_t *position; ttable_t ttable; void* split_point_pool; }; #ifdef ENGINE_THREADS_INTERNAL void __threads_args_init( thread_args_t* 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 *child_thread(void *args); void *root_thread(void *args); #endif // ENGINE_THREADS_H