Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::avm2::simulation::CancellationToken Class Reference

A thread-safe cancellation token for C++ AVM simulation. More...

#include <cancellation_token.hpp>

Public Member Functions

 CancellationToken ()
 
 CancellationToken (const CancellationToken &)=delete
 
CancellationTokenoperator= (const CancellationToken &)=delete
 
 CancellationToken (CancellationToken &&)=delete
 
CancellationTokenoperator= (CancellationToken &&)=delete
 
void cancel ()
 Signal cancellation. Called from TypeScript thread.
 
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.
 

Private Attributes

std::atomic< bool > cancelled_
 

Detailed Description

A thread-safe cancellation token for C++ AVM simulation.

This token is used to signal cancellation from TypeScript to C++ when a simulation times out. The token is created in TypeScript, passed through NAPI, and checked periodically during C++ execution.

Usage:

  • TypeScript creates the token and passes it to avmSimulate
  • C++ checks is_cancelled() in the execution loop
  • On timeout, TypeScript calls cancel()
  • C++ throws CancelledException when it observes cancellation

Thread safety:

  • cancel() is called from the TypeScript/main thread
  • is_cancelled()/check() are called from the libuv worker thread
  • std::atomic ensures visibility between threads

Definition at line 37 of file cancellation_token.hpp.

Constructor & Destructor Documentation

◆ CancellationToken() [1/3]

bb::avm2::simulation::CancellationToken::CancellationToken ( )
inline

Definition at line 39 of file cancellation_token.hpp.

◆ CancellationToken() [2/3]

bb::avm2::simulation::CancellationToken::CancellationToken ( const CancellationToken )
delete

◆ CancellationToken() [3/3]

bb::avm2::simulation::CancellationToken::CancellationToken ( CancellationToken &&  )
delete

Member Function Documentation

◆ cancel()

void bb::avm2::simulation::CancellationToken::cancel ( )
inline

Signal cancellation. Called from TypeScript thread.

This is thread-safe and can be called while C++ simulation is running.

Definition at line 54 of file cancellation_token.hpp.

◆ check_and_throw()

void bb::avm2::simulation::CancellationToken::check_and_throw ( ) const
inline

Check and throw if cancelled. Called from C++ simulation thread.

Exceptions
CancelledExceptionif cancel() has been called

Definition at line 68 of file cancellation_token.hpp.

◆ is_cancelled()

bool bb::avm2::simulation::CancellationToken::is_cancelled ( ) const
inline

Check if cancellation has been signaled. Called from C++ simulation thread.

Returns
true if cancel() has been called

Definition at line 61 of file cancellation_token.hpp.

◆ operator=() [1/2]

CancellationToken & bb::avm2::simulation::CancellationToken::operator= ( CancellationToken &&  )
delete

◆ operator=() [2/2]

CancellationToken & bb::avm2::simulation::CancellationToken::operator= ( const CancellationToken )
delete

Member Data Documentation

◆ cancelled_

std::atomic<bool> bb::avm2::simulation::CancellationToken::cancelled_
private

Definition at line 76 of file cancellation_token.hpp.


The documentation for this class was generated from the following file: