Skip to content

Commit

Permalink
Bench: 30658368
Browse files Browse the repository at this point in the history
  • Loading branch information
TerjeKir committed Nov 18, 2023
1 parent 865bc25 commit ffed687
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@


SearchLimits Limits = { .multiPV = 1 };
volatile bool ABORT_SIGNAL;
volatile bool SEARCH_STOPPED = true;
atomic_bool ABORT_SIGNAL;
atomic_bool SEARCH_STOPPED = true;

static int Reductions[2][32][32];

Expand Down Expand Up @@ -70,7 +70,7 @@ static int Quiescence(Thread *thread, Stack *ss, int alpha, const int beta) {
int bestScore = -INFINITE;

// Check time situation
if (OutOfTime(thread) || ABORT_SIGNAL)
if (OutOfTime(thread) || LoadRelaxed(ABORT_SIGNAL))
longjmp(thread->jumpBuffer, true);

// Position is drawn
Expand Down Expand Up @@ -193,7 +193,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth
const bool root = ss->ply == 0;

// Check time situation
if (OutOfTime(thread) || ABORT_SIGNAL)
if (OutOfTime(thread) || LoadRelaxed(ABORT_SIGNAL))
longjmp(thread->jumpBuffer, true);

// Early exits
Expand Down
4 changes: 2 additions & 2 deletions src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ typedef struct {


extern SearchLimits Limits;
extern volatile bool ABORT_SIGNAL;
extern volatile bool SEARCH_STOPPED;
extern atomic_bool ABORT_SIGNAL;
extern atomic_bool SEARCH_STOPPED;


void *SearchPosition(void *pos);
4 changes: 2 additions & 2 deletions src/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ void RunWithAllThreads(void *(*func)(void *)) {
}

// Thread sleeps until it is woken up
void Wait(volatile bool *condition) {
void Wait(atomic_bool *condition) {
pthread_mutex_lock(&mutex);
while (!*condition)
while (!atomic_load(condition))
pthread_cond_wait(&sleepCondition, &mutex);
pthread_mutex_unlock(&mutex);
}
Expand Down
2 changes: 1 addition & 1 deletion src/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ void StartHelpers(void *(*func)(void *));
void WaitForHelpers();
void ResetThreads();
void RunWithAllThreads(void *(*func)(void *));
void Wait(volatile bool *condition);
void Wait(atomic_bool *condition);
void Wake();
3 changes: 3 additions & 0 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <assert.h>
#include <inttypes.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stdio.h>

Expand All @@ -31,6 +32,8 @@
#define INLINE static inline __attribute__((always_inline))
#define CONSTR(prio) static __attribute__((constructor (1000 + prio))) void

#define LoadRelaxed(x) atomic_load_explicit(&(x), memory_order_relaxed)

#define lastMoveNullMove (!root && history(-1).move == NOMOVE)
#define history(offset) (pos->gameHistory[pos->histPly + offset])

Expand Down

0 comments on commit ffed687

Please sign in to comment.