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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/7zstub/src/Windows/Thread.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,52 @@
     1.4 +// Windows/Thread.h
     1.5 +
     1.6 +#ifndef __WINDOWS_THREAD_H
     1.7 +#define __WINDOWS_THREAD_H
     1.8 +
     1.9 +#include "Handle.h"
    1.10 +#include "Defs.h"
    1.11 +
    1.12 +namespace NWindows {
    1.13 +
    1.14 +class CThread: public CHandle
    1.15 +{
    1.16 +  bool IsOpen() const { return _handle != 0; }
    1.17 +public:
    1.18 +  bool Create(LPSECURITY_ATTRIBUTES threadAttributes, 
    1.19 +      SIZE_T stackSize, LPTHREAD_START_ROUTINE startAddress,
    1.20 +      LPVOID parameter, DWORD creationFlags, LPDWORD threadId)
    1.21 +  {
    1.22 +    _handle = ::CreateThread(threadAttributes, stackSize, startAddress,
    1.23 +        parameter, creationFlags, threadId);
    1.24 +    return (_handle != NULL);
    1.25 +  }
    1.26 +  bool Create(LPTHREAD_START_ROUTINE startAddress, LPVOID parameter)
    1.27 +  {
    1.28 +    DWORD threadId;
    1.29 +    return Create(NULL, 0, startAddress, parameter, 0, &threadId);
    1.30 +  }
    1.31 +  
    1.32 +  DWORD Resume()
    1.33 +    { return ::ResumeThread(_handle); }
    1.34 +  DWORD Suspend()
    1.35 +    { return ::SuspendThread(_handle); }
    1.36 +  bool Terminate(DWORD exitCode)
    1.37 +    { return BOOLToBool(::TerminateThread(_handle, exitCode)); }
    1.38 +  
    1.39 +  int GetPriority()
    1.40 +    { return ::GetThreadPriority(_handle); }
    1.41 +  bool SetPriority(int priority)
    1.42 +    { return BOOLToBool(::SetThreadPriority(_handle, priority)); }
    1.43 +
    1.44 +  bool Wait() 
    1.45 +  { 
    1.46 +    if (!IsOpen())
    1.47 +      return true;
    1.48 +    return (::WaitForSingleObject(_handle, INFINITE) == WAIT_OBJECT_0); 
    1.49 +  }
    1.50 +
    1.51 +};
    1.52 +
    1.53 +}
    1.54 +
    1.55 +#endif

mercurial