Use a timer to avoid polling

The timer will be fired asynchronously to handle
time management flags, while other threads are
searching.

This implementation uses a thread waiting on a
timed condition variable instead of real timers.
This approach allow to reduce platform dependant
code to a minimum and also is the most portable given
that timers libraries are very different among platforms
and also the best ones are not compatible with olds
Windows.

Also retire the now unused polling code.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba
2011-11-05 11:19:21 +01:00
parent 0095f423f2
commit d58176bfea
8 changed files with 149 additions and 96 deletions

View File

@@ -70,6 +70,7 @@ struct Thread {
bool is_available_to(int master) const;
void idle_loop(SplitPoint* sp);
void listener_loop();
void timer_loop();
SplitPoint splitPoints[MAX_ACTIVE_SPLIT_POINTS];
MaterialInfoTable materialTable;
@@ -115,9 +116,9 @@ public:
bool available_slave_exists(int master) const;
void getline(std::string& cmd);
void do_uci_async_cmd(const std::string& cmd);
void start_listener();
void stop_listener();
void set_timer(int msec);
template <bool Fake>
Value split(Position& pos, SearchStack* ss, Value alpha, Value beta, Value bestValue,
@@ -125,7 +126,7 @@ public:
private:
friend struct Thread;
Thread threads[MAX_THREADS + 1];
Thread threads[MAX_THREADS + 2]; // Last 2 are the listener and the timer
Lock threadsLock;
Depth minimumSplitDepth;
int maxThreadsPerSplitPoint;