"Fossies" - the Fresh Open Source Software Archive

Member "src/Platform/Thread.h" (10 Oct 2018, 1744 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Thread.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file)
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #ifndef TC_HEADER_Platform_Thread
   14 #define TC_HEADER_Platform_Thread
   15 
   16 #ifdef TC_WINDOWS
   17 #   include "System.h"
   18 #   define TC_THREAD_PROC DWORD WINAPI
   19 #else
   20 #   include <pthread.h>
   21 #   define TC_THREAD_PROC void*
   22 #endif
   23 #include "PlatformBase.h"
   24 #include "Functor.h"
   25 #include "SharedPtr.h"
   26 #include "SyncEvent.h"
   27 
   28 namespace VeraCrypt
   29 {
   30     class Thread
   31     {
   32     public:
   33 #ifdef TC_WINDOWS
   34         typedef HANDLE ThreadSystemHandle;
   35         typedef LPTHREAD_START_ROUTINE ThreadProcPtr;
   36 #else
   37         typedef pthread_t ThreadSystemHandle;
   38         typedef void* (*ThreadProcPtr) (void *);
   39 #endif
   40         Thread () { };
   41         virtual ~Thread () { };
   42 
   43         void Join () const;
   44         void Start (ThreadProcPtr threadProc, void *parameter = nullptr);
   45 
   46         void Start (Functor *functor)
   47         {
   48             Start (Thread::FunctorEntry, (void *)functor);
   49         }
   50 
   51         static void Sleep (uint32 milliSeconds);
   52 
   53     protected:
   54         static TC_THREAD_PROC FunctorEntry (void *functorArg)
   55         {
   56             Functor *functor = (Functor *) functorArg;
   57             try
   58             {
   59                 (*functor) ();
   60             }
   61             catch (...) { }
   62 
   63             delete functor;
   64             return 0;
   65         }
   66 
   67         static const size_t MinThreadStackSize = 1024 * 1024;
   68 
   69         ThreadSystemHandle SystemHandle;
   70 
   71     private:
   72         Thread (const Thread &);
   73         Thread &operator= (const Thread &);
   74     };
   75 
   76 }
   77 
   78 #endif // TC_HEADER_Platform_Thread