diff options
Diffstat (limited to 'CPP/Windows/Thread.h')
-rwxr-xr-x | CPP/Windows/Thread.h | 56 |
1 files changed, 22 insertions, 34 deletions
diff --git a/CPP/Windows/Thread.h b/CPP/Windows/Thread.h index 5b676027..044ec9a3 100755 --- a/CPP/Windows/Thread.h +++ b/CPP/Windows/Thread.h @@ -3,47 +3,35 @@ #ifndef __WINDOWS_THREAD_H #define __WINDOWS_THREAD_H -// #include <process.h> +#include <process.h> -#include "Handle.h" #include "Defs.h" +extern "C" +{ +#include "../../C/Threads.h" +} + namespace NWindows { -class CThread: public CHandle +class CThread { - bool IsOpen() const { return _handle != 0; } + ::CThread thread; public: - bool Create(LPSECURITY_ATTRIBUTES threadAttributes, - SIZE_T stackSize, LPTHREAD_START_ROUTINE startAddress, - LPVOID parameter, DWORD creationFlags, LPDWORD threadId) - { - _handle = ::CreateThread(threadAttributes, stackSize, startAddress, - parameter, creationFlags, threadId); - return (_handle != NULL); - } - bool Create(LPTHREAD_START_ROUTINE startAddress, LPVOID parameter) - { - DWORD threadId; - return Create(NULL, 0, startAddress, parameter, 0, &threadId); - /* - _handle = (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, NULL); - return (_handle != NULL); - */ - } - - DWORD Resume() { return ::ResumeThread(_handle); } - DWORD Suspend() { return ::SuspendThread(_handle); } - bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(_handle, exitCode)); } - int GetPriority() { return ::GetThreadPriority(_handle); } - bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(_handle, priority)); } - - bool Wait() - { - if (!IsOpen()) - return true; - return (::WaitForSingleObject(_handle, INFINITE) == WAIT_OBJECT_0); - } + CThread() { Thread_Construct(&thread); } + ~CThread() { Close(); } + HRes Close() { return Thread_Close(&thread); } + HRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter) + { return Thread_Create(&thread, startAddress, parameter); } + HRes Wait() { return Thread_Wait(&thread); } + + #ifdef _WIN32 + DWORD Resume() { return ::ResumeThread(thread.handle); } + DWORD Suspend() { return ::SuspendThread(thread.handle); } + bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread.handle, exitCode)); } + int GetPriority() { return ::GetThreadPriority(thread.handle); } + bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread.handle, priority)); } + #endif }; } |