lastfm: put code that takes info from a thread to separate function

This commit is contained in:
Andrzej Rybczak
2010-08-13 05:54:37 +02:00
parent 3afa0028e6
commit a7b9088b87
2 changed files with 15 additions and 9 deletions

View File

@@ -64,13 +64,17 @@ std::basic_string<my_char_t> Lastfm::Title()
void Lastfm::Update() void Lastfm::Update()
{ {
if (isReadyToTake) if (isReadyToTake)
{ Take();
pthread_join(itsDownloader, 0); }
w->Flush();
w->Refresh(); void Lastfm::Take()
isDownloadInProgress = 0; {
isReadyToTake = 0; assert(isReadyToTake);
} pthread_join(itsDownloader, 0);
w->Flush();
w->Refresh();
isDownloadInProgress = 0;
isReadyToTake = 0;
} }
void Lastfm::SwitchTo() void Lastfm::SwitchTo()
@@ -84,8 +88,9 @@ void Lastfm::SwitchTo()
if (hasToBeResized) if (hasToBeResized)
Resize(); Resize();
// if something is ready to take, take it // get an old info if it waits
Update(); if (isReadyToTake)
Take();
Load(); Load();

View File

@@ -76,6 +76,7 @@ class Lastfm : public Screen<Scrollpad>
void Download(); void Download();
static void *DownloadWrapper(void *); static void *DownloadWrapper(void *);
void Take();
bool isReadyToTake; bool isReadyToTake;
bool isDownloadInProgress; bool isDownloadInProgress;
pthread_t itsDownloader; pthread_t itsDownloader;