summaryrefslogtreecommitdiff
path: root/src/ipc.c
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-07-06 23:39:55 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-07-06 23:39:55 +0530
commit3c540db464f4034d0a393b076c79a26851f68f47 (patch)
treee9e94fb838b05818948f4f4596f0db6acba4402c /src/ipc.c
parent1876294f217d7faa2a07dbaaaab82d142ce42803 (diff)
removed unnescessary stuff + ipc with shared memory + somehow the build is faster?
Diffstat (limited to 'src/ipc.c')
-rw-r--r--src/ipc.c133
1 files changed, 20 insertions, 113 deletions
diff --git a/src/ipc.c b/src/ipc.c
index d7ef968..9c4dfcc 100644
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -1,133 +1,40 @@
#ifndef IPC_C
#define IPC_C
-#include <stdlib.h>
-#include <sys/mman.h>
-
-#include "engine/fen.h"
-
-typedef struct {
- struct uci_move *moves;
- int count;
- int capacity;
-} comm_moves;
-
-void add_comm_move(comm_moves *moves, struct uci_move move) {
- if (moves->count + 1 > moves->capacity) {
- moves->capacity += 50;
- moves->moves = realloc(moves->moves, moves->capacity * sizeof(struct uci_move));
- }
- moves->moves[moves->count++] = move;
-}
-
-typedef struct {
- bool engine_message_ready;
- int depth;
- int seldepth;
- int multipv;
- int score_cp;
- int nodes;
- int nps;
- int hashfull;
- int tbhits;
- int time;
- comm_moves pv;
-
- bool uci_message_ready;
- struct fen_load from_position;
- comm_moves moves;
-} comms;
+#include "ipc.h"
// https://stackoverflow.com/a/5656561
-comms* create_shared_memory() {
+void* create_shared_memory(size_t size) {
int protection = PROT_READ | PROT_WRITE;
int visibility = MAP_SHARED | MAP_ANONYMOUS;
- comms* state = (comms*)mmap(
+ return mmap(
NULL,
- sizeof(comms),
+ size,
protection, visibility,
-1, 0
);
- state->engine_message_ready = false;
- state->depth = 0;
- state->seldepth = 0;
- state->multipv = 0;
- state->score_cp = 0;
- state->nodes = 0;
- state->nps = 0;
- state->hashfull = 0;
- state->tbhits = 0;
- state->time = 0;
- state->pv = (comm_moves) {
- (comms*)mmap(
- NULL,
- sizeof(struct uci_move) * 50,
- protection, visibility,
- -1, 0
- ), 0, 50
- };
- state->uci_message_ready = false;
- state->from_position = {0};
- state->moves = (comm_moves) {
- (comms*)mmap(
- NULL,
- sizeof(struct uci_move) * 50,
- protection, visibility,
- -1, 0
- ), 0, 50
- };
-
- return state;
-}
-
-void send_uci_message(
- comms *comms,
- struct fen_load from_position
-) {
- comms->from_position = from_position;
- comms->uci_message_ready = true;
-}
-
-void send_engine_message(
- comms *comms,
- int depth,
- int seldepth,
- int multipv,
- int score_cp,
- int nodes,
- int nps,
- int hashfull,
- int tbhits,
- int time
-) {
- comms->depth = depth;
- comms->seldepth = seldepth;
- comms->multipv = multipv;
- comms->score_cp = score_cp;
- comms->nodes = nodes;
- comms->nps = nps;
- comms->hashfull = hashfull;
- comms->tbhits = tbhits;
- comms->time = time;
- comms->engine_message_ready = true;
}
-bool receive_uci_message(comms *comms) {
- if (comms->uci_message_ready) {
- comms->uci_message_ready = false;
- return true;
- }
- return false;
+comm_moves comm_moves_init() {
+ return (comm_moves) {
+ create_shared_memory(sizeof(struct uci_move) * 50),
+ 0,
+ 50
+ };
}
-// TODO: think about dealing with multiple engine messages
-bool receive_engine_message(comms *comms) {
- if (comms->engine_message_ready) {
- comms->engine_message_ready = false;
- return true;
+void add_comm_move(comm_moves *moves, struct uci_move move) {
+ if (moves->count + 1 > moves->capacity) {
+ moves->capacity += 50;
+ moves->moves = realloc(
+ moves->moves,
+ moves->capacity * sizeof(struct uci_move)
+ );
}
- return false;
+ moves->moves[moves->count++] = move;
}
+#include "fen.c"
+#include "bitboard.c"
#endif // IPC_C