25#ifndef JOIN_CORE_THREAD_HPP
26#define JOIN_CORE_THREAD_HPP
29#include <system_error>
56 template <
class Function,
class... Args>
57 explicit Invoker (Function&& func, Args&&... args)
58 :
Invoker (-1, 0,
std::forward<Function> (func),
std::forward<Args> (args)...)
69 template <
class Function,
class... Args>
70 explicit Invoker (
int core,
int prio, Function&& func, Args&&... args)
71 : _func (
std::bind (
std::forward<Function> (func),
std::forward<Args> (args)...))
76 pthread_create (&_handle,
nullptr, _routine,
this);
117 static void* _routine (
void* context);
126 std::function<void ()> _func;
138 std::atomic_bool _done;
160 template <class Function, class... Args>
161 explicit
Thread (Function&& func, Args&&... args)
162 :
Thread (-1, 0,
std::forward<Function> (func),
std::forward<Args> (args)...)
173 template <
class Function,
class... Args>
174 explicit Thread (
int core,
int prio, Function&& func, Args&&... args)
175 : _invoker (new
Invoker (core, prio,
std::forward<Function> (func),
std::forward<Args> (args)...))
262 bool running () const noexcept;
267 void join () noexcept;
290 pthread_t
handle () const noexcept;
thread invoker class.
Definition thread.hpp:43
Invoker()=delete
default constructor.
~Invoker()=default
destoyer.
Invoker(const Invoker &other)=delete
copy constructor.
Invoker & operator=(const Invoker &other)=delete
copy assignment.
Invoker(Invoker &&other)=delete
move constructor.
thread class.
Definition thread.hpp:148
int priority() const noexcept
get current thread priority.
Definition thread.cpp:224
int affinity() const noexcept
get current thread affinity.
Definition thread.cpp:159
~Thread()
destroys the thread object.
Definition thread.cpp:96
bool tryJoin() noexcept
performs a nonblocking join on the running thread.
Definition thread.cpp:264
Thread() noexcept=default
default constructor.
Thread(int core, int prio, Function &&func, Args &&... args)
creates a new thread object associated with a thread of execution.
Definition thread.hpp:174
Thread(const Thread &other)=delete
copy constructor.
void swap(Thread &other) noexcept
swap underlying handles of two thread objects.
Definition thread.cpp:291
void cancel() noexcept
cancel the running thread if any.
Definition thread.cpp:278
Thread & operator=(const Thread &other)=delete
copy assignment.
bool joinable() const noexcept
check if thread is joinable.
Definition thread.cpp:233
pthread_t handle() const noexcept
get the handle of the thread of execution. @retunr thread of execution handle.
Definition thread.cpp:300
bool running() const noexcept
check if the thread is running.
Definition thread.cpp:242
Definition acceptor.hpp:32