@@ -2725,7 +2725,10 @@ void IGFD::ThumbnailFeature::m_StartThumbnailFileDatasExtraction() {
27252725 m_CountFiles = 0U ;
27262726 m_ThumbnailGenerationThread = std::shared_ptr<std::thread>(new std::thread (&IGFD::ThumbnailFeature::m_ThreadThumbnailFileDatasExtractionFunc, this ), [this ](std::thread* obj) {
27272727 m_IsWorking = false ;
2728- if (obj) obj->join ();
2728+ if (obj) {
2729+ m_ThumbnailFileDatasToGetCv.notify_all ();
2730+ obj->join ();
2731+ }
27292732 });
27302733 }
27312734}
@@ -2745,12 +2748,14 @@ void IGFD::ThumbnailFeature::m_ThreadThumbnailFileDatasExtractionFunc() {
27452748
27462749 // infinite loop while is thread working
27472750 while (m_IsWorking) {
2751+ std::unique_lock<std::mutex> thumbnailFileDatasToGetLock (m_ThumbnailFileDatasToGetMutex);
2752+ m_ThumbnailFileDatasToGetCv.wait (thumbnailFileDatasToGetLock);
27482753 if (!m_ThumbnailFileDatasToGet.empty ()) {
27492754 std::shared_ptr<FileInfos> file = nullptr ;
2750- m_ThumbnailFileDatasToGetMutex.lock ();
27512755 // get the first file in the list
27522756 file = (*m_ThumbnailFileDatasToGet.begin ());
2753- m_ThumbnailFileDatasToGetMutex.unlock ();
2757+ m_ThumbnailFileDatasToGet.pop_front ();
2758+ thumbnailFileDatasToGetLock.unlock ();
27542759
27552760 // retrieve datas of the texture file if its an image file
27562761 if (file.use_count ()) {
@@ -2803,16 +2808,9 @@ void IGFD::ThumbnailFeature::m_ThreadThumbnailFileDatasExtractionFunc() {
28032808 }
28042809 }
28052810 }
2806-
2807- // peu importe le resultat on vire le fichier
2808- // remove form this list
2809- // write => thread concurency issues
2810- m_ThumbnailFileDatasToGetMutex.lock ();
2811- m_ThumbnailFileDatasToGet.pop_front ();
2812- m_ThumbnailFileDatasToGetMutex.unlock ();
28132811 }
28142812 } else {
2815- std::this_thread::sleep_for ( std::chrono::milliseconds ( 100 ) );
2813+ thumbnailFileDatasToGetLock. unlock ( );
28162814 }
28172815 }
28182816}
@@ -2849,6 +2847,7 @@ void IGFD::ThumbnailFeature::m_AddThumbnailToLoad(const std::shared_ptr<FileInfo
28492847 m_ThumbnailFileDatasToGet.push_back (vFileInfos);
28502848 vFileInfos->thumbnailInfo .isLoadingOrLoaded = true ;
28512849 m_ThumbnailFileDatasToGetMutex.unlock ();
2850+ m_ThumbnailFileDatasToGetCv.notify_all ();
28522851 }
28532852 }
28542853 }
@@ -2913,31 +2912,31 @@ void IGFD::ThumbnailFeature::SetDestroyThumbnailCallback(const DestroyThumbnailF
29132912
29142913void IGFD::ThumbnailFeature::ManageGPUThumbnails () {
29152914 if (m_CreateThumbnailFun) {
2915+ m_ThumbnailToCreateMutex.lock ();
29162916 if (!m_ThumbnailToCreate.empty ()) {
29172917 for (const auto & file : m_ThumbnailToCreate) {
29182918 if (file.use_count ()) {
29192919 m_CreateThumbnailFun (&file->thumbnailInfo );
29202920 }
29212921 }
2922- m_ThumbnailToCreateMutex.lock ();
29232922 m_ThumbnailToCreate.clear ();
2924- m_ThumbnailToCreateMutex.unlock ();
29252923 }
2924+ m_ThumbnailToCreateMutex.unlock ();
29262925 } else {
29272926 printf (
29282927 " No Callback found for create texture\n You need to define the callback with a call to "
29292928 " SetCreateThumbnailCallback\n " );
29302929 }
29312930
29322931 if (m_DestroyThumbnailFun) {
2932+ m_ThumbnailToDestroyMutex.lock ();
29332933 if (!m_ThumbnailToDestroy.empty ()) {
29342934 for (auto thumbnail : m_ThumbnailToDestroy) {
29352935 m_DestroyThumbnailFun (&thumbnail);
29362936 }
2937- m_ThumbnailToDestroyMutex.lock ();
29382937 m_ThumbnailToDestroy.clear ();
2939- m_ThumbnailToDestroyMutex.unlock ();
29402938 }
2939+ m_ThumbnailToDestroyMutex.unlock ();
29412940 } else {
29422941 printf (
29432942 " No Callback found for destroy texture\n You need to define the callback with a call to "
0 commit comments