HRESULT CEncoder::Create() { RINOK_THREAD(CanProcessEvent.CreateIfNotCreated()); RINOK_THREAD(CanStartWaitingEvent.CreateIfNotCreated()); if (ThreadsInfo != 0 && m_NumThreadsPrev == NumThreads) return S_OK; try { Free(); MtMode = (NumThreads > 1); m_NumThreadsPrev = NumThreads; ThreadsInfo = new CThreadInfo[NumThreads]; if (ThreadsInfo == 0) return E_OUTOFMEMORY; } catch(...) { return E_OUTOFMEMORY; } for (UInt32 t = 0; t < NumThreads; t++) { CThreadInfo &ti = ThreadsInfo[t]; ti.Encoder = this; if (MtMode) { HRESULT res = ti.Create(); if (res != S_OK) { NumThreads = t; Free(); return res; } } } return S_OK; }
HRESULT CDecoder::Create() { RINOK_THREAD(CanProcessEvent.CreateIfNotCreated()); RINOK_THREAD(CanStartWaitingEvent.CreateIfNotCreated()); if (m_States != 0 && m_NumThreadsPrev == NumThreads) return S_OK; Free(); MtMode = (NumThreads > 1); m_NumThreadsPrev = NumThreads; try { m_States = new CState[NumThreads]; if (!m_States) return E_OUTOFMEMORY; } catch(...) { return E_OUTOFMEMORY; } for (UInt32 t = 0; t < NumThreads; t++) { CState &ti = m_States[t]; ti.Decoder = this; if (MtMode) { HRESULT res = ti.Create(); if (res != S_OK) { NumThreads = t; Free(); return res; } } } return S_OK; }
HRESULT CState::Create() { RINOK_THREAD(StreamWasFinishedEvent.CreateIfNotCreated()); RINOK_THREAD(WaitingWasStartedEvent.CreateIfNotCreated()); RINOK_THREAD(CanWriteEvent.CreateIfNotCreated()); RINOK_THREAD(Thread.Create(MFThread, this)); return S_OK; }
static SRes CMtThread_Prepare(CMtThread *p) { MY_BUF_ALLOC(p->inBuf, p->inBufSize, p->mtCoder->blockSize) MY_BUF_ALLOC(p->outBuf, p->outBufSize, p->mtCoder->destBlockSize) p->stopReading = False; p->stopWriting = False; RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canRead)); RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canWrite)); return SZ_OK; }
static SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks) { if (p->wasCreated) return SZ_OK; RINOK_THREAD(CriticalSection_Init(&p->cs)); p->csWasInitialized = True; RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart)); RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted)); RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped)); RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks)); RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks)); p->needStart = True; RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj)); p->wasCreated = True; return SZ_OK; }