diff --git a/platform/platform.cpp b/platform/platform.cpp index 52b85066f6..fd20d34865 100644 --- a/platform/platform.cpp +++ b/platform/platform.cpp @@ -357,6 +357,31 @@ void Platform::RunThreads() m_backgroundThread = make_unique(); } +void Platform::CancelTask(Thread thread, base::thread_pool::delayed::ThreadPool::TaskId const & id) +{ + ASSERT(m_networkThread && m_fileThread && m_backgroundThread, ()); + switch (thread) + { + case Thread::File: m_fileThread->Cancel(id); return; + case Thread::Network: m_networkThread->Cancel(id); return; + case Thread::Gui: CHECK(false, ("Task cancelling for gui thread is not supported yet")); return; + case Thread::Background: m_backgroundThread->Cancel(id); return; + } +} + +void Platform::CancelDelayedTask(Thread thread, + base::thread_pool::delayed::ThreadPool::TaskId const & id) +{ + ASSERT(m_networkThread && m_fileThread && m_backgroundThread, ()); + switch (thread) + { + case Thread::File: m_fileThread->CancelDelayed(id); return; + case Thread::Network: m_networkThread->CancelDelayed(id); return; + case Thread::Gui: CHECK(false, ("Task cancelling for gui thread is not supported yet")); return; + case Thread::Background: m_backgroundThread->CancelDelayed(id); return; + } +} + string DebugPrint(Platform::EError err) { switch (err) diff --git a/platform/platform.hpp b/platform/platform.hpp index 053457100b..4b5ca22484 100644 --- a/platform/platform.hpp +++ b/platform/platform.hpp @@ -313,45 +313,38 @@ public: /// \note |task| cannot be moved in case of |Thread::Gui|. This way unique_ptr cannot be used /// in |task|. Use shared_ptr instead. template - void RunTask(Thread thread, Task && task) + base::thread_pool::delayed::ThreadPool::TaskId RunTask(Thread thread, Task && task) { ASSERT(m_networkThread && m_fileThread && m_backgroundThread, ()); switch (thread) { - case Thread::File: - m_fileThread->Push(std::forward(task)); - break; - case Thread::Network: - m_networkThread->Push(std::forward(task)); - break; - case Thread::Gui: - RunOnGuiThread(std::forward(task)); - break; - case Thread::Background: m_backgroundThread->Push(std::forward(task)); break; + case Thread::File: return m_fileThread->Push(std::forward(task)); + case Thread::Network: return m_networkThread->Push(std::forward(task)); + case Thread::Gui: RunOnGuiThread(std::forward(task)); return {}; + case Thread::Background: return m_backgroundThread->Push(std::forward(task)); } } template - void RunDelayedTask(Thread thread, base::thread_pool::delayed::ThreadPool::Duration const & delay, Task && task) + base::thread_pool::delayed::ThreadPool::TaskId RunDelayedTask( + Thread thread, base::thread_pool::delayed::ThreadPool::Duration const & delay, Task && task) { ASSERT(m_networkThread && m_fileThread && m_backgroundThread, ()); switch (thread) { - case Thread::File: - m_fileThread->PushDelayed(delay, std::forward(task)); - break; - case Thread::Network: - m_networkThread->PushDelayed(delay, std::forward(task)); - break; + case Thread::File: return m_fileThread->PushDelayed(delay, std::forward(task)); + case Thread::Network: return m_networkThread->PushDelayed(delay, std::forward(task)); case Thread::Gui: CHECK(false, ("Delayed tasks for gui thread are not supported yet")); - break; + return {}; case Thread::Background: - m_backgroundThread->PushDelayed(delay, std::forward(task)); - break; + return m_backgroundThread->PushDelayed(delay, std::forward(task)); } } + void CancelTask(Thread thread, base::thread_pool::delayed::ThreadPool::TaskId const & id); + void CancelDelayedTask(Thread thread, base::thread_pool::delayed::ThreadPool::TaskId const & id); + // Use this method for testing purposes only. void SetGuiThread(std::unique_ptr guiThread);