Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
cancellation_token.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <memory>
5#include <stdexcept>
6
7namespace bb::avm2::simulation {
8
12class CancelledException : public std::runtime_error {
13 public:
15 : std::runtime_error("Simulation cancelled")
16 {}
17};
18
38 public:
40 : cancelled_(false)
41 {}
42
43 // Non-copyable, non-movable
48
55
61 bool is_cancelled() const { return cancelled_.load(std::memory_order_acquire); }
62
68 void check_and_throw() const
69 {
70 if (is_cancelled()) {
71 throw CancelledException();
72 }
73 }
74
75 private:
76 std::atomic<bool> cancelled_;
77};
78
79using CancellationTokenPtr = std::shared_ptr<CancellationToken>;
80
81} // namespace bb::avm2::simulation
A thread-safe cancellation token for C++ AVM simulation.
CancellationToken(const CancellationToken &)=delete
bool is_cancelled() const
Check if cancellation has been signaled. Called from C++ simulation thread.
void check_and_throw() const
Check and throw if cancelled. Called from C++ simulation thread.
void cancel()
Signal cancellation. Called from TypeScript thread.
CancellationToken & operator=(const CancellationToken &)=delete
CancellationToken(CancellationToken &&)=delete
CancellationToken & operator=(CancellationToken &&)=delete
Exception thrown when simulation is cancelled.
std::shared_ptr< CancellationToken > CancellationTokenPtr
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13