Update README.md
[nemesis.git] / Platform / Thread.h
1 /*
2  Copyright (c) 2008 TrueCrypt Developers Association. All rights reserved.
3
4  Governed by the TrueCrypt License 3.0 the full text of which is contained in
5  the file License.txt included in TrueCrypt binary and source code distribution
6  packages.
7 */
8
9 #ifndef TC_HEADER_Platform_Thread
10 #define TC_HEADER_Platform_Thread
11
12 #ifdef TC_WINDOWS
13 #       include "System.h"
14 #       define TC_THREAD_PROC DWORD WINAPI
15 #else
16 #       include <pthread.h>
17 #       define TC_THREAD_PROC void*
18 #endif
19 #include "PlatformBase.h"
20 #include "Functor.h"
21 #include "SharedPtr.h"
22 #include "SyncEvent.h"
23
24 namespace TrueCrypt
25 {
26         class Thread
27         {
28         public:
29 #ifdef TC_WINDOWS
30                 typedef HANDLE ThreadSystemHandle;
31                 typedef LPTHREAD_START_ROUTINE ThreadProcPtr;
32 #else
33                 typedef pthread_t ThreadSystemHandle;
34                 typedef void* (*ThreadProcPtr) (void *);
35 #endif
36                 Thread () { };
37                 virtual ~Thread () { };
38
39                 void Join () const;
40                 void Start (ThreadProcPtr threadProc, void *parameter = nullptr);
41
42                 void Start (Functor *functor)
43                 {
44                         Start (Thread::FunctorEntry, (void *)functor);
45                 }
46
47                 static void Sleep (uint32 milliSeconds);
48
49         protected:
50                 static TC_THREAD_PROC FunctorEntry (void *functorArg)
51                 {
52                         Functor *functor = (Functor *) functorArg;
53                         try
54                         {
55                                 (*functor) ();
56                         }
57                         catch (...) { }
58
59                         delete functor;
60                         return 0;
61                 }
62
63                 static const size_t MinThreadStackSize = 1024 * 1024;
64
65                 ThreadSystemHandle SystemHandle;
66
67         private:
68                 Thread (const Thread &);
69                 Thread &operator= (const Thread &);
70         };
71
72 }
73
74 #endif // TC_HEADER_Platform_Thread
This page took 0.025895 seconds and 3 git commands to generate. Download a nemesis OSX (sierra+high sierra, tested/working) binary, with fuse-ext3 via e2fsprogs, at this link. application and installer are signed by screwjack, llc. must install fuse with macFUSE layer first.