Changed to unique_ptr for the threading in VideoFFmpegComponent and TextureDataManager.

This commit is contained in:
Leon Styhre 2021-05-12 22:49:24 +02:00
parent 398e47e2cc
commit f3f86c6e20
4 changed files with 7 additions and 7 deletions

View file

@ -189,7 +189,8 @@ void VideoFFmpegComponent::update(int deltaTime)
mTimeReference = std::chrono::high_resolution_clock::now();
if (!mFrameProcessingThread)
mFrameProcessingThread = new std::thread(&VideoFFmpegComponent::frameProcessing, this);
mFrameProcessingThread =
std::make_unique<std::thread>(&VideoFFmpegComponent::frameProcessing, this);
}
void VideoFFmpegComponent::frameProcessing()
@ -729,8 +730,7 @@ void VideoFFmpegComponent::stopVideo()
if (mFrameProcessingThread) {
// Wait for the thread execution to complete.
mFrameProcessingThread->join();
delete mFrameProcessingThread;
mFrameProcessingThread = nullptr;
mFrameProcessingThread.reset();
}
// Clear the video and audio frame queues.

View file

@ -74,7 +74,7 @@ private:
std::shared_ptr<TextureResource> mTexture;
std::vector<float> mVideoRectangleCoords;
std::thread* mFrameProcessingThread;
std::unique_ptr<std::thread> mFrameProcessingThread;
std::mutex mPictureMutex;
AVFormatContext* mFormatContext;

View file

@ -149,7 +149,7 @@ void TextureDataManager::load(std::shared_ptr<TextureData> tex, bool block)
TextureLoader::TextureLoader() : mExit(false)
{
mThread = new std::thread(&TextureLoader::threadProc, this);
mThread = std::make_unique<std::thread>(&TextureLoader::threadProc, this);
}
TextureLoader::~TextureLoader()
@ -162,7 +162,7 @@ TextureLoader::~TextureLoader()
mExit = true;
mEvent.notify_one();
mThread->join();
delete mThread;
mThread.reset();
}
void TextureLoader::threadProc()

View file

@ -38,7 +38,7 @@ private:
std::map<TextureData*,
std::list<std::shared_ptr<TextureData>>::const_iterator> mTextureDataLookup;
std::thread* mThread;
std::unique_ptr<std::thread> mThread;
std::mutex mMutex;
std::condition_variable mEvent;
bool mExit;