"Fossies" - the Fresh Open Source Software Archive 
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 "EncryptionThreadPool.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_Volume_EncryptionThreadPool
14 #define TC_HEADER_Volume_EncryptionThreadPool
15
16 #include "Platform/Platform.h"
17 #include "EncryptionMode.h"
18
19 namespace VeraCrypt
20 {
21 class EncryptionThreadPool
22 {
23 public:
24 struct WorkType
25 {
26 enum Enum
27 {
28 EncryptDataUnits,
29 DecryptDataUnits,
30 DeriveKey
31 };
32 };
33
34 struct WorkItem
35 {
36 struct State
37 {
38 enum Enum
39 {
40 Free,
41 Ready,
42 Busy
43 };
44 };
45
46 struct WorkItem *FirstFragment;
47 auto_ptr <Exception> ItemException;
48 SyncEvent ItemCompletedEvent;
49 SharedVal <size_t> OutstandingFragmentCount;
50 SharedVal <State::Enum> State;
51 WorkType::Enum Type;
52
53 union
54 {
55 struct
56 {
57 const EncryptionMode *Mode;
58 byte *Data;
59 uint64 StartUnitNo;
60 uint64 UnitCount;
61 size_t SectorSize;
62 } Encryption;
63 };
64 };
65
66 static void DoWork (WorkType::Enum type, const EncryptionMode *mode, byte *data, uint64 startUnitNo, uint64 unitCount, size_t sectorSize);
67 static bool IsRunning () { return ThreadPoolRunning; }
68 static void Start ();
69 static void Stop ();
70
71 protected:
72 static void WorkThreadProc ();
73
74 static const size_t MaxThreadCount = 32;
75 static const size_t QueueSize = MaxThreadCount * 2;
76
77 static Mutex DequeueMutex;
78 static volatile size_t DequeuePosition;
79 static volatile size_t EnqueuePosition;
80 static Mutex EnqueueMutex;
81 static list < shared_ptr <Thread> > RunningThreads;
82 static volatile bool StopPending;
83 static size_t ThreadCount;
84 static volatile bool ThreadPoolRunning;
85 static SyncEvent WorkItemCompletedEvent;
86 static WorkItem WorkItemQueue[QueueSize];
87 static SyncEvent WorkItemReadyEvent;
88 };
89 }
90
91 #endif // TC_HEADER_Volume_EncryptionThreadPool