|
Barretenberg
The ZK-SNARK library at the core of Aztec
|
Runs work on a dedicated std::thread instead of the libuv thread pool. More...
#include <async_op.hpp>
Public Member Functions | |
| ThreadedAsyncOperation (Napi::Env env, std::shared_ptr< Napi::Promise::Deferred > deferred, async_fn fn) | |
| ThreadedAsyncOperation (const ThreadedAsyncOperation &)=delete | |
| ThreadedAsyncOperation & | operator= (const ThreadedAsyncOperation &)=delete |
| ThreadedAsyncOperation (ThreadedAsyncOperation &&)=delete | |
| ThreadedAsyncOperation & | operator= (ThreadedAsyncOperation &&)=delete |
| ~ThreadedAsyncOperation ()=default | |
Static Public Member Functions | |
| static void | Run (Napi::Env env, std::shared_ptr< Napi::Promise::Deferred > deferred, async_fn fn) |
Private Member Functions | |
| void | Queue () |
Static Private Member Functions | |
| static void | launch_detached_with_large_stack (std::function< void()> work) |
Private Attributes | |
| async_fn | _fn |
| std::shared_ptr< Napi::Promise::Deferred > | _deferred |
| Napi::ThreadSafeFunction | _completion_tsfn |
| msgpack::sbuffer | _result |
| bool | _success = false |
| std::string | _error |
Static Private Attributes | |
| static constexpr size_t | WORKER_STACK_SIZE = 32UL * 1024 * 1024 |
Runs work on a dedicated std::thread instead of the libuv thread pool.
Unlike AsyncOperation (which uses Napi::AsyncWorker and occupies a libuv thread), this class spawns a new OS thread for each operation. This prevents AVM simulations from exhausting the libuv thread pool, which would deadlock when C++ callbacks need to invoke JS functions that themselves require libuv threads (e.g., LMDB reads).
The completion callback (resolve/reject) is posted back to the JS main thread via a Napi::ThreadSafeFunction, so the event loop returns immediately after launch and is woken up only when the work is done.
Prevent use-after-free: the TSFN callback runs asynchronously on the JS thread (napi_tsfn_blocking only blocks on queue insertion, NOT on callback completion). Both the worker thread lambda and the callback capture a shared_ptr to keep the object alive until both are done.
Usage: ThreadedAsyncOperation::Run(env, deferred, fn);
Definition at line 93 of file async_op.hpp.
|
inline |
Definition at line 95 of file async_op.hpp.
|
delete |
|
delete |
|
default |
|
inlinestaticprivate |
Definition at line 159 of file async_op.hpp.
|
delete |
|
delete |
|
inlineprivate |
Definition at line 124 of file async_op.hpp.
|
inlinestatic |
Definition at line 110 of file async_op.hpp.
|
private |
Definition at line 194 of file async_op.hpp.
|
private |
Definition at line 193 of file async_op.hpp.
|
private |
Definition at line 197 of file async_op.hpp.
|
private |
Definition at line 192 of file async_op.hpp.
|
private |
Definition at line 195 of file async_op.hpp.
|
private |
Definition at line 196 of file async_op.hpp.
|
staticconstexprprivate |
Definition at line 122 of file async_op.hpp.