From 5c1c4e8980226281352484a4bfbc463b11757ee8 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Sun, 19 Nov 2023 20:46:07 +0100 Subject: [PATCH] fix restarting stockfish --- lib/stockfish.dart | 8 -------- src/stockfish.cpp | 3 ++- src/stream_fix.cpp | 9 +++++++++ src/stream_fix.h | 1 + 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/stockfish.dart b/lib/stockfish.dart index eba6abb..9346fba 100644 --- a/lib/stockfish.dart +++ b/lib/stockfish.dart @@ -27,14 +27,6 @@ final DynamicLibrary _dylib = () { if (Platform.isWindows) { return DynamicLibrary.open('$_libName.dll'); } - /*if (Platform.isLinux) { - return DynamicLibrary.open( - '${File(Platform.resolvedExecutable).parent.parent.path}/plugins/flutter_stockfish_plugin/shared/lib$_libName.so'); - } - if (Platform.isWindows) { - return DynamicLibrary.open( - '${File(Platform.resolvedExecutable).parent.parent.parent.path}/plugins/flutter_stockfish_plugin/shared/$_releaseType/$_libName.dll'); - }*/ throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}'); }(); diff --git a/src/stockfish.cpp b/src/stockfish.cpp index cdfda3f..00eb675 100644 --- a/src/stockfish.cpp +++ b/src/stockfish.cpp @@ -23,7 +23,8 @@ const char *QUITOK = "quitok\n"; int main(int, char **); int stockfish_init() { - //std::cout << "Init Stockfish: Nothing todo!"; + fakein.open(); + fakeout.open(); return 0; } diff --git a/src/stream_fix.cpp b/src/stream_fix.cpp index f7a3806..4271c6b 100644 --- a/src/stream_fix.cpp +++ b/src/stream_fix.cpp @@ -8,9 +8,18 @@ bool FakeStream::try_get_line(std::string& val) { return true; } +void FakeStream::open() { + std::lock_guard lock(mutex_guard); + closed = false; + mutex_signal.notify_one(); +} + void FakeStream::close() { std::lock_guard lock(mutex_guard); closed = true; + while (!string_queue.empty()) { + string_queue.pop(); + } mutex_signal.notify_one(); } bool FakeStream::is_closed() { return closed; } diff --git a/src/stream_fix.h b/src/stream_fix.h index 8044f36..cfc94d1 100644 --- a/src/stream_fix.h +++ b/src/stream_fix.h @@ -37,6 +37,7 @@ class FakeStream { bool try_get_line(std::string& val); + void open(); void close(); bool is_closed();