-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy paththread.h
124 lines (107 loc) · 3.13 KB
/
thread.h
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
Fire is a freeware UCI chess playing engine authored by Norman Schmidt.
Fire utilizes many state-of-the-art chess programming ideas and techniques
which have been documented in detail at https://www.chessprogramming.org/
and demonstrated via the very strong open-source chess engine Stockfish...
https://github.com/official-stockfish/Stockfish.
Fire is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or any later version.
You should have received a copy of the GNU General Public License with
this program: copying.txt. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <thread>
#include <vector>
#include "fire.h"
#include "endgame.h"
#include "material.h"
#include "movepick.h"
#include "mutex.h"
#include "pawn.h"
#include "position.h"
#include "search.h"
class thread
{
std::thread native_thread_;
Mutex mutex_;
ConditionVariable sleep_condition_;
bool exit_, search_active_;
int thread_index_;
public:
thread();
virtual ~thread();
virtual void begin_search();
void idle_loop();
void wake(bool activate_search);
void wait_for_search_to_end();
void wait(std::atomic_bool& condition);
threadinfo* ti{};
cmhinfo* cmhi{};
position* root_position{};
rootmoves root_moves;
int completed_depth = no_depth;
int active_pv{};
};
struct cmhinfo
{
counter_move_history counter_move_stats;
};
struct threadinfo
{
position root_position{};
position_info position_inf[1024]{};
s_move move_list[8192]{};
move_value_stats history{};
move_value_stats evasion_history{};
max_gain_stats max_gain_table;
counter_move_stats counter_moves{};
counter_follow_up_move_stats counter_followup_moves;
move_value_stats capture_history{};
material::material_hash material_table{};
pawn::pawn_hash pawn_table{};
};
struct mainthread final : thread
{
void begin_search() override;
bool quick_move_allow = false, quick_move_played = false, quick_move_evaluation_busy = false;
bool quick_move_evaluation_stopped = false, failed_low = false;
int best_move_changed = 0;
int previous_root_score = score_0;
int interrupt_counter = 0;
int previous_root_depth = {};
};
struct threadpool : std::vector<thread*>
{
void init();
void exit();
int thread_count{};
time_point start{};
int total_analyze_time{};
thread* threads[max_threads]{};
mainthread* main()
{
return static_cast<mainthread*>(threads[0]);
}
void begin_search(position&, const search_limit&);
void change_thread_count(int num_threads);
[[nodiscard]] uint64_t visited_nodes() const;
[[nodiscard]] uint64_t tb_hits() const;
static void delete_counter_move_history();
int active_thread_count{};
side contempt_color = num_sides;
int piece_contempt{};
int root_contempt_value = score_0;
endgames end_games;
position* root_position{};
rootmoves root_moves;
position_info* root_position_info{};
bool analysis_mode{};
int fifty_move_distance{};
int multi_pv{}, multi_pv_max{};
bool dummy_null_move_threat{}, dummy_prob_cut{};
};
extern threadpool thread_pool;