NPRPC docs

struct DispatchExecutor

C++

struct DispatchExecutor

Optional dispatch executor for servant callbacks / SHM offload.

Two uses:

  1. Fire-and-forget hop (preferred for SHM UI POAs): the ring thread calls post(ctx, work, arg) to run a full handle_request+reply job on the target queue (Swift: DispatchQueue.async / dispatch_async_f). No Asio hop, no blocking the ring.
  2. invoke_sync: post+wait when a caller is not already on the queue. With is_running_on set, work already on the queue runs inline (avoids nested async / deadlock).

Default (all null) = no custom executor; transport affinity decides ring-inline vs Asio offload.

Swift / Foundation example for DispatchQueue.main: post: dispatch_async_f(queue, arg, fn) or queue.async { fn(arg) } is_running_on: Thread.isMainThread / queue-specific key

include/nprpc/nprpc.hpp:203

Fields

void *ctx = nullptr

Passed back to post and is_running_on.

include/nprpc/nprpc.hpp:216

IsRunningOnFn is_running_on = nullptr

Optional; lets invoke_sync run inline instead of deadlocking.

include/nprpc/nprpc.hpp:214

PostFn post = nullptr

Schedules fn(arg) on the executor and returns without waiting.

include/nprpc/nprpc.hpp:212

Methods

template <typename F> void invoke_sync(F &&fn) const

Run fn on this executor; blocks until it finishes.

If the executor is empty or is_running_on reports the current thread, fn runs inline. Exceptions thrown by fn are rethrown on the calling thread.

Prefer fire-and-forget post from the SHM ring for whole requests; use this when already inside a stack that must wait for the result.

include/nprpc/nprpc.hpp:232

Operators

explicit operator bool() const noexcept

Whether an executor is set.

include/nprpc/nprpc.hpp:219

Type aliases

using IsRunningOnFn = bool (*)(void *)

Return true if the calling thread is already the executor's thread.

include/nprpc/nprpc.hpp:209

using PostFn = void (*)(void *, WorkFn, void *)

Schedule fn(arg) on the executor identified by ctx.

include/nprpc/nprpc.hpp:207

using WorkFn = void (*)(void *)

A unit of work: call with its argument.

include/nprpc/nprpc.hpp:205