5#include <__cheri_sealed.h>
56int __cheri_compartment(
"thread_pool")
69# include <type_traits>
103 key,
Sealed<T>(
static_cast<CHERI_SEALED(T *)
>(rawFn)));
125 template<
typename Fn>
138 [[no_unique_address]] Fn f;
143 static_assert(offsetof(Test, b) == 0,
144 "Stateless callable object is not stateless");
164 if constexpr (std::is_convertible_v<T, void (*)()>)
175 using LambdaType = std::remove_reference_t<
decltype(lambda)>;
194 T *copy =
new (buffer) T(
C++ helpers for operating on capabilities.
Helper template for representing a sealed capability created by the allocator's token API.
Implementation details, should not be used outside of this header.
TokenKey sealing_key_for_type()
Helper that generates a different sealing key per type using the allocator's token mechanism.
__cheri_callback void wrap_callback_lambda(CHERI_SEALED(void *) rawFn)
Helper that provides a callback function for invoking and then freeing a sealed heap-allocated lambda...
__cheri_callback void wrap_callback_function(CHERI_SEALED(void *))
Helper to wrap pure C function (including a stateless lambda) as a callback.
For C++ programmers, we provide some more user-friendly wrappers.
int async(T &&lambda)
Asynchronously invoke a lambda.
Message to a thread pool.
ThreadPoolCallback invoke
The function pointer that will be called in the thread pool.
CHERI_SEALED(void *) data
The data associated with the asynchronous invocation.
Structure representing a timeout.
int thread_pool_async(ThreadPoolCallback fn, CHERI_SEALED(void *) data)
Invoke a function that takes a void* argument in another thread.
__cheri_callback void(* ThreadPoolCallback)(CHERI_SEALED(void *))
The type of a thread-pool callback.
int thread_pool_run(void)
Run a thread pool.
static const Ticks UnlimitedTimeout
Value indicating an unbounded timeout for use with Timeout.
APIs for dealing with type-safe opaque handles (sealed objects).
T * token_unseal(TokenKey key, Sealed< T > sealed)
Type-safe helper that unseal a Sealed<T> and returns a T*.
token_sealed_unsealed_alloc(TimeoutArgument timeout, AllocatorCapability heapCapability, TokenKey key, size_t sz, void **unsealed)
Allocate a new object with size sz.
TokenKey token_key_new(void)
Create a new sealing key.
int token_obj_destroy(AllocatorCapability heapCapability, TokenKey, CHERI_SEALED(void *))
Destroy the object given its key, freeing memory.
struct TokenKeyType * TokenKey
Sealing keys in CHERI are represented as capabilities.