12 #include <ecl/config/ecl.hpp>
13 #if defined(ECL_IS_WIN32)
20 #include "../../include/ecl/threads/thread_win.hpp"
38 start(
function, priority, stack_size);
41 Error Thread::start(VoidFunction
function,
const Priority &priority,
const long &stack_size)
46 ecl_debug_throw(StandardException(LOC,BusyError,
"The thread has already been started."));
47 return Error(BusyError);
53 thread_task =
new threads::ThreadTask< NullaryFreeFunction<void> >(nullary_function_object, priority);
57 thread_handle = CreateThread(NULL,
59 (LPTHREAD_START_ROUTINE)threads::ThreadTask< NullaryFreeFunction<void> >::EntryPoint,
65 ecl_debug_throw(StandardException(LOC, UnknownError,
"Failed to create thread."));
66 return Error(UnknownError);
72 bResult = SetThreadPriority(thread_handle, THREAD_PRIORITY_TIME_CRITICAL);
77 bResult = SetThreadPriority(thread_handle, HIGH_PRIORITY_CLASS);
80 bResult = SetThreadPriority(thread_handle, THREAD_PRIORITY_ABOVE_NORMAL);
83 bResult = SetThreadPriority(thread_handle, THREAD_PRIORITY_BELOW_NORMAL);
86 bResult = SetThreadPriority(thread_handle, THREAD_PRIORITY_IDLE);
96 return Error(NoError);
103 void Thread::cancel() {
105 unsigned long exitcode;
106 if (::GetExitCodeThread(thread_handle, &exitcode)) {
107 if (exitcode == 0x0103) {
109 ::TerminateThread(thread_handle, exitcode);
112 ::CloseHandle(thread_handle);
113 thread_handle = NULL;
120 join_requested =
false;
123 void Thread::join() {
124 join_requested =
true;
127 WaitForSingleObject(thread_handle, INFINITE);
131 void Thread::initialise(
const long &stack_size) {