56 template<
typename Callback>
75 static void*
run(
void* arg);
84 [[nodiscard]]
virtual bool valid()
const = 0;
108 explicit operator
bool() const;
114 bool operator!() const;
120 [[nodiscard]]
bool joinable() const;
131 [[nodiscard]]
bool valid()
const override;
146 template<
typename Callback,
typename... ARGS>
147 explicit pThread(Callback c, ARGS&&... args);
187 template<
typename Callback,
typename... ARGS>
188 explicit thread(Callback c, ARGS&&... args);
198 template<
typename Callback,
typename... ARGS>
199 explicit thread(Callback c,
bool will_join, ARGS&&... args);
231 [[nodiscard]]
bool joinable()
const;
237 explicit operator bool()
const;
266template <
typename Callback>
270template <
typename Callback>
276 }
catch (
const error&) {
282inline original::threadBase::operator bool()
const
284 return this->
valid();
289 return !this->
valid();
293 return this->is_joinable;
297 : is_joinable(is_joinable) {}
300 if (this->is_joinable) {
307template<
typename Callback,
typename... ARGS>
311 [func = std::forward<Callback>(c), ...lambda_args = std::forward<ARGS>(args)]()
mutable {
312 std::invoke(std::move(func), std::move(lambda_args)...);
315 using bound_callback =
decltype(bound_lambda);
318 auto task =
new bound_thread_data(std::move(bound_lambda));
320 if (
const int code = pthread_create(&this->handle,
nullptr, &bound_thread_data::run, task); code != 0)
326inline bool original::pThread::valid()
const
328 return this->handle != pthread_t{};
333 this->operator=(std::move(other));
336inline original::pThread& original::pThread::operator=(
pThread&& other)
noexcept
338 if (
this == &other) {
342 if (this->is_joinable && this->valid()) {
343 pthread_detach(this->handle);
346 this->handle = other.handle;
348 this->is_joinable = other.is_joinable;
349 other.is_joinable =
false;
354 if (this->is_joinable){
355 if (
const int code = pthread_join(this->handle,
nullptr);
359 this->is_joinable =
false;
365 if (this->is_joinable){
366 if (
const int code = pthread_detach(this->handle);
370 this->is_joinable =
false;
378template <
typename Callback,
typename ... ARGS>
380 : thread_(std::forward<Callback>(c), std::forward<ARGS>(args)...), will_join(true) {}
382template <
typename Callback,
typename ... ARGS>
384 : thread_(std::forward<Callback>(c), std::forward<ARGS>(args)...), will_join(will_join) {}
387 : thread_(std::move(p_thread)), will_join(will_join) {}
390 : thread_(std::move(other.thread_)), will_join(
true) {}
393 : thread_(std::move(other.thread_)), will_join(will_join) {}
396 if (
this == &other) {
400 this->thread_ = std::move(other.thread_);
401 this->will_join = other.will_join;
402 other.will_join =
false;
408 this->thread_.
join();
413 this->thread_.detach();
418 if (this->thread_.joinable()) {
419 this->will_join ? this->thread_.join() : this->thread_.detach();
424 return this->thread_.joinable();
427original::thread::operator bool()
const {
428 return this->thread_.operator bool();
432 return this->thread_.operator!();
Base interface for all exception types in Original.
Definition error.h:50
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:30
POSIX thread implementation.
Definition thread.h:128
void detach()
Detach thread (allow it to run independently)
Definition thread.h:364
void join()
Wait for thread to complete.
Definition thread.h:353
pThread()
Construct empty (invalid) thread.
Definition thread.h:305
Wrapper for thread execution data.
Definition thread.h:58
threadData(Callback c)
Construct thread data wrapper.
Definition thread.h:267
static void * run(void *arg)
Thread entry point wrapper.
Definition thread.h:271
Base class for thread implementations.
Definition thread.h:49
virtual bool valid() const =0
Check if thread is valid.
virtual ~threadBase() noexcept(false)
Destructor.
Definition thread.h:299
threadBase(bool is_joinable=false)
Construct thread base.
Definition thread.h:296
bool joinable() const
Check if thread is joinable.
Definition thread.h:292
bool operator!() const
Check if thread is not valid.
Definition thread.h:287
High-level thread wrapper.
Definition thread.h:170
~thread()
Destructor.
Definition thread.h:416
void detach()
Detach thread (allow it to run independently)
Definition thread.h:411
bool operator!() const
Check if thread is not valid.
Definition thread.h:431
thread()
Construct empty thread.
Definition thread.h:375
bool joinable() const
Check if thread is joinable.
Definition thread.h:423
void join()
Wait for thread to complete.
Definition thread.h:406
Custom exception classes and callback validation utilities.
Main namespace for the project Original.
Definition algorithms.h:21
Exclusive-ownership smart pointer implementation.