Rewrite how commands from GUI are read

Instead of polling for input use a dedicated listener
thread to read commands from the GUI independently
from other threads.

To do this properly we have to delegate to the listener
all the reading from the GUI: while searching but also
while waiting for a command, like in std::getline().

So we have two possible behaviours: in-sync mode, in which
the thread mimics std::getline() and the caller blocks until
something is read from GUI, and async mode where the listener
continuously reads and processes GUI commands while other
threads are searching.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba
2011-11-05 07:53:19 +01:00
parent 22b9307aba
commit 2617aa415e
4 changed files with 188 additions and 65 deletions

View File

@@ -69,6 +69,7 @@ struct Thread {
bool cutoff_occurred() const;
bool is_available_to(int master) const;
void idle_loop(SplitPoint* sp);
void listener_loop();
SplitPoint splitPoints[MAX_ACTIVE_SPLIT_POINTS];
MaterialInfoTable materialTable;
@@ -113,16 +114,25 @@ public:
void read_uci_options();
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();
template <bool Fake>
Value split(Position& pos, SearchStack* ss, Value alpha, Value beta, Value bestValue,
Depth depth, Move threatMove, int moveCount, MovePicker* mp, int nodeType);
private:
Thread threads[MAX_THREADS];
friend struct Thread;
Thread threads[MAX_THREADS + 1];
Lock threadsLock;
Depth minimumSplitDepth;
int maxThreadsPerSplitPoint;
int activeThreads;
bool useSleepingThreads;
WaitCondition sleepCond;
std::string inputLine;
};
extern ThreadsManager Threads;