other-licenses/7zstub/src/Windows/Thread.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 // Windows/Thread.h
michael@0 2
michael@0 3 #ifndef __WINDOWS_THREAD_H
michael@0 4 #define __WINDOWS_THREAD_H
michael@0 5
michael@0 6 #include "Handle.h"
michael@0 7 #include "Defs.h"
michael@0 8
michael@0 9 namespace NWindows {
michael@0 10
michael@0 11 class CThread: public CHandle
michael@0 12 {
michael@0 13 bool IsOpen() const { return _handle != 0; }
michael@0 14 public:
michael@0 15 bool Create(LPSECURITY_ATTRIBUTES threadAttributes,
michael@0 16 SIZE_T stackSize, LPTHREAD_START_ROUTINE startAddress,
michael@0 17 LPVOID parameter, DWORD creationFlags, LPDWORD threadId)
michael@0 18 {
michael@0 19 _handle = ::CreateThread(threadAttributes, stackSize, startAddress,
michael@0 20 parameter, creationFlags, threadId);
michael@0 21 return (_handle != NULL);
michael@0 22 }
michael@0 23 bool Create(LPTHREAD_START_ROUTINE startAddress, LPVOID parameter)
michael@0 24 {
michael@0 25 DWORD threadId;
michael@0 26 return Create(NULL, 0, startAddress, parameter, 0, &threadId);
michael@0 27 }
michael@0 28
michael@0 29 DWORD Resume()
michael@0 30 { return ::ResumeThread(_handle); }
michael@0 31 DWORD Suspend()
michael@0 32 { return ::SuspendThread(_handle); }
michael@0 33 bool Terminate(DWORD exitCode)
michael@0 34 { return BOOLToBool(::TerminateThread(_handle, exitCode)); }
michael@0 35
michael@0 36 int GetPriority()
michael@0 37 { return ::GetThreadPriority(_handle); }
michael@0 38 bool SetPriority(int priority)
michael@0 39 { return BOOLToBool(::SetThreadPriority(_handle, priority)); }
michael@0 40
michael@0 41 bool Wait()
michael@0 42 {
michael@0 43 if (!IsOpen())
michael@0 44 return true;
michael@0 45 return (::WaitForSingleObject(_handle, INFINITE) == WAIT_OBJECT_0);
michael@0 46 }
michael@0 47
michael@0 48 };
michael@0 49
michael@0 50 }
michael@0 51
michael@0 52 #endif

mercurial