- // ThreadsManager class is used to handle all the threads related stuff in search,
- // init, starting, parking and, the most important, launching a slave thread at a
- // split point are what this class does. All the access to shared thread data is
- // done through this class, so that we avoid using global variables instead.
-
- class ThreadsManager {
- /* As long as the single ThreadsManager object is defined as a global we don't
- need to explicitly initialize to zero its data members because variables with
- static storage duration are automatically set to zero before enter main()
- */
- public:
- void init_threads();
- void exit_threads();
-
- int active_threads() const { return ActiveThreads; }
- void set_active_threads(int newActiveThreads) { ActiveThreads = newActiveThreads; }
- void incrementNodeCounter(int threadID) { threads[threadID].nodes++; }
-
- void resetNodeCounters();
- int64_t nodes_searched() const;
- bool available_thread_exists(int master) const;
- bool thread_is_available(int slave, int master) const;
- bool thread_should_stop(int threadID) const;
- void wake_sleeping_threads();
- void put_threads_to_sleep();
- void idle_loop(int threadID, SplitPoint* sp);
-
- template <bool Fake>
- void split(const Position& pos, SearchStack* ss, int ply, Value* alpha, const Value beta, Value* bestValue,
- Depth depth, Move threatMove, bool mateThreat, int moveCount, MovePicker* mp, bool pvNode);
-
- private:
- friend void poll();
-
- int ActiveThreads;
- volatile bool AllThreadsShouldExit, AllThreadsShouldSleep;
- Thread threads[MAX_THREADS];
-
- Lock MPLock, WaitLock;
-
-#if !defined(_MSC_VER)
- pthread_cond_t WaitCond;
-#else
- HANDLE SitIdleEvent[MAX_THREADS];
-#endif
-
- };
-
-
- // RootMove struct is used for moves at the root at the tree. For each
- // root move, we store a score, a node count, and a PV (really a refutation
- // in the case of moves which fail low).