Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | // CoderMixer2MT.h |
michael@0 | 2 | |
michael@0 | 3 | #ifndef __CODER_MIXER2_MT_H |
michael@0 | 4 | #define __CODER_MIXER2_MT_H |
michael@0 | 5 | |
michael@0 | 6 | #include "CoderMixer2.h" |
michael@0 | 7 | #include "../../../Common/MyCom.h" |
michael@0 | 8 | #include "../../../Windows/Thread.h" |
michael@0 | 9 | #include "../../Common/StreamBinder.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace NCoderMixer2 { |
michael@0 | 12 | |
michael@0 | 13 | // CreateEvents(); |
michael@0 | 14 | // { |
michael@0 | 15 | // SetCoderInfo() |
michael@0 | 16 | // Init Streams |
michael@0 | 17 | // set CompressEvent() |
michael@0 | 18 | // wait CompressionCompletedEvent |
michael@0 | 19 | // } |
michael@0 | 20 | |
michael@0 | 21 | struct CThreadCoderInfo: public CCoderInfo |
michael@0 | 22 | { |
michael@0 | 23 | NWindows::NSynchronization::CAutoResetEvent *CompressEvent; |
michael@0 | 24 | HANDLE ExitEvent; |
michael@0 | 25 | NWindows::NSynchronization::CAutoResetEvent *CompressionCompletedEvent; |
michael@0 | 26 | |
michael@0 | 27 | CObjectVector< CMyComPtr<ISequentialInStream> > InStreams; |
michael@0 | 28 | CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams; |
michael@0 | 29 | CRecordVector<ISequentialInStream *> InStreamPointers; |
michael@0 | 30 | CRecordVector<ISequentialOutStream *> OutStreamPointers; |
michael@0 | 31 | |
michael@0 | 32 | CMyComPtr<ICompressProgressInfo> Progress; // CMyComPtr |
michael@0 | 33 | HRESULT Result; |
michael@0 | 34 | |
michael@0 | 35 | CThreadCoderInfo(UInt32 numInStreams, UInt32 numOutStreams); |
michael@0 | 36 | void SetCoderInfo(const UInt64 **inSizes, |
michael@0 | 37 | const UInt64 **outSizes, ICompressProgressInfo *progress); |
michael@0 | 38 | ~CThreadCoderInfo(); |
michael@0 | 39 | bool WaitAndCode(); |
michael@0 | 40 | void CreateEvents(); |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | |
michael@0 | 44 | // SetBindInfo() |
michael@0 | 45 | // for each coder |
michael@0 | 46 | // { |
michael@0 | 47 | // AddCoder[2]() |
michael@0 | 48 | // } |
michael@0 | 49 | // |
michael@0 | 50 | // for each file |
michael@0 | 51 | // { |
michael@0 | 52 | // ReInit() |
michael@0 | 53 | // for each coder |
michael@0 | 54 | // { |
michael@0 | 55 | // SetCoderInfo |
michael@0 | 56 | // } |
michael@0 | 57 | // SetProgressIndex(UInt32 coderIndex); |
michael@0 | 58 | // Code |
michael@0 | 59 | // } |
michael@0 | 60 | |
michael@0 | 61 | |
michael@0 | 62 | class CCoderMixer2MT: |
michael@0 | 63 | public ICompressCoder2, |
michael@0 | 64 | public CCoderMixer2, |
michael@0 | 65 | public CMyUnknownImp |
michael@0 | 66 | { |
michael@0 | 67 | MY_UNKNOWN_IMP |
michael@0 | 68 | |
michael@0 | 69 | public: |
michael@0 | 70 | STDMETHOD(Init)(ISequentialInStream **inStreams, |
michael@0 | 71 | ISequentialOutStream **outStreams); |
michael@0 | 72 | |
michael@0 | 73 | STDMETHOD(Code)(ISequentialInStream **inStreams, |
michael@0 | 74 | const UInt64 **inSizes, |
michael@0 | 75 | UInt32 numInStreams, |
michael@0 | 76 | ISequentialOutStream **outStreams, |
michael@0 | 77 | const UInt64 **outSizes, |
michael@0 | 78 | UInt32 numOutStreams, |
michael@0 | 79 | ICompressProgressInfo *progress); |
michael@0 | 80 | |
michael@0 | 81 | |
michael@0 | 82 | CCoderMixer2MT(); |
michael@0 | 83 | ~CCoderMixer2MT(); |
michael@0 | 84 | void AddCoderCommon(); |
michael@0 | 85 | void AddCoder(ICompressCoder *coder); |
michael@0 | 86 | void AddCoder2(ICompressCoder2 *coder); |
michael@0 | 87 | |
michael@0 | 88 | void ReInit(); |
michael@0 | 89 | void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) |
michael@0 | 90 | { _coderInfoVector[coderIndex].SetCoderInfo(inSizes, outSizes, NULL); } |
michael@0 | 91 | void SetProgressCoderIndex(UInt32 coderIndex) |
michael@0 | 92 | { _progressCoderIndex = coderIndex; } |
michael@0 | 93 | |
michael@0 | 94 | |
michael@0 | 95 | UInt64 GetWriteProcessedSize(UInt32 binderIndex) const; |
michael@0 | 96 | |
michael@0 | 97 | |
michael@0 | 98 | bool MyCode(); |
michael@0 | 99 | |
michael@0 | 100 | private: |
michael@0 | 101 | CBindInfo _bindInfo; |
michael@0 | 102 | CObjectVector<CStreamBinder> _streamBinders; |
michael@0 | 103 | CObjectVector<CThreadCoderInfo> _coderInfoVector; |
michael@0 | 104 | CRecordVector<NWindows::CThread> _threads; |
michael@0 | 105 | NWindows::CThread _mainThread; |
michael@0 | 106 | |
michael@0 | 107 | NWindows::NSynchronization::CAutoResetEvent _startCompressingEvent; |
michael@0 | 108 | CRecordVector<HANDLE> _compressingCompletedEvents; |
michael@0 | 109 | NWindows::NSynchronization::CAutoResetEvent _compressingFinishedEvent; |
michael@0 | 110 | |
michael@0 | 111 | NWindows::NSynchronization::CManualResetEvent _exitEvent; |
michael@0 | 112 | UInt32 _progressCoderIndex; |
michael@0 | 113 | |
michael@0 | 114 | public: |
michael@0 | 115 | void SetBindInfo(const CBindInfo &bindInfo); |
michael@0 | 116 | |
michael@0 | 117 | }; |
michael@0 | 118 | |
michael@0 | 119 | } |
michael@0 | 120 | #endif |
michael@0 | 121 |