Compare commits
3 Commits
01af1f5c49
...
7ae6604e10
Author | SHA1 | Date | |
---|---|---|---|
7ae6604e10 | |||
f7a6e582ed | |||
e1debcc3ae |
14
Makefile
14
Makefile
@@ -39,7 +39,9 @@ OBJ := $(addprefix $(OBJDIR)/,$(SRC_FN:.c=.o))
|
|||||||
TSTSRC := $(wildcard $(TSTDIR)/*.c)
|
TSTSRC := $(wildcard $(TSTDIR)/*.c)
|
||||||
|
|
||||||
LIB := br_$(shell uname -m) # library name
|
LIB := br_$(shell uname -m) # library name
|
||||||
LIBS := $(strip -l$(LIB))
|
LIB := $(strip $(LIB))
|
||||||
|
LIBFILE := ${BRLIBDIR}/lib$(strip ${LIB}).a
|
||||||
|
LIBS := $(addprefix -l,$(strip $(LIB)))
|
||||||
|
|
||||||
DEP_FN := $(SRC_FN)
|
DEP_FN := $(SRC_FN)
|
||||||
DEP := $(addprefix $(DEPDIR)/,$(DEP_FN:.c=.d))
|
DEP := $(addprefix $(DEPDIR)/,$(DEP_FN:.c=.d))
|
||||||
@@ -102,7 +104,7 @@ endif
|
|||||||
# if no version, use last commit and date.
|
# if no version, use last commit and date.
|
||||||
# else, if last commit != last tag commit, add commit and date to version number
|
# else, if last commit != last tag commit, add commit and date to version number
|
||||||
ifeq ($(VERSION),)
|
ifeq ($(VERSION),)
|
||||||
VERSION := $(build)-$(COMMIT)-$(DATE)
|
VERSION := $(build)-git.$(COMMIT)-$(DATE)
|
||||||
else ifneq ($(COMMIT), $(TAG_COMMIT))
|
else ifneq ($(COMMIT), $(TAG_COMMIT))
|
||||||
VERSION := $(VERSION)-next-$(build)-$(COMMIT)-$(DATE)
|
VERSION := $(VERSION)-next-$(build)-$(COMMIT)-$(DATE)
|
||||||
endif
|
endif
|
||||||
@@ -344,6 +346,7 @@ brlib:
|
|||||||
$(info calling with build=$(build))
|
$(info calling with build=$(build))
|
||||||
$(MAKE) -e -C $(BRLIB) lib-static
|
$(MAKE) -e -C $(BRLIB) lib-static
|
||||||
unexport build
|
unexport build
|
||||||
|
|
||||||
##################################### brchess binaries
|
##################################### brchess binaries
|
||||||
.PHONY: targets cleanbin cleanbindir
|
.PHONY: targets cleanbin cleanbindir
|
||||||
|
|
||||||
@@ -355,9 +358,9 @@ cleanbin:
|
|||||||
cleanbindir:
|
cleanbindir:
|
||||||
$(call rmdir,$(BINDIR),binaries)
|
$(call rmdir,$(BINDIR),binaries)
|
||||||
|
|
||||||
$(TARGET): libs $(OBJ) | $(BINDIR)
|
$(TARGET): $(LIBFILE) $(OBJ) | $(BINDIR) libs
|
||||||
@echo linking $@.
|
@echo linking $@.
|
||||||
$(CC) $(LDFLAGS) $(OBJ) $(LIBS) -o $@
|
$(CC) $(ALL_LDFLAGS) $(OBJ) -o $@
|
||||||
|
|
||||||
##################################### pre-processed (.i) and assembler (.s) output
|
##################################### pre-processed (.i) and assembler (.s) output
|
||||||
.PHONY: cleanasmcpp
|
.PHONY: cleanasmcpp
|
||||||
@@ -415,7 +418,7 @@ TEST += movedo-test perft-test tt-test
|
|||||||
PIECE_OBJS := piece.o
|
PIECE_OBJS := piece.o
|
||||||
FEN_OBJS := $(PIECE_OBJS) fen.o position.o bitboard.o board.o \
|
FEN_OBJS := $(PIECE_OBJS) fen.o position.o bitboard.o board.o \
|
||||||
hq.o attack.o hash.o init.o util.o alloc.o move.o \
|
hq.o attack.o hash.o init.o util.o alloc.o move.o \
|
||||||
eval.o eval-defs.o eval-simple.o
|
eval.o eval-defs.o eval-simple.o hist.o
|
||||||
BB_OBJS := $(FEN_OBJS)
|
BB_OBJS := $(FEN_OBJS)
|
||||||
MOVEGEN_OBJS := $(BB_OBJS) move-gen.o
|
MOVEGEN_OBJS := $(BB_OBJS) move-gen.o
|
||||||
ATTACK_OBJS := $(MOVEGEN_OBJS)
|
ATTACK_OBJS := $(MOVEGEN_OBJS)
|
||||||
@@ -490,6 +493,7 @@ wtf:
|
|||||||
@#echo LIBSRC=$(LIBSRC)
|
@#echo LIBSRC=$(LIBSRC)
|
||||||
|
|
||||||
zob:
|
zob:
|
||||||
|
echo $(LIBFILE)
|
||||||
@#$(CC) $(LDFLAGS) $(CPPFLAGS) $(CFLAGS) $< $(LIBS) src/util.c -o util
|
@#$(CC) $(LDFLAGS) $(CPPFLAGS) $(CFLAGS) $< $(LIBS) src/util.c -o util
|
||||||
|
|
||||||
##################################### End of multi-targets
|
##################################### End of multi-targets
|
||||||
|
@@ -480,3 +480,18 @@ finish:
|
|||||||
return movelist;
|
return movelist;
|
||||||
//return movelist->nmoves = moves - movelist->move;
|
//return movelist->nmoves = moves - movelist->move;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pos_gen_legal() - generate position legal moves
|
||||||
|
* @pos: position
|
||||||
|
* @movelist: &movelist_t array to store moves
|
||||||
|
*
|
||||||
|
* Generate all @pos legal moves for player-to-move.
|
||||||
|
* @movelist is filled with the moves.
|
||||||
|
*
|
||||||
|
* @Return: movelist
|
||||||
|
*/
|
||||||
|
movelist_t *pos_gen_legal(pos_t *pos, movelist_t *movelist)
|
||||||
|
{
|
||||||
|
return pos_legal(pos, pos_gen_pseudo(pos, movelist));
|
||||||
|
}
|
||||||
|
@@ -27,5 +27,6 @@ movelist_t *pos_legal_dup(const pos_t *pos, movelist_t *pseudo, movelist_t *lega
|
|||||||
movelist_t *pos_legal(const pos_t *pos, movelist_t *list);
|
movelist_t *pos_legal(const pos_t *pos, movelist_t *list);
|
||||||
|
|
||||||
movelist_t *pos_gen_pseudo(pos_t *pos, movelist_t *movelist);
|
movelist_t *pos_gen_pseudo(pos_t *pos, movelist_t *movelist);
|
||||||
|
movelist_t *pos_gen_legal(pos_t *pos, movelist_t *movelist);
|
||||||
|
|
||||||
#endif /* MOVEGEN_H */
|
#endif /* MOVEGEN_H */
|
||||||
|
70
src/thread.c
Normal file
70
src/thread.c
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/* thread.c - thread management.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 Bruno Raoult ("br")
|
||||||
|
* Licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* Some rights reserved. See COPYING.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this
|
||||||
|
* program. If not, see <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <brlib.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <poll.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
|
/* Still have to decide: thread or process ?
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
thread_pool_t threadpool;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* thrd_create - initialize thrd.
|
||||||
|
*/
|
||||||
|
int thrd_create(__unused int num)
|
||||||
|
{
|
||||||
|
int fd[2];
|
||||||
|
/* shall we make a communication channel via a pipe or socket ? */
|
||||||
|
int __unused ret = socketpair(AF_LOCAL, SOCK_SEQPACKET, PF_LOCAL, fd);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* thread_init - initialize thread pool.
|
||||||
|
*/
|
||||||
|
int thread_init(int nb)
|
||||||
|
{
|
||||||
|
nb = clamp(nb, MIN_THRDS, MAX_THRDS);
|
||||||
|
|
||||||
|
/* stop unwanted threads, always keep 1 */
|
||||||
|
for (int i = nb + 1; i < threadpool.nb; ++i) {
|
||||||
|
printf("stopping thread %d - status = \n", i);
|
||||||
|
threadpool.thread[i].cmd = THRD_DO_QUIT;
|
||||||
|
}
|
||||||
|
for (int i = threadpool.nb; i < nb; ++i) {
|
||||||
|
printf("creating thread %d - status = \n", i);
|
||||||
|
thrd_create(i);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return nb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
communication:
|
||||||
|
main thread -> thread
|
||||||
|
commands via memory
|
||||||
|
thread -> main thread
|
||||||
|
status via memory
|
||||||
|
output via pipe/socket
|
||||||
|
thread output will be output/filtered by main thread
|
||||||
|
|
||||||
|
*/
|
55
src/thread.h
Normal file
55
src/thread.h
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/* thread.h - thread management.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021-2024 Bruno Raoult ("br")
|
||||||
|
* Licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* Some rights reserved. See COPYING.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this
|
||||||
|
* program. If not, see <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef THREAD_H
|
||||||
|
#define THREAD_H
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include <brlib.h>
|
||||||
|
|
||||||
|
#include "position.h"
|
||||||
|
|
||||||
|
#define MIN_THRDS 1
|
||||||
|
#define MAX_THRDS 16
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
THRD_DEAD,
|
||||||
|
THRD_IDLE,
|
||||||
|
THRD_WORKING,
|
||||||
|
} thread_status_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
/* main thread to subs */
|
||||||
|
THRD_DO_SEARCH,
|
||||||
|
THRD_DO_STOP,
|
||||||
|
THRD_DO_QUIT,
|
||||||
|
} thread_cmd_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int id;
|
||||||
|
thread_status_t status;
|
||||||
|
thread_cmd_t cmd;
|
||||||
|
int fd[2];
|
||||||
|
pos_t pos;
|
||||||
|
} thread_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int nb;
|
||||||
|
thread_t thread[MAX_THRDS + 1];
|
||||||
|
} thread_pool_t;
|
||||||
|
|
||||||
|
int thrd_create(__unused int num);
|
||||||
|
int thread_init(int nb);
|
||||||
|
|
||||||
|
#endif /* THREAD_H */
|
Reference in New Issue
Block a user