86 template <
class... Args>
167 template <class Callable, class... Args>
187 state->~ThreadState();
198 template <
class... Args>
218 std::apply([&state](Args&... args) {
223 state->~FunctionState();
259 return m_value == other.m_value;
268 return m_value != other.m_value;
277 return m_value < other.m_value;
286 return m_value <= other.m_value;
295 return m_value > other.m_value;
304 return m_value >= other.m_value;
311 inline std::uint64_t
Value() const noexcept {
320 inline explicit Id(std::uint64_t value) noexcept
323 std::uint64_t m_value;
335 : m_thread{
nullptr} {}
345 template <
class Callable,
class... Args>
350 State* state = ::new (raw) State(std::forward<Callable>(callable), std::forward<Args>(args)...);
363 template <
class... Args>
368 State* state = ::new (raw) State(std::move(function), std::forward<Args>(args)...);
398 if (
this != &other) {
411 void* mine = m_thread;
412 m_thread = other.m_thread;
413 other.m_thread = mine;
445 if (m_thread ==
nullptr)
455 if (m_thread ==
nullptr)
489 namespace this_thread {
511 template <
class Rep,
class Period>
513 if (time <= std::chrono::duration<Rep, Period>::zero())
515 const auto nanos = std::chrono::duration_cast<std::chrono::nanoseconds>(time).count();
527 template <
class Clock,
class Duration>
Base exception type for the suite.
Definition exception.hxx:67
Status Call(Args... args) const
Invoke the provider callback.
Definition function.hxx:194
Copyable, creator-context callback with a typed signature.
Definition function.hxx:98
Identifier of an execution.
Definition thread.hxx:243
Id() noexcept
Not an execution.
Definition thread.hxx:250
bool operator<(const Id &other) const noexcept
Order two identifiers.
Definition thread.hxx:276
bool operator!=(const Id &other) const noexcept
Compare two identifiers.
Definition thread.hxx:267
bool operator>=(const Id &other) const noexcept
Order two identifiers.
Definition thread.hxx:303
std::uint64_t Value() const noexcept
Value used by a hash.
Definition thread.hxx:311
friend class Thread
Definition thread.hxx:244
bool operator>(const Id &other) const noexcept
Order two identifiers.
Definition thread.hxx:294
bool operator==(const Id &other) const noexcept
Compare two identifiers.
Definition thread.hxx:258
bool operator<=(const Id &other) const noexcept
Order two identifiers.
Definition thread.hxx:285
Execution owned by Base.
Definition thread.hxx:237
Thread & operator=(const Thread &)=delete
Thread(Thread &&other) noexcept
Take an execution.
Definition thread.hxx:378
~Thread() noexcept
Destroy the handle.
Definition thread.hxx:386
native_handle_type native_handle() noexcept
Native handle as an integer.
Definition thread.hxx:454
static unsigned hardware_concurrency() noexcept
Hint of concurrent executions.
Definition thread.hxx:464
void detach()
Detach the execution.
Definition thread.hxx:436
Thread(const Thread &)=delete
void join()
Wait until the execution returns.
Definition thread.hxx:428
STORMBYTE_FORCE_INLINE Thread(Callable &&callable, Args &&... args)
Start callable in a Base-owned execution.
Definition thread.hxx:346
void swap(Thread &other) noexcept
Exchange two executions.
Definition thread.hxx:410
Thread & operator=(Thread &&other) noexcept
Take an execution.
Definition thread.hxx:397
Thread() noexcept
Not an execution.
Definition thread.hxx:334
static Id Calling() noexcept
Identifier of the calling execution.
Definition thread.hxx:472
bool joinable() const noexcept
Whether this object owns an execution.
Definition thread.hxx:420
std::uintptr_t native_handle_type
Native handle as an integer.
Definition thread.hxx:329
STORMBYTE_FORCE_INLINE Thread(Function< void(Args...)> function, Args &&... args)
Start a void Function in a Base-owned execution.
Definition thread.hxx:364
Id get_id() const noexcept
Identifier of the owned execution.
Definition thread.hxx:444
Private Base heap used by StormByte::Safe::Shared, StormByte::Safe::Unique and StormByte::Safe::Clona...
void ThreadSleep(std::uint64_t nanoseconds) noexcept
Sleep the calling execution.
std::uintptr_t ThreadNative(void *thread) noexcept
Native handle as an integer.
void ThreadYield() noexcept
Offer the calling execution.
unsigned ThreadHardware() noexcept
Hint of concurrent executions.
std::uint64_t ThreadId(void *thread) noexcept
Identifier of the owned execution.
void ThreadDetach(void *thread)
Detach the execution.
void ThreadDestroy(void *thread) noexcept
Destroy a thread from ThreadStart.
bool ThreadJoinable(void *thread) noexcept
Whether the thread still owns an execution.
void * ThreadStart(void(*entry)(void *), void *argument)
Start a thread whose body lives in Base.
std::uint64_t ThreadSelf() noexcept
Identifier of the calling execution.
void ThreadJoin(void *thread)
Wait until the execution returns.
void * Allocate(std::size_t bytes)
Allocate bytes on Base's heap.
void Free(void *pointer) noexcept
Release a block obtained from Allocate.
Operations on the calling execution.
Thread::Id get_id() noexcept
Identifier of the calling execution.
Definition thread.hxx:494
STORMBYTE_FORCE_INLINE void sleep_for(const std::chrono::duration< Rep, Period > &time) noexcept
Sleep the calling execution.
Definition thread.hxx:512
void yield() noexcept
Offer the calling execution.
Definition thread.hxx:501
STORMBYTE_FORCE_INLINE void sleep_until(const std::chrono::time_point< Clock, Duration > &time) noexcept
Sleep until a time point.
Definition thread.hxx:528
Owned values that cross a DLL without the caller's CRT.
void swap(Binary &left, Binary &right) noexcept
Exchange two sequences.
Definition binary.hxx:760
Root namespace of the StormByte suite.
Function and its arguments, allocated on Base's heap.
Definition thread.hxx:199
std::tuple< Args... > arguments
Arguments captured before the execution starts.
Definition thread.hxx:201
static STORMBYTE_FORCE_INLINE void Run(void *raw)
Invoke Call and destroy the state.
Definition thread.hxx:215
STORMBYTE_FORCE_INLINE FunctionState(Function< void(Args...)> &&fn, Args &&... args)
Capture the callback and its arguments.
Definition thread.hxx:208
Function< void(Args...)> function
Creator-owned callback.
Definition thread.hxx:200
Whether T is a void-returning Function.
Definition thread.hxx:80
Decayed callable and arguments, allocated on Base's heap.
Definition thread.hxx:168
std::tuple< Args... > arguments
Arguments captured before the execution starts.
Definition thread.hxx:170
static STORMBYTE_FORCE_INLINE void Run(void *raw)
Invoke and destroy the state.
Definition thread.hxx:184
Callable callable
Entry.
Definition thread.hxx:169
STORMBYTE_FORCE_INLINE ThreadState(Callable &&fn, Args &&... args)
Capture the entry.
Definition thread.hxx:177
#define STORMBYTE_PUBLIC
Definition visibility.h:52