summaryrefslogtreecommitdiff
path: root/src/ipc.c
blob: 9c4dfcca2b4a47f0e041b3d1fbeef53adf74c371 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef IPC_C
#define IPC_C

#include "ipc.h"

// https://stackoverflow.com/a/5656561
void* create_shared_memory(size_t size) {
  int protection = PROT_READ | PROT_WRITE;
  int visibility = MAP_SHARED | MAP_ANONYMOUS;
  return mmap(
    NULL,
    size,
    protection, visibility,
    -1, 0
  );
}

comm_moves comm_moves_init() {
  return (comm_moves) {
    create_shared_memory(sizeof(struct uci_move) * 50),
    0,
    50
  };
}

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;
}

#include "fen.c"
#include "bitboard.c"

#endif // IPC_C