Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

Commit

Permalink
[smt] fixed hang in threads waiting mechanism
Browse files Browse the repository at this point in the history
Old mechanism used pthread_cond_timedwait()/pthread_cond_signal() to wait till end
of all threads executions. pthread_cond_signal() issued only once at the end of each
thread execution but the signal has no effect if the main thread is not blocked on
corresponding pthread_cond_timedwait. As a result smt could hang in the infinite loop.
  • Loading branch information
Vitaliy Ilichev authored and Oleg Nabiullin committed Nov 14, 2018
1 parent 07832b8 commit 8945928
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 125 deletions.
41 changes: 24 additions & 17 deletions samples/sample_multi_transcode/include/pipeline_transcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ or https://software.intel.com/en-us/media-client-solutions-support.
#include "mfxplugin.h"
#include "mfxplugin++.h"

#include "vm/atomic_defs.h"
#include "vm/thread_defs.h"

#include <memory>
#include <vector>
#include <list>
#include <ctime>
#include <map>
#include <future>
#include <chrono>

#include "sample_defs.h"
#include "sample_utils.h"
Expand Down Expand Up @@ -88,8 +87,6 @@ const mfxF64 MCTF_LOSSLESS_BPP = 0.0;

namespace TranscodingSample
{
extern mfxU32 MFX_STDCALL TranscodeRoutine(void *pObj);

enum PipelineMode
{
Native = 0, // means that pipeline is based depends on the cmd parameters (decode/encode/transcode)
Expand Down Expand Up @@ -910,28 +907,38 @@ namespace TranscodingSample
// Pointer to the session's pipeline
std::unique_ptr<CTranscodingPipeline> pPipeline;
// Pointer to bitstream handling object
FileBitstreamProcessor *pBSProcessor;
FileBitstreamProcessor *pBSProcessor = nullptr;
// Session implementation type
mfxIMPL implType;
mfxIMPL implType = MFX_IMPL_AUTO;

// Session's starting status
mfxStatus startStatus;
mfxStatus startStatus = MFX_ERR_NONE;
// Session's working time
mfxF64 working_time;
mfxF64 working_time = 0;

// Number of processed frames
mfxU32 numTransFrames;
mfxU32 numTransFrames = 0;
// Status of the finished session
mfxStatus transcodingSts;
mfxStatus transcodingSts = MFX_ERR_NONE;

ThreadTranscodeContext()
// Thread handle
std::future<void> handle;

void TranscodeRoutine()
{
pBSProcessor = NULL;
implType = MFX_IMPL_AUTO;
startStatus = MFX_ERR_NONE;
working_time = 0;
numTransFrames = 0;
using namespace std::chrono;
MSDK_CHECK_POINTER_NO_RET(pPipeline);
transcodingSts = MFX_ERR_NONE;

auto start_time = system_clock::now();
while (MFX_ERR_NONE == transcodingSts)
{
transcodingSts = pPipeline->Run();
}
working_time = duration_cast<microseconds>(system_clock::now() - start_time).count();

MSDK_IGNORE_MFX_STS(transcodingSts, MFX_WRN_VALUE_NOT_CHANGED);
numTransFrames = pPipeline->GetProcessFrames();
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ namespace TranscodingSample

// command line parser
CmdProcessor m_parser;
// sessions to process playlist
std::vector<ThreadTranscodeContext*> m_pSessionArray;
// handles
typedef std::vector<MSDKThread*>::iterator MSDKThreadsIterator;
std::vector<MSDKThread*> m_HDLArray;
// threads contexts to process playlist
std::vector<ThreadTranscodeContext*> m_pThreadContextArray;
// allocator for each session
std::vector<GeneralAllocator*> m_pAllocArray;
// input parameters for each session
Expand All @@ -91,4 +88,4 @@ namespace TranscodingSample
};
}

#endif
#endif
22 changes: 0 additions & 22 deletions samples/sample_multi_transcode/src/pipeline_transcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,6 @@ or https://software.intel.com/en-us/media-client-solutions-support.

using namespace TranscodingSample;

mfxU32 MFX_STDCALL TranscodingSample::TranscodeRoutine(void *pObj)
{
mfxU64 start = TranscodingSample::GetTick();
ThreadTranscodeContext *pContext = (ThreadTranscodeContext*)pObj;
pContext->transcodingSts = MFX_ERR_NONE;
for(;;)
{
while (MFX_ERR_NONE == pContext->transcodingSts)
{
pContext->transcodingSts = pContext->pPipeline->Run();
}
break; // exit loop
}

MSDK_IGNORE_MFX_STS(pContext->transcodingSts, MFX_WRN_VALUE_NOT_CHANGED);

pContext->working_time = TranscodingSample::GetTime(start);
pContext->numTransFrames = pContext->pPipeline->GetProcessFrames();

return 0;
} // mfxU32 __stdcall TranscodeRoutine(void *pObj)

#ifdef ENABLE_MCTF
namespace TranscodingSample
{
Expand Down
Loading

0 comments on commit 8945928

Please sign in to comment.