mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-22 18:17:02 +08:00
Modernize code base a little bit
Removed sprintf() which generated a warning, because of security reasons. Replace NULL with nullptr Replace typedef with using Do not inherit from std::vector. Use composition instead. optimize mutex-unlocking closes https://github.com/official-stockfish/Stockfish/pull/4327 No functional change
This commit is contained in:
committed by
Joost VandeVondele
parent
31acd6bab7
commit
5a88c5bb9b
14
src/thread.h
14
src/thread.h
@@ -101,13 +101,13 @@ struct MainThread : public Thread {
|
||||
/// parking and, most importantly, launching a thread. All the access to threads
|
||||
/// is done through this class.
|
||||
|
||||
struct ThreadPool : public std::vector<Thread*> {
|
||||
struct ThreadPool {
|
||||
|
||||
void start_thinking(Position&, StateListPtr&, const Search::LimitsType&, bool = false);
|
||||
void clear();
|
||||
void set(size_t);
|
||||
|
||||
MainThread* main() const { return static_cast<MainThread*>(front()); }
|
||||
MainThread* main() const { return static_cast<MainThread*>(threads.front()); }
|
||||
uint64_t nodes_searched() const { return accumulate(&Thread::nodes); }
|
||||
uint64_t tb_hits() const { return accumulate(&Thread::tbHits); }
|
||||
Thread* get_best_thread() const;
|
||||
@@ -116,13 +116,21 @@ struct ThreadPool : public std::vector<Thread*> {
|
||||
|
||||
std::atomic_bool stop, increaseDepth;
|
||||
|
||||
auto cbegin() const noexcept { return threads.cbegin(); }
|
||||
auto begin() noexcept { return threads.begin(); }
|
||||
auto end() noexcept { return threads.end(); }
|
||||
auto cend() const noexcept { return threads.cend(); }
|
||||
auto size() const noexcept { return threads.size(); }
|
||||
auto empty() const noexcept { return threads.empty(); }
|
||||
|
||||
private:
|
||||
StateListPtr setupStates;
|
||||
std::vector<Thread*> threads;
|
||||
|
||||
uint64_t accumulate(std::atomic<uint64_t> Thread::* member) const {
|
||||
|
||||
uint64_t sum = 0;
|
||||
for (Thread* th : *this)
|
||||
for (Thread* th : threads)
|
||||
sum += (th->*member).load(std::memory_order_relaxed);
|
||||
return sum;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user