Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CoderMixer2MT.h « Common « Archive « 7zip « CPP - github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 67c0c8a59f13da42cf663a3756af8eb5ffd5202d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// CoderMixer2MT.h

#ifndef __CODER_MIXER2_MT_H
#define __CODER_MIXER2_MT_H

#include "CoderMixer2.h"
#include "../../../Common/MyCom.h"
#include "../../../Windows/Thread.h"
#include "../../Common/StreamBinder.h"

namespace NCoderMixer2 {

//  CreateEvents();
//  {
//    SetCoderInfo()
//    Init Streams   
//    set CompressEvent()
//    wait CompressionCompletedEvent
//  }

struct CThreadCoderInfo: public CCoderInfo
{
  NWindows::NSynchronization::CAutoResetEvent CompressEvent;
  HANDLE ExitEvent;
  NWindows::NSynchronization::CAutoResetEvent CompressionCompletedEvent;

  CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;
  CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;
  CRecordVector<ISequentialInStream *> InStreamPointers;
  CRecordVector<ISequentialOutStream *> OutStreamPointers;

  CMyComPtr<ICompressProgressInfo> Progress; // CMyComPtr
  HRESULT Result;

  CThreadCoderInfo(UInt32 numInStreams, UInt32 numOutStreams);
  void SetCoderInfo(const UInt64 **inSizes,
      const UInt64 **outSizes, ICompressProgressInfo *progress);
  bool WaitAndCode();
  HRes CreateEvents()
  {
    RINOK(CompressEvent.CreateIfNotCreated());
    return CompressionCompletedEvent.CreateIfNotCreated();
  }
};


//  SetBindInfo()
//  for each coder
//  {
//    AddCoder[2]()
//  }
// 
//  for each file
//  {
//    ReInit()
//    for each coder
//    {
//      SetCoderInfo  
//    }
//    SetProgressIndex(UInt32 coderIndex);
//    Code
//  }


class CCoderMixer2MT:
  public ICompressCoder2,
  public CCoderMixer2,
  public CMyUnknownImp
{
  MY_UNKNOWN_IMP

public:
  STDMETHOD(Init)(ISequentialInStream **inStreams,
    ISequentialOutStream **outStreams);

  STDMETHOD(Code)(ISequentialInStream **inStreams,
      const UInt64 **inSizes, 
      UInt32 numInStreams,
      ISequentialOutStream **outStreams, 
      const UInt64 **outSizes,
      UInt32 numOutStreams,
      ICompressProgressInfo *progress);


  CCoderMixer2MT();
  ~CCoderMixer2MT();
  void AddCoderCommon();
  void AddCoder(ICompressCoder *coder);
  void AddCoder2(ICompressCoder2 *coder);

  void ReInit();
  void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)
    {  _coderInfoVector[coderIndex].SetCoderInfo(inSizes, outSizes, NULL); }
  void SetProgressCoderIndex(UInt32 coderIndex)
    {  _progressCoderIndex = coderIndex; }


  UInt64 GetWriteProcessedSize(UInt32 binderIndex) const;


  bool MyCode();

private:
  CBindInfo _bindInfo;
  CObjectVector<CStreamBinder> _streamBinders;
  CObjectVector<CThreadCoderInfo> _coderInfoVector;
  CRecordVector<NWindows::CThread> _threads;
  NWindows::CThread _mainThread;

  NWindows::NSynchronization::CAutoResetEvent _startCompressingEvent;
  NWindows::NSynchronization::CAutoResetEvent _compressingFinishedEvent;

  NWindows::NSynchronization::CManualResetEvent _exitEvent;
  UInt32 _progressCoderIndex;

  HRes CreateEvents()
  {
    RINOK(_startCompressingEvent.CreateIfNotCreated());
    RINOK(_compressingFinishedEvent.CreateIfNotCreated());
    return _exitEvent.CreateIfNotCreated();
  }

public:
  HRESULT SetBindInfo(const CBindInfo &bindInfo);

};

}
#endif