summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/engine/thread.c12
-rw-r--r--src/engine/threads.c16
-rw-r--r--src/uci.c3
-rw-r--r--src/uci/command.c15
4 files changed, 32 insertions, 14 deletions
diff --git a/src/engine/thread.c b/src/engine/thread.c
index 017e9b6..25e583e 100644
--- a/src/engine/thread.c
+++ b/src/engine/thread.c
@@ -1,8 +1,8 @@
#include "engine/threads.h"
#include <stdio.h>
-void *engine_thread(void *_args) {
- struct thread_args *args = (struct thread_args*)_args;
+void *child_thread(void *_args) {
+ struct child_thread_args *args = (struct child_thread_args*)_args;
args->stop = 0;
int depth = 0;
@@ -32,3 +32,11 @@ void *engine_thread(void *_args) {
args->stop = 2;
}
+// DTS requires a root thread which is initialize the search tree, and the
+// others who use that search tree. it's as if root_thread is the owner of the
+// tree
+void *root_thread(void *_args) {
+ struct root_thread_args *args = (struct root_thread_args*)_args;
+ args->stop = 0;
+}
+
diff --git a/src/engine/threads.c b/src/engine/threads.c
index 5afe155..541efb1 100644
--- a/src/engine/threads.c
+++ b/src/engine/threads.c
@@ -48,7 +48,7 @@ void threads_go(struct threads *handler) {
pthread_create(
handler->threads + i,
NULL,
- engine_thread,
+ i == 0 ? root_thread : child_thread,
handler->args + i
);
}
@@ -78,10 +78,22 @@ void threads_cleanup(struct threads *handler) {
}
void __threads_args_init(
- struct thread_args* args,
+ thread_args_t* _args,
struct threads *handler,
int i
) {
+ if (i > 0) {
+ struct child_thread_args *args = _args;
+ atomic_init(&args->stop, 0);
+ atomic_init(&args->finished, 0);
+ args->id = i;
+ args->position = handler->position;
+ args->go_args = handler->go_args;
+ args->message = handler->engine_messages->data[i];
+ return;
+ }
+
+ struct root_thread_args *args = _args;
atomic_init(&args->stop, 0);
atomic_init(&args->finished, 0);
args->id = i;
diff --git a/src/uci.c b/src/uci.c
index f842328..7b1ab8c 100644
--- a/src/uci.c
+++ b/src/uci.c
@@ -37,7 +37,8 @@ void *uci(ipc_state_t *ipc_state) {
// https://stackoverflow.com/a/41559081
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
- uci_cmd_t cmd = uci_cmd_init();
+ uci_cmd_t cmd;
+ uci_cmd_init(&cmd);
size_t n;
char buf[1024];
diff --git a/src/uci/command.c b/src/uci/command.c
index 583b887..327e0e2 100644
--- a/src/uci/command.c
+++ b/src/uci/command.c
@@ -3,14 +3,10 @@
#include <stdlib.h>
#include "uci/internals/command.h"
-uci_cmd_t uci_cmd_init() {
- uci_cmd_t output = {0};
-
- output.empty = true;
- output.args_capacity = 32;
- output.args = calloc(sizeof(char) * MAX_TOKEN_SIZE, output.args_capacity);
-
- return output;
+void uci_cmd_init(uci_cmd_t *cmd) {
+ cmd->empty = true;
+ cmd->args_capacity = 32;
+ cmd->args = calloc(sizeof(char) * MAX_TOKEN_SIZE, output.args_capacity);
}
bool is_valid_cmd(const char *token) {
@@ -122,7 +118,8 @@ bool test_uci_cmd_t() {
}
bool test_invalid_cmd_uci_cmd_t() {
- uci_cmd_t cmd = uci_cmd_init();
+ uci_cmd_t cmd;
+ uci_cmd_init(&cmd);
uci_cmd_add(&cmd, "john");
uci_cmd_add(&cmd, "debug");