diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-07-21 14:46:48 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-07-21 14:46:48 +0200 |
commit | a76dabb12734154177a78033324b40365e7c6f21 (patch) | |
tree | dab1d6b997ba283dfcc7f9dd12adee96dd631dc2 /src/plugins | |
parent | 3c16cb376669e4ae500d22529b40112c761088c0 (diff) |
Fix freeze on search reset in manga combined plugin. Fix multithreading issues in AsyncTask
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/MangaCombined.cpp | 18 | ||||
-rw-r--r-- | src/plugins/Youtube.cpp | 3 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/plugins/MangaCombined.cpp b/src/plugins/MangaCombined.cpp index 1745ee0..5440871 100644 --- a/src/plugins/MangaCombined.cpp +++ b/src/plugins/MangaCombined.cpp @@ -23,10 +23,14 @@ namespace QuickMedia { int accumulated_sleep_time = 0; while(true) { + size_t num_dead_threads = 0; for(size_t i = 0; i < search_threads.size(); ++i) { auto &search_thread = search_threads[i]; - if(!search_thread.second.valid()) + if(!search_thread.second.valid()) { + if(!plugin_finished_state[i].second) + ++num_dead_threads; continue; + } if(!search_thread.second.ready()) continue; @@ -40,6 +44,9 @@ namespace QuickMedia { } } + if(num_dead_threads == search_threads.size()) + break; + size_t num_finished_plugins = 0; for(auto &f : plugin_finished_state) { if(f.second) @@ -58,7 +65,7 @@ namespace QuickMedia { break; } - int sleep_time_ms = 200; + int sleep_time_ms = 50; std::this_thread::sleep_for(std::chrono::milliseconds(sleep_time_ms)); accumulated_sleep_time += sleep_time_ms; if(accumulated_sleep_time >= SEARCH_TIMEOUT_MILLISECONDS) { @@ -114,4 +121,11 @@ namespace QuickMedia { if(!page) return PluginResult::OK; return page->submit(title, url, result_tabs); } + + void MangaCombinedSearchPage::cancel_operation() { + for(auto &search_thread : search_threads) { + search_thread.second.cancel(); + } + search_threads.clear(); + } }
\ No newline at end of file diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 2fd193f..cd3fddd 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -1667,6 +1667,9 @@ R"END( const time_t time_now = time(nullptr); for(const std::string &channel_id : channel_ids) { + if(program_is_dead_in_current_thread()) + return PluginResult::OK; + subscription_load_tasks[async_task_index] = AsyncTask<std::vector<YoutubeSubscriptionTaskResult>>([&channel_id, time_now]() -> std::vector<YoutubeSubscriptionTaskResult> { std::string website_data; DownloadResult result = download_to_string("https://www.youtube.com/feeds/videos.xml?channel_id=" + url_param_encode(channel_id), website_data, {}, false); |