12 #ifndef ECL_THREADS_THREAD_POS_HPP_ 13 #define ECL_THREADS_THREAD_POS_HPP_ 20 #if defined(ECL_IS_POSIX) 27 #include "thread_exceptions_pos.hpp" 28 #include <ecl/config/macros.hpp> 29 #include <ecl/concepts/nullary_function.hpp> 30 #include <ecl/exceptions/standard_exception.hpp> 31 #include <ecl/utilities/void.hpp> 32 #include <ecl/utilities/function_objects.hpp> 33 #include "priority_pos.hpp" 53 virtual ~ThreadTaskBase() {};
56 ThreadTaskBase(
const Priority& priority) : priority_level(priority) {};
68 template <
typename F,
bool IsReferenceWrapper = false>
69 class ECL_LOCAL ThreadTask :
public ThreadTaskBase {
79 ThreadTask(
const F &f,
const Priority &priority) : ThreadTaskBase(priority), function(f) {
82 virtual ~ThreadTask() {};
94 static void* EntryPoint(
void *ptr_this) {
95 ThreadTask< F, false > *ptr =
static_cast< ThreadTask< F, false > *
>(ptr_this);
96 ecl::set_priority(ptr->priority_level);
116 template <
typename F>
117 class ECL_LOCAL ThreadTask<F, true> :
public ThreadTaskBase {
127 ThreadTask(
const F &f,
const Priority &priority) : ThreadTaskBase(priority), function(f.reference()) {
130 virtual ~ThreadTask() {};
142 static void* EntryPoint(
void *ptr_this) {
143 ThreadTask< F, true > *ptr =
static_cast< ThreadTask< F, true > *
>(ptr_this);
144 ecl::set_priority(ptr->priority_level);
152 typename F::type &
function;
245 join_requested(false)
300 template <typename C>
301 Thread(
void (C::*function)(), C &c, const
Priority &priority = DefaultPriority, const
long &stack_size = -1 )
ecl_debug_throw_decl(StandardException);
312 template <typename C>
313 Error start(
void (C::*function)(), C &c, const
Priority &priority = DefaultPriority, const
long &stack_size = -1 )
ecl_debug_throw_decl(StandardException);
353 template <typename F>
354 Thread(const F &function, const
Priority &priority = DefaultPriority, const
long &stack_size = -1 )
ecl_debug_throw_decl(StandardException);
364 template <typename F>
365 Error start(const F &function, const
Priority &priority = DefaultPriority, const
long &stack_size = -1 )
ecl_debug_throw_decl(StandardException);
382 bool isRunning()
const {
if ( thread_task == NULL ) {
return false; }
else {
return true; } }
415 pthread_t thread_handle;
416 pthread_attr_t attrs;
417 sched_param schedule_parameters;
418 threads::ThreadTaskBase *thread_task;
424 enum ThreadProperties {
425 DefaultStackSize = -1
433 template <
typename C>
437 join_requested(false)
439 start<C>(
function, c, priority, stack_size);
443 template <
typename F>
447 join_requested(false)
449 start<F>(
function, priority, stack_size);
452 template <
typename C>
453 Error Thread::start(
void (C::*
function)(), C &c,
const Priority &priority,
const long &stack_size)
ecl_debug_throw_decl(StandardException)
461 initialise(stack_size);
462 thread_task =
new threads::ThreadTask< BoundNullaryMemberFunction<C,void> >(
generateFunctionObject(
function, c ), priority);
463 int result = pthread_create(&(this->thread_handle), &(this->attrs), threads::ThreadTask< BoundNullaryMemberFunction<C,void> >::EntryPoint, thread_task);
464 pthread_attr_destroy(&attrs);
469 return threads::handlePthreadCreateError(result);
474 template <
typename F>
483 initialise(stack_size);
484 thread_task =
new threads::ThreadTask<F, is_reference_wrapper<F>::value >(
function, priority);
485 int result = pthread_create(&(this->thread_handle), &(this->attrs), threads::ThreadTask<F,
is_reference_wrapper<F>::value>::EntryPoint, thread_task);
486 pthread_attr_destroy(&attrs);
491 return threads::handlePthreadCreateError(result);
#define LOC
Stringify the line of code you are at.
Pre-processed macro definitions that define the target platform.
BoundUnaryFreeFunction< A, R > generateFunctionObject(R(*function)(A), I &a)
Generate a nullary function object from a bound unary global/static function.
static bool const value
The value for this integral constant wrapper.
#define ecl_assert_throw_decl(exception)
Assure throw exception declaration.
#define ecl_compile_time_concept_check(Model)
Compile time concept checking assertion.
#define ecl_debug_throw_decl(exception)
Debug mode throw exception declaration.
#define ecl_debug_throw(exception)
Debug mode exception throw.
Virtual interface definition for nullary function objects.