Skip to content

Commit

Permalink
removed: BackGroundInfo Loader multithreading (no longer needed)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnova committed Jun 29, 2013
1 parent 98a74f4 commit 9752e49
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 75 deletions.
62 changes: 11 additions & 51 deletions xbmc/BackgroundInfoLoader.cpp
Expand Up @@ -26,47 +26,29 @@

using namespace std;

#define ITEMS_PER_THREAD 5

CBackgroundInfoLoader::CBackgroundInfoLoader(int nThreads)
CBackgroundInfoLoader::CBackgroundInfoLoader() : m_thread (NULL)
{
m_bStop = true;
m_pObserver=NULL;
m_pProgressCallback=NULL;
m_pVecItems = NULL;
m_nRequestedThreads = nThreads;
m_bStartCalled = false;
m_nActiveThreads = 0;
}

CBackgroundInfoLoader::~CBackgroundInfoLoader()
{
StopThread();
}

void CBackgroundInfoLoader::SetNumOfWorkers(int nThreads)
{
m_nRequestedThreads = nThreads;
}

void CBackgroundInfoLoader::Run()
{
try
{
if (m_vecItems.size() > 0)
{
{
CSingleLock lock(m_lock);
if (!m_bStartCalled)
{
OnLoaderStart();
m_bStartCalled = true;
}
}
OnLoaderStart();

while (!m_bStop)
{
CSingleLock lock(m_lock);
CFileItemPtr pItem;
vector<CFileItemPtr>::iterator iter = m_vecItems.begin();
if (iter != m_vecItems.end())
Expand All @@ -82,7 +64,6 @@ void CBackgroundInfoLoader::Run()
if ((m_pProgressCallback && m_pProgressCallback->Abort()) || m_bStop)
break;

lock.Leave();
try
{
if (LoadItem(pItem.get()) && m_pObserver)
Expand All @@ -95,15 +76,10 @@ void CBackgroundInfoLoader::Run()
}
}

CSingleLock lock(m_lock);
if (m_nActiveThreads == 1)
OnLoaderFinish();
m_nActiveThreads--;

OnLoaderFinish();
}
catch (...)
{
m_nActiveThreads--;
CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__);
}
}
Expand All @@ -122,26 +98,12 @@ void CBackgroundInfoLoader::Load(CFileItemList& items)

m_pVecItems = &items;
m_bStop = false;
m_bStartCalled = false;

int nThreads = m_nRequestedThreads;
if (nThreads == -1)
nThreads = (m_vecItems.size() / (ITEMS_PER_THREAD+1)) + 1;

if (nThreads > g_advancedSettings.m_bgInfoLoaderMaxThreads)
nThreads = g_advancedSettings.m_bgInfoLoaderMaxThreads;

m_nActiveThreads = nThreads;
for (int i=0; i < nThreads; i++)
{
CThread *pThread = new CThread(this, "BackgroundLoader");
pThread->Create();
m_thread = new CThread(this, "BackgroundLoader");
m_thread->Create();
#ifndef TARGET_POSIX
pThread->SetPriority(THREAD_PRIORITY_BELOW_NORMAL);
m_thread->SetPriority(THREAD_PRIORITY_BELOW_NORMAL);
#endif
m_workers.push_back(pThread);
}

}

void CBackgroundInfoLoader::StopAsync()
Expand All @@ -154,21 +116,19 @@ void CBackgroundInfoLoader::StopThread()
{
StopAsync();

for (int i=0; i<(int)m_workers.size(); i++)
if (m_thread)
{
m_workers[i]->StopThread();
delete m_workers[i];
m_thread->StopThread();
delete m_thread;
m_thread = NULL;
}

m_workers.clear();
m_vecItems.clear();
m_pVecItems = NULL;
m_nActiveThreads = 0;
}

bool CBackgroundInfoLoader::IsLoading()
{
return m_nActiveThreads > 0;
return m_thread != NULL;
}

void CBackgroundInfoLoader::SetObserver(IBackgroundLoaderObserver* pObserver)
Expand Down
12 changes: 3 additions & 9 deletions xbmc/BackgroundInfoLoader.h
Expand Up @@ -40,7 +40,7 @@ class IBackgroundLoaderObserver
class CBackgroundInfoLoader : public IRunnable
{
public:
CBackgroundInfoLoader(int nThreads=-1);
CBackgroundInfoLoader();
virtual ~CBackgroundInfoLoader();

void Load(CFileItemList& items);
Expand All @@ -50,11 +50,9 @@ class CBackgroundInfoLoader : public IRunnable
void SetProgressCallback(IProgressCallback* pCallback);
virtual bool LoadItem(CFileItem* pItem) { return false; };

void StopThread(); // will actually stop all worker threads.
void StopThread(); // will actually stop the loader thread.
void StopAsync(); // will ask loader to stop as soon as possible, but not block

void SetNumOfWorkers(int nThreads); // -1 means auto compute num of required threads

protected:
virtual void OnLoaderStart() {};
virtual void OnLoaderFinish() {};
Expand All @@ -63,14 +61,10 @@ class CBackgroundInfoLoader : public IRunnable
std::vector<CFileItemPtr> m_vecItems; // FileItemList would delete the items and we only want to keep a reference.
CCriticalSection m_lock;

bool m_bStartCalled;
volatile bool m_bStop;
int m_nRequestedThreads;
int m_nActiveThreads;
CThread *m_thread;

IBackgroundLoaderObserver* m_pObserver;
IProgressCallback* m_pProgressCallback;

std::vector<CThread *> m_workers;
};

4 changes: 2 additions & 2 deletions xbmc/ThumbLoader.cpp
Expand Up @@ -26,8 +26,8 @@
using namespace std;
using namespace XFILE;

CThumbLoader::CThumbLoader(int nThreads) :
CBackgroundInfoLoader(nThreads)
CThumbLoader::CThumbLoader() :
CBackgroundInfoLoader()
{
}

Expand Down
2 changes: 1 addition & 1 deletion xbmc/ThumbLoader.h
Expand Up @@ -25,7 +25,7 @@
class CThumbLoader : public CBackgroundInfoLoader
{
public:
CThumbLoader(int nThreads=-1);
CThumbLoader();
virtual ~CThumbLoader();

virtual void Initialize() { };
Expand Down
1 change: 0 additions & 1 deletion xbmc/addons/GUIWindowAddonBrowser.cpp
Expand Up @@ -59,7 +59,6 @@ using namespace std;
CGUIWindowAddonBrowser::CGUIWindowAddonBrowser(void)
: CGUIMediaWindow(WINDOW_ADDON_BROWSER, "AddonBrowser.xml")
{
m_thumbLoader.SetNumOfWorkers(1);
}

CGUIWindowAddonBrowser::~CGUIWindowAddonBrowser()
Expand Down
2 changes: 1 addition & 1 deletion xbmc/music/MusicInfoLoader.cpp
Expand Up @@ -41,7 +41,7 @@ using namespace XFILE;
using namespace MUSIC_INFO;

// HACK until we make this threadable - specify 1 thread only for now
CMusicInfoLoader::CMusicInfoLoader() : CBackgroundInfoLoader(1)
CMusicInfoLoader::CMusicInfoLoader() : CBackgroundInfoLoader()
{
m_mapFileItems = new CFileItemList;

Expand Down
2 changes: 1 addition & 1 deletion xbmc/music/MusicThumbLoader.cpp
Expand Up @@ -30,7 +30,7 @@
using namespace std;
using namespace MUSIC_INFO;

CMusicThumbLoader::CMusicThumbLoader() : CThumbLoader(1)
CMusicThumbLoader::CMusicThumbLoader() : CThumbLoader()
{
m_database = new CMusicDatabase;
}
Expand Down
2 changes: 1 addition & 1 deletion xbmc/pictures/PictureThumbLoader.cpp
Expand Up @@ -35,7 +35,7 @@
using namespace XFILE;
using namespace std;

CPictureThumbLoader::CPictureThumbLoader() : CThumbLoader(1), CJobQueue(true)
CPictureThumbLoader::CPictureThumbLoader() : CThumbLoader(), CJobQueue(true)
{
m_regenerateThumbs = false;
}
Expand Down
1 change: 0 additions & 1 deletion xbmc/pvr/windows/GUIWindowPVRRecordings.cpp
Expand Up @@ -42,7 +42,6 @@ CGUIWindowPVRRecordings::CGUIWindowPVRRecordings(CGUIWindowPVR *parent) :
CGUIWindowPVRCommon(parent, PVR_WINDOW_RECORDINGS, CONTROL_BTNRECORDINGS, CONTROL_LIST_RECORDINGS)
{
m_strSelectedPath = "pvr://recordings/";
m_thumbLoader.SetNumOfWorkers(1);
}

void CGUIWindowPVRRecordings::UnregisterObservers(void)
Expand Down
5 changes: 0 additions & 5 deletions xbmc/settings/AdvancedSettings.cpp
Expand Up @@ -346,8 +346,6 @@ void CAdvancedSettings::Initialize()
m_alwaysOnTop = false;
#endif

m_bgInfoLoaderMaxThreads = 5;

m_iPVRTimeCorrection = 0;
m_iPVRInfoToggleInterval = 3000;
m_bPVRShowEpgInfoOnEpgItemSelect = true;
Expand Down Expand Up @@ -1053,9 +1051,6 @@ void CAdvancedSettings::ParseSettingsFile(const CStdString &file)

XMLUtils::GetBoolean(pRootElement, "alwaysontop", m_alwaysOnTop);

XMLUtils::GetInt(pRootElement, "bginfoloadermaxthreads", m_bgInfoLoaderMaxThreads);
m_bgInfoLoaderMaxThreads = std::max(1, m_bgInfoLoaderMaxThreads);

TiXmlElement *pPVR = pRootElement->FirstChildElement("pvr");
if (pPVR)
{
Expand Down
1 change: 0 additions & 1 deletion xbmc/settings/AdvancedSettings.h
Expand Up @@ -337,7 +337,6 @@ class CAdvancedSettings : public ISettingCallback, public ISettingsHandler

CStdString m_cpuTempCmd;
CStdString m_gpuTempCmd;
int m_bgInfoLoaderMaxThreads;

/* PVR/TV related advanced settings */
int m_iPVRTimeCorrection; /*!< @brief correct all times (epg tags, timer tags, recording tags) by this amount of minutes. defaults to 0. */
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/VideoThumbLoader.cpp
Expand Up @@ -116,7 +116,7 @@ bool CThumbExtractor::DoWork()
}

CVideoThumbLoader::CVideoThumbLoader() :
CThumbLoader(1), CJobQueue(true), m_pStreamDetailsObs(NULL)
CThumbLoader(), CJobQueue(true), m_pStreamDetailsObs(NULL)
{
m_database = new CVideoDatabase();
}
Expand Down

4 comments on commit 9752e49

@wsoltys
Copy link

@wsoltys wsoltys commented on 9752e49 Jul 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arnova : this broke tag reading on audio files for me. Whenever I enter a directory with audio files (mixed formats) the window "scanning media info 100%" pops up and nothing happened anymore. The mouse still reacts until I press cancel. Then XBMC hangs totally.
I noticed that we never leave the loop "while (m_musicInfoLoader.IsLoading())" in GUIWindowMusicBase.cpp l1072. Isloading is still true even though the BackgroundLoader thread already ended.
Another message I noticed but it might be irrelevant is "Control 50 in window 10501 has been asked to focus, but it can't".
Please turn on music tag reading and try your changes again.

@arnova
Copy link
Member

@arnova arnova commented on 9752e49 Jul 7, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wsoltys : I think I understand why that happens. Will fix it later today. Thanks for the heads up.

@arnova
Copy link
Member

@arnova arnova commented on 9752e49 Jul 7, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wsoltys : Fixed in 94817e6

@wsoltys
Copy link

@wsoltys wsoltys commented on 9752e49 Jul 7, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arnova : yup works now. Thanks.

Please sign in to comment.