Worker threads with an explicit stack size, and the bounds of the calling thread's stack. More...
#include <pthread.h>#include <cstddef>#include <cstdint>#include <optional>Classes | |
| struct | donner::tasks::StackBounds |
| The stack of one thread, which grows down on every platform the scheduler builds for: the lowest usable address (the floor) and the size above it. More... | |
Namespaces | |
| namespace | donner |
| Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css. | |
Functions | |
| StackBounds | donner::tasks::CurrentThreadStackBounds () |
| The calling thread's stack bounds, as the platform reports them: pthread_get_stackaddr_np and pthread_get_stacksize_np on Apple platforms, pthread_getattr_np elsewhere. | |
| std::optional< StackBounds > | donner::tasks::TryCurrentThreadStackBounds () |
| Try to measure the calling thread's stack without asserting on a platform query failure. | |
| std::uintptr_t | donner::tasks::CurrentStackPosition () |
| The calling frame's position on the real stack. | |
| constexpr std::size_t | donner::tasks::StackRemaining (std::uintptr_t position, const StackBounds &bounds) |
Bytes of bounds' stack left below position: zero at or below the floor, never negative. | |
| std::size_t | donner::tasks::WorkerStackSize (std::size_t bytes) |
The stack size a worker is created with for a requested bytes: rounded up to whole pages. | |
| constexpr StackBounds | donner::tasks::UsableStack (const StackBounds &platform, std::size_t usableBytes) |
The part of a thread's stack a worker uses: the top usableBytes of platform's bounds, or all of them if the platform's stack is smaller. | |
| std::optional< pthread_t > | donner::tasks::TryStartThreadWithStack (std::size_t bytes, void *(*entry)(void *), void *argument, WorkerThreadCreate create) |
| Attempts to start a thread with an explicit stack size. | |
| pthread_t | donner::tasks::StartThreadWithStack (std::size_t bytes, void *(*entry)(void *), void *argument) |
Starts a thread running entry(argument) on a stack of WorkerStackSize(bytes) bytes. | |
Worker threads with an explicit stack size, and the bounds of the calling thread's stack.
|
inline |
The calling frame's position on the real stack.
Under AddressSanitizer with its fake stack, the addresses of locals can lie on the heap; the frame address never does.
Unsupported on an alternate signal stack: in a handler installed with SA_ONSTACK, the frame is on that stack, not the thread's, so a stack-left measurement taken there is meaningless.
| StackBounds donner::tasks::CurrentThreadStackBounds | ( | ) |
The calling thread's stack bounds, as the platform reports them: pthread_get_stackaddr_np and pthread_get_stacksize_np on Apple platforms, pthread_getattr_np elsewhere.
Intended for threads created with an explicit stack size; the main thread's bounds depend on the platform's resource limits.
|
constexpr |
Bytes of bounds' stack left below position: zero at or below the floor, never negative.
| position | A position on the stack, from CurrentStackPosition. |
| bounds | The stack's bounds. |
| pthread_t donner::tasks::StartThreadWithStack | ( | std::size_t | bytes, |
| void *(* | entry )(void *), | ||
| void * | argument ) |
Starts a thread running entry(argument) on a stack of WorkerStackSize(bytes) bytes.
Fails a release assertion if the thread cannot be created, as a std::thread built without exceptions ends the process.
| std::optional< pthread_t > donner::tasks::TryStartThreadWithStack | ( | std::size_t | bytes, |
| void *(* | entry )(void *), | ||
| void * | argument, | ||
| WorkerThreadCreate | create ) |
Attempts to start a thread with an explicit stack size.
Invalid sizes fail a release assertion.
| bytes | Requested stack size. |
| entry | Thread entry point. |
| argument | Argument passed to the entry point. |
| create | Thread creation function. |
|
constexpr |
The part of a thread's stack a worker uses: the top usableBytes of platform's bounds, or all of them if the platform's stack is smaller.
A platform can hand a new thread a larger stack than it asked for (glibc reuses a cached stack up to four times the requested size), so the configured size, not the platform's, is what a worker counts as its stack.
| platform | The thread's bounds, from CurrentThreadStackBounds. |
| usableBytes | The configured stack size, from WorkerStackSize. |
| std::size_t donner::tasks::WorkerStackSize | ( | std::size_t | bytes | ) |
The stack size a worker is created with for a requested bytes: rounded up to whole pages.
Fails a release assertion when bytes is below the platform's minimum thread stack or does not leave room above kStackReserveBytes.