ce188d4d |
1 | /* MtCoder.h -- Multi-thread Coder\r |
2 | 2009-11-19 : Igor Pavlov : Public domain */\r |
3 | \r |
4 | #ifndef __MT_CODER_H\r |
5 | #define __MT_CODER_H\r |
6 | \r |
7 | #include "Threads.h"\r |
8 | \r |
9 | EXTERN_C_BEGIN\r |
10 | \r |
11 | typedef struct\r |
12 | {\r |
13 | CThread thread;\r |
14 | CAutoResetEvent startEvent;\r |
15 | CAutoResetEvent finishedEvent;\r |
16 | int stop;\r |
17 | \r |
18 | THREAD_FUNC_TYPE func;\r |
19 | LPVOID param;\r |
20 | THREAD_FUNC_RET_TYPE res;\r |
21 | } CLoopThread;\r |
22 | \r |
23 | void LoopThread_Construct(CLoopThread *p);\r |
24 | void LoopThread_Close(CLoopThread *p);\r |
25 | WRes LoopThread_Create(CLoopThread *p);\r |
26 | WRes LoopThread_StopAndWait(CLoopThread *p);\r |
27 | WRes LoopThread_StartSubThread(CLoopThread *p);\r |
28 | WRes LoopThread_WaitSubThread(CLoopThread *p);\r |
29 | \r |
30 | #ifndef _7ZIP_ST\r |
31 | #define NUM_MT_CODER_THREADS_MAX 32\r |
32 | #else\r |
33 | #define NUM_MT_CODER_THREADS_MAX 1\r |
34 | #endif\r |
35 | \r |
36 | typedef struct\r |
37 | {\r |
38 | UInt64 totalInSize;\r |
39 | UInt64 totalOutSize;\r |
40 | ICompressProgress *progress;\r |
41 | SRes res;\r |
42 | CCriticalSection cs;\r |
43 | UInt64 inSizes[NUM_MT_CODER_THREADS_MAX];\r |
44 | UInt64 outSizes[NUM_MT_CODER_THREADS_MAX];\r |
45 | } CMtProgress;\r |
46 | \r |
47 | SRes MtProgress_Set(CMtProgress *p, unsigned index, UInt64 inSize, UInt64 outSize);\r |
48 | \r |
49 | struct _CMtCoder;\r |
50 | \r |
51 | typedef struct\r |
52 | {\r |
53 | struct _CMtCoder *mtCoder;\r |
54 | Byte *outBuf;\r |
55 | size_t outBufSize;\r |
56 | Byte *inBuf;\r |
57 | size_t inBufSize;\r |
58 | unsigned index;\r |
59 | CLoopThread thread;\r |
60 | \r |
61 | Bool stopReading;\r |
62 | Bool stopWriting;\r |
63 | CAutoResetEvent canRead;\r |
64 | CAutoResetEvent canWrite;\r |
65 | } CMtThread;\r |
66 | \r |
67 | typedef struct\r |
68 | {\r |
69 | SRes (*Code)(void *p, unsigned index, Byte *dest, size_t *destSize,\r |
70 | const Byte *src, size_t srcSize, int finished);\r |
71 | } IMtCoderCallback;\r |
72 | \r |
73 | typedef struct _CMtCoder\r |
74 | {\r |
75 | size_t blockSize;\r |
76 | size_t destBlockSize;\r |
77 | unsigned numThreads;\r |
78 | \r |
79 | ISeqInStream *inStream;\r |
80 | ISeqOutStream *outStream;\r |
81 | ICompressProgress *progress;\r |
82 | ISzAlloc *alloc;\r |
83 | \r |
84 | IMtCoderCallback *mtCallback;\r |
85 | CCriticalSection cs;\r |
86 | SRes res;\r |
87 | \r |
88 | CMtProgress mtProgress;\r |
89 | CMtThread threads[NUM_MT_CODER_THREADS_MAX];\r |
90 | } CMtCoder;\r |
91 | \r |
92 | void MtCoder_Construct(CMtCoder* p);\r |
93 | void MtCoder_Destruct(CMtCoder* p);\r |
94 | SRes MtCoder_Code(CMtCoder *p);\r |
95 | \r |
96 | EXTERN_C_END\r |
97 | \r |
98 | #endif\r |