mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-14 13:21:34 +00:00
Allow stopping enqueued scripts
This commit is contained in:
parent
662d5730f7
commit
12d04b21c9
2
laf
2
laf
@ -1 +1 @@
|
||||
Subproject commit 23c11583b626b36b125dbe74a2d1cde880780623
|
||||
Subproject commit d32eb3f60bc2bb780f817798e0da2383d052613e
|
@ -297,12 +297,13 @@ RunScriptTask::~RunScriptTask()
|
||||
|
||||
void RunScriptTask::execute(base::thread_pool& pool)
|
||||
{
|
||||
m_task.start(pool);
|
||||
m_token = &m_task.start(pool);
|
||||
}
|
||||
|
||||
void RunScriptTask::stop()
|
||||
void RunScriptTask::stop(base::thread_pool& pool)
|
||||
{
|
||||
m_wantsToStop = true;
|
||||
m_task.try_skip(pool);
|
||||
}
|
||||
|
||||
Engine::Engine()
|
||||
@ -625,7 +626,7 @@ void Engine::destroy()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
for (auto& task : m_tasks) {
|
||||
task->stop();
|
||||
task->stop(m_threadPool);
|
||||
}
|
||||
}
|
||||
m_threadPool.wait_all();
|
||||
@ -888,12 +889,18 @@ void Engine::stopDebugger()
|
||||
|
||||
void Engine::stopTask(const RunScriptTask* task)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
for (const auto& t : m_tasks) {
|
||||
if (t.get() == task) {
|
||||
t->stop();
|
||||
RunScriptTask* taskPtr = nullptr;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
for (const auto& t : m_tasks) {
|
||||
if (t.get() == task) {
|
||||
taskPtr = t.get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (taskPtr)
|
||||
taskPtr->stop(m_threadPool);
|
||||
}
|
||||
|
||||
void Engine::onConsoleError(const char* text)
|
||||
|
@ -87,6 +87,8 @@ public:
|
||||
};
|
||||
|
||||
class RunScriptTask {
|
||||
friend class Engine;
|
||||
|
||||
public:
|
||||
typedef std::function<void(lua_State* L)> Func;
|
||||
|
||||
@ -98,7 +100,7 @@ public:
|
||||
m_task.on_finished(std::move(onFinishedFunc));
|
||||
}
|
||||
void execute(base::thread_pool& pool);
|
||||
void stop();
|
||||
void stop(base::thread_pool& pool);
|
||||
bool wantsToStop() const { return m_wantsToStop; }
|
||||
|
||||
int ref() const { return m_LRef; }
|
||||
@ -113,6 +115,7 @@ private:
|
||||
base::task m_task;
|
||||
bool m_wantsToStop = false;
|
||||
std::string m_description;
|
||||
base::task_token* m_token;
|
||||
};
|
||||
|
||||
class Engine {
|
||||
|
@ -662,8 +662,7 @@ private:
|
||||
m_label.setExpansive(true);
|
||||
m_row.setExpansive(true);
|
||||
m_row.addChild(&m_label);
|
||||
if (!task->isEnqueued())
|
||||
m_row.addChild(&m_stop);
|
||||
m_row.addChild(&m_stop);
|
||||
addChild(&m_row);
|
||||
|
||||
m_stop.Click.connect([this]() { App::instance()->scriptEngine()->stopTask(m_task); });
|
||||
|
Loading…
x
Reference in New Issue
Block a user