mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-24 12:41:08 +00:00
* Removed base::mutex & base::scoped_lock * We can use std::lock_guard with deduced template args (as we're using C++17 now)
46 lines
743 B
C++
46 lines
743 B
C++
// Aseprite
|
|
// Copyright (C) 2019-2022 Igara Studio S.A.
|
|
//
|
|
// This program is distributed under the terms of
|
|
// the End-User License Agreement for Aseprite.
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include "app/task.h"
|
|
|
|
#include "base/task.h"
|
|
#include "base/thread.h"
|
|
#include "base/thread_pool.h"
|
|
|
|
namespace app {
|
|
|
|
static base::thread_pool tasks_pool(4);
|
|
|
|
Task::Task()
|
|
: m_token(nullptr)
|
|
{
|
|
}
|
|
|
|
Task::~Task()
|
|
{
|
|
}
|
|
|
|
void Task::run(base::task::func_t&& func)
|
|
{
|
|
std::lock_guard lock(m_token_mutex);
|
|
m_task.on_execute(std::move(func));
|
|
m_token = &m_task.start(tasks_pool);
|
|
}
|
|
|
|
void Task::wait()
|
|
{
|
|
// TODO wait a condition variable
|
|
while (!m_task.completed()) {
|
|
base::this_thread::sleep_for(0.1);
|
|
}
|
|
}
|
|
|
|
} // namespace app
|