-#include "thread_win32.h"
-
-struct Thread;
-
-const size_t MAX_THREADS = 128;
-
-
-/// ThreadBase struct is the base of the hierarchy from where we derive all the
-/// specialized thread classes.
-
-struct ThreadBase : public std::thread {
-
- virtual ~ThreadBase() = default;
- virtual void idle_loop() = 0;
- void notify_one();
- void wait(volatile const bool& b);
- void wait_while(volatile const bool& b);
-
- Mutex mutex;
- ConditionVariable sleepCondition;
- volatile bool exit = false;
+#include "thread_win32_osx.h"
+#include "types.h"
+
+namespace Stockfish {
+
+// Thread class keeps together all the thread-related stuff.
+class Thread {
+
+ std::mutex mutex;
+ std::condition_variable cv;
+ size_t idx;
+ bool exit = false, searching = true; // Set before starting std::thread
+ NativeThread stdThread;
+
+ public:
+ explicit Thread(size_t);
+ virtual ~Thread();
+ virtual void search();
+ void clear();
+ void idle_loop();
+ void start_searching();
+ void wait_for_search_finished();
+ size_t id() const { return idx; }
+
+ size_t pvIdx, pvLast;
+ std::atomic<uint64_t> nodes, tbHits, bestMoveChanges;
+ int selDepth, nmpMinPly;
+ Value bestValue, optimism[COLOR_NB];
+
+ Position rootPos;
+ StateInfo rootState;
+ Search::RootMoves rootMoves;
+ Depth rootDepth, completedDepth;
+ Value rootDelta;
+ Value rootSimpleEval;
+ CounterMoveHistory counterMoves;
+ ButterflyHistory mainHistory;
+ CapturePieceToHistory captureHistory;
+ ContinuationHistory continuationHistory[2][2];
+ PawnHistory pawnHistory;