Loading...
Searching...
No Matches
ExecutionTransaction.hpp
1#pragma once
2#include <Process/ExecutionCommand.hpp>
3#include <Process/ExecutionContext.hpp>
4
5#include <ossia/detail/thread.hpp>
6
7#include <verdigris>
8
9namespace Execution
10{
11struct Context;
12template <typename... T>
13inline constexpr auto gc(T&&... t) noexcept
14{
15 return
16 [... gced = std::move(t)] { OSSIA_ENSURE_CURRENT_THREAD(ossia::thread_type::Ui); };
17}
18
20{
21 const Context& context;
22 std::vector<ExecutionCommand> commands;
23 explicit Transaction(const Context& ctx) noexcept
24 : context{ctx}
25 {
26 }
27
28 Transaction(Transaction&& other) noexcept
29 : context{other.context}
30 , commands(std::move(other.commands))
31 {
32 }
33
34 Transaction& operator=(Transaction&& other) noexcept
35 {
36 commands = std::move(other.commands);
37 return *this;
38 }
39 void reserve(std::size_t sz) noexcept { commands.reserve(sz); }
40 bool empty() const noexcept { return commands.empty(); }
41 template <typename T>
42 void push_back(T&& t) noexcept
43 {
44 commands.push_back(std::move(t));
45 }
46
47 void run_all()
48 {
49 context.executionQueue.enqueue(
50 [t = std::move(*this)]() mutable { t.run_all_in_exec(); });
51 }
52
53 void run_all_in_exec()
54 {
55 for(auto& cmd : commands)
56 cmd();
57 }
58};
59
60}
61Q_DECLARE_METATYPE(Execution::Transaction*)
62W_REGISTER_ARGTYPE(Execution::Transaction*)
Components used for the execution of a score.
Definition ProcessComponent.cpp:14
Definition ExecutionContext.hpp:76
ExecutionCommandQueue & executionQueue
Definition ExecutionContext.hpp:122
Definition ExecutionTransaction.hpp:20