split data_ready to lyrics_ready and artist_info_ready to avoid main loop lockup
This commit is contained in:
@@ -31,7 +31,8 @@ const string lyrics_folder = home_folder + "/" + ".lyrics";
|
|||||||
|
|
||||||
#ifdef HAVE_CURL_CURL_H
|
#ifdef HAVE_CURL_CURL_H
|
||||||
pthread_mutex_t curl = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t curl = PTHREAD_MUTEX_INITIALIZER;
|
||||||
bool data_ready = 0;
|
bool artist_info_ready = 0;
|
||||||
|
bool lyrics_ready = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -87,7 +88,7 @@ void * GetArtistInfo(void *ptr)
|
|||||||
*result += line + "\n";
|
*result += line + "\n";
|
||||||
input.close();
|
input.close();
|
||||||
*result = result->substr(0, result->length()-1);
|
*result = result->substr(0, result->length()-1);
|
||||||
data_ready = 1;
|
artist_info_ready = 1;
|
||||||
pthread_exit(result);
|
pthread_exit(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +113,7 @@ void * GetArtistInfo(void *ptr)
|
|||||||
if (code != CURLE_OK)
|
if (code != CURLE_OK)
|
||||||
{
|
{
|
||||||
*result = "Error while fetching artist's info: " + string(curl_easy_strerror(code));
|
*result = "Error while fetching artist's info: " + string(curl_easy_strerror(code));
|
||||||
data_ready = 1;
|
artist_info_ready = 1;
|
||||||
pthread_exit(result);
|
pthread_exit(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +127,7 @@ void * GetArtistInfo(void *ptr)
|
|||||||
{
|
{
|
||||||
EscapeHtml(*result);
|
EscapeHtml(*result);
|
||||||
*result = "Last.fm returned an error message: " + *result;
|
*result = "Last.fm returned an error message: " + *result;
|
||||||
data_ready = 1;
|
artist_info_ready = 1;
|
||||||
pthread_exit(result);
|
pthread_exit(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +206,7 @@ void * GetArtistInfo(void *ptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data_ready = 1;
|
artist_info_ready = 1;
|
||||||
pthread_exit(result);
|
pthread_exit(result);
|
||||||
}
|
}
|
||||||
#endif // HAVE_CURL_CURL_H
|
#endif // HAVE_CURL_CURL_H
|
||||||
@@ -231,7 +232,7 @@ void * GetLyrics(void *song)
|
|||||||
input.close();
|
input.close();
|
||||||
*result = result->substr(0, result->length()-1);
|
*result = result->substr(0, result->length()-1);
|
||||||
# ifdef HAVE_CURL_CURL_H
|
# ifdef HAVE_CURL_CURL_H
|
||||||
data_ready = 1;
|
lyrics_ready = 1;
|
||||||
pthread_exit(result);
|
pthread_exit(result);
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
@@ -262,7 +263,7 @@ void * GetLyrics(void *song)
|
|||||||
if (code != CURLE_OK)
|
if (code != CURLE_OK)
|
||||||
{
|
{
|
||||||
*result = "Error while fetching lyrics: " + string(curl_easy_strerror(code));
|
*result = "Error while fetching lyrics: " + string(curl_easy_strerror(code));
|
||||||
data_ready = 1;
|
lyrics_ready = 1;
|
||||||
pthread_exit(result);
|
pthread_exit(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,7 +275,7 @@ void * GetLyrics(void *song)
|
|||||||
|
|
||||||
if (*result == "Not found")
|
if (*result == "Not found")
|
||||||
{
|
{
|
||||||
data_ready = 1;
|
lyrics_ready = 1;
|
||||||
pthread_exit(result);
|
pthread_exit(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +293,7 @@ void * GetLyrics(void *song)
|
|||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
data_ready = 1;
|
lyrics_ready = 1;
|
||||||
pthread_exit(result);
|
pthread_exit(result);
|
||||||
# else
|
# else
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -109,7 +109,8 @@ NcmpcppScreen prev_screen;
|
|||||||
#ifdef HAVE_CURL_CURL_H
|
#ifdef HAVE_CURL_CURL_H
|
||||||
pthread_t lyrics_downloader;
|
pthread_t lyrics_downloader;
|
||||||
pthread_t artist_info_downloader;
|
pthread_t artist_info_downloader;
|
||||||
extern bool data_ready;
|
extern bool artist_info_ready;
|
||||||
|
extern bool lyrics_ready;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool dont_change_now_playing = 0;
|
bool dont_change_now_playing = 0;
|
||||||
@@ -677,26 +678,27 @@ int main(int argc, char *argv[])
|
|||||||
reload_lyrics = 0;
|
reload_lyrics = 0;
|
||||||
}
|
}
|
||||||
# ifdef HAVE_CURL_CURL_H
|
# ifdef HAVE_CURL_CURL_H
|
||||||
if (data_ready)
|
if (artist_info_ready)
|
||||||
{
|
{
|
||||||
void *result;
|
void *result;
|
||||||
string *str_result = 0;
|
string *str_result = 0;
|
||||||
if (lyrics_downloader)
|
|
||||||
{
|
|
||||||
pthread_join(lyrics_downloader, &result);
|
|
||||||
str_result = static_cast<string *>(result);
|
|
||||||
sLyrics->Add(*str_result);
|
|
||||||
lyrics_downloader = 0;
|
|
||||||
}
|
|
||||||
if (artist_info_downloader)
|
|
||||||
{
|
|
||||||
pthread_join(artist_info_downloader, &result);
|
pthread_join(artist_info_downloader, &result);
|
||||||
str_result = static_cast<string *>(result);
|
str_result = static_cast<string *>(result);
|
||||||
sInfo->Add(*str_result);
|
sInfo->Add(*str_result);
|
||||||
artist_info_downloader = 0;
|
|
||||||
}
|
|
||||||
delete str_result;
|
delete str_result;
|
||||||
data_ready = 0;
|
artist_info_downloader = 0;
|
||||||
|
artist_info_ready = 0;
|
||||||
|
}
|
||||||
|
else if (lyrics_ready)
|
||||||
|
{
|
||||||
|
void *result;
|
||||||
|
string *str_result = 0;
|
||||||
|
pthread_join(lyrics_downloader, &result);
|
||||||
|
str_result = static_cast<string *>(result);
|
||||||
|
sLyrics->Add(*str_result);
|
||||||
|
delete str_result;
|
||||||
|
lyrics_downloader = 0;
|
||||||
|
lyrics_ready = 0;
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
// lyrics end
|
// lyrics end
|
||||||
|
|||||||
Reference in New Issue
Block a user