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