|
|
1.1 root 1: /*
1.1.1.6 root 2: Copyright (c) 2008 TrueCrypt Developers Association. All rights reserved.
1.1 root 3:
1.1.1.7 ! root 4: Governed by the TrueCrypt License 3.0 the full text of which is contained in
1.1.1.6 root 5: the file License.txt included in TrueCrypt binary and source code distribution
6: packages.
1.1 root 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"
1.1.1.2 root 22: #include "SyncEvent.h"
1.1 root 23:
24: namespace TrueCrypt
25: {
26: class Thread
27: {
28: public:
29: #ifdef TC_WINDOWS
1.1.1.2 root 30: typedef HANDLE ThreadSystemHandle;
1.1 root 31: typedef LPTHREAD_START_ROUTINE ThreadProcPtr;
32: #else
1.1.1.2 root 33: typedef pthread_t ThreadSystemHandle;
1.1 root 34: typedef void* (*ThreadProcPtr) (void *);
35: #endif
36: Thread () { };
37: virtual ~Thread () { };
38:
1.1.1.2 root 39: void Join () const;
1.1 root 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:
1.1.1.2 root 65: ThreadSystemHandle SystemHandle;
66:
1.1 root 67: private:
68: Thread (const Thread &);
69: Thread &operator= (const Thread &);
70: };
71:
72: }
73:
74: #endif // TC_HEADER_Platform_Thread
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.