12 #ifndef ECL_THREADS_THREAD_WIN_HPP_ 13 #define ECL_THREADS_THREAD_WIN_HPP_ 19 #include <ecl/config/ecl.hpp> 20 #if defined(ECL_IS_WIN32) 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_win.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 unsigned int EntryPoint(
void *ptr_this) {
95 ThreadTask< F, false > *ptr =
static_cast< ThreadTask< F, false > *
>(ptr_this);
113 template <
typename F>
114 class ECL_LOCAL ThreadTask<F, true> :
public ThreadTaskBase {
124 ThreadTask(
const F &f,
const Priority &priority) : ThreadTaskBase(priority), function(f.reference()) {
127 virtual ~ThreadTask() {};
138 static unsigned int EntryPoint(
void *ptr_this) {
139 ThreadTask< F, true > *ptr =
static_cast< ThreadTask< F, true > *
>(ptr_this);
145 typename F::type &
function;
239 join_requested(false)
294 template <typename C>
295 Thread(
void (C::*function)(), C &c, const
Priority &priority = DefaultPriority, const
long &stack_size = -1 )
ecl_debug_throw_decl(StandardException);
306 template <typename C>
307 Error start(
void (C::*function)(), C &c, const
Priority &priority = DefaultPriority, const
long &stack_size = -1 )
ecl_debug_throw_decl(StandardException);
347 template <typename F>
348 Thread(const F &function, const
Priority &priority = DefaultPriority, const
long &stack_size = -1 )
ecl_debug_throw_decl(StandardException);
358 template <typename F>
359 Error start(const F &function, const
Priority &priority = DefaultPriority, const
long &stack_size = -1 )
ecl_debug_throw_decl(StandardException);
376 bool isRunning() {
if ( thread_task == NULL ) {
return false; }
else {
return true; } }
404 HANDLE thread_handle;
405 threads::ThreadTaskBase *thread_task;
411 enum ThreadProperties {
412 DefaultStackSize = -1
420 template <
typename C>
425 join_requested(false)
427 start<C>(
function, c, priority, stack_size);
431 template <
typename F>
436 join_requested(false)
438 start<F>(
function, priority, stack_size);
441 template <
typename C>
453 thread_task =
new threads::ThreadTask< BoundNullaryMemberFunction<C,void> >(
generateFunctionObject(
function, c ), priority);
457 thread_handle = CreateThread(NULL,
459 (LPTHREAD_START_ROUTINE)threads::ThreadTask< BoundNullaryMemberFunction<C,void> >::EntryPoint,
464 if (!thread_handle) {
469 BOOL bResult = FALSE;
472 bResult = SetThreadPriority(thread_handle, THREAD_PRIORITY_TIME_CRITICAL);
477 bResult = SetThreadPriority(thread_handle, HIGH_PRIORITY_CLASS);
480 bResult = SetThreadPriority(thread_handle, THREAD_PRIORITY_ABOVE_NORMAL);
483 bResult = SetThreadPriority(thread_handle, THREAD_PRIORITY_BELOW_NORMAL);
486 bResult = SetThreadPriority(thread_handle, THREAD_PRIORITY_IDLE);
499 template <
typename F>
511 thread_task =
new threads::ThreadTask<F, is_reference_wrapper<F>::value >(
function, priority);
515 thread_handle = CreateThread(NULL,
522 if (!thread_handle) {
527 BOOL bResult = FALSE;
530 bResult = SetThreadPriority(thread_handle, THREAD_PRIORITY_TIME_CRITICAL);
535 bResult = SetThreadPriority(thread_handle, HIGH_PRIORITY_CLASS);
538 bResult = SetThreadPriority(thread_handle, THREAD_PRIORITY_ABOVE_NORMAL);
541 bResult = SetThreadPriority(thread_handle, THREAD_PRIORITY_BELOW_NORMAL);
544 bResult = SetThreadPriority(thread_handle, THREAD_PRIORITY_IDLE);
#define LOC
Stringify the line of code you are at.
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_threads_PUBLIC
#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.