From 344fc21d7622278795f50a534cb87d86864257b1 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Thu, 26 Mar 2009 16:18:11 +0100 Subject: [PATCH] use pthread_t * handlers rather than pthread_t pthread-win32 doesn't accept assigning zero to pthread_t type, so we need to use pointers instead. this is more semantic anyway. --- src/info.cpp | 14 ++++++++------ src/info.h | 2 +- src/lyrics.cpp | 11 ++++++++--- src/lyrics.h | 5 +---- src/ncmpcpp.h | 6 ++++-- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/info.cpp b/src/info.cpp index 3c2d3596..a9b3f0e6 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -27,9 +27,6 @@ # else # include # endif // WIN32 -# ifdef HAVE_PTHREAD_H -# include -# endif # include "curl/curl.h" # include "helpers.h" #endif @@ -53,7 +50,7 @@ const std::string Info::Folder = home_folder + "/.ncmpcpp/artists"; bool Info::ArtistReady = 0; #ifdef HAVE_PTHREAD_H -pthread_t Info::Downloader = 0; +pthread_t *Info::Downloader = 0; #endif // HAVE_PTHREAD_H #endif // HAVE_CURL_CURL_H @@ -83,8 +80,9 @@ void Info::Update() if (!ArtistReady) return; - pthread_join(Downloader, NULL); + pthread_join(*Downloader, NULL); w->Flush(); + delete Downloader; Downloader = 0; ArtistReady = 0; } @@ -158,8 +156,12 @@ void Info::GetArtist() static_cast(*w) << "Fetching artist's info..."; # ifdef HAVE_PTHREAD_H if (!Downloader) - pthread_create(&Downloader, NULL, PrepareArtist, artist); + { + Downloader = new pthread_t; + pthread_create(Downloader, NULL, PrepareArtist, artist); + } # else + w->Window::Refresh(); PrepareArtist(&artist); w->Flush(); # endif // HAVE_PTHREAD_H diff --git a/src/info.h b/src/info.h index 43fabe7b..ed3acb46 100644 --- a/src/info.h +++ b/src/info.h @@ -61,7 +61,7 @@ class Info : public Screen static bool ArtistReady; # ifdef HAVE_PTHREAD_H - static pthread_t Downloader; + static pthread_t *Downloader; # endif // HAVE_PTHREAD_H # endif // HAVE_CURL_CURL_H diff --git a/src/lyrics.cpp b/src/lyrics.cpp index 2567926e..d614e1fe 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -54,7 +54,7 @@ bool Lyrics::Ready = 0; std::string Lyrics::Filename; #ifdef HAVE_PTHREAD_H -pthread_t Lyrics::Downloader = 0; +pthread_t *Lyrics::Downloader = 0; pthread_mutex_t Global::CurlLock = PTHREAD_MUTEX_INITIALIZER; #endif // HAVE_PTHREAD_H @@ -134,8 +134,12 @@ void Lyrics::SwitchTo() # endif // HAVE_CURL_CURL_H # ifdef HAVE_PTHREAD_H if (!Downloader) - pthread_create(&Downloader, NULL, Get, &itsSong); + { + Downloader = new pthread_t; + pthread_create(Downloader, NULL, Get, &itsSong); + } # else + w->Window::Refresh(); Get(&itsSong); w->Flush(); # endif // HAVE_PTHREAD_H @@ -297,8 +301,9 @@ void Lyrics::Take() { if (!Ready) return; - pthread_join(Downloader, NULL); + pthread_join(*Downloader, NULL); w->Flush(); + delete Downloader; Downloader = 0; Ready = 0; } diff --git a/src/lyrics.h b/src/lyrics.h index ea9c6491..96668cb7 100644 --- a/src/lyrics.h +++ b/src/lyrics.h @@ -26,9 +26,6 @@ #include "screen.h" #ifdef HAVE_CURL_CURL_H -# ifdef HAVE_PTHREAD_H -# include -# endif # include "curl/curl.h" #endif @@ -88,7 +85,7 @@ class Lyrics : public Screen static bool Ready; # ifdef HAVE_PTHREAD_H - static pthread_t Downloader; + static pthread_t *Downloader; # endif // HAVE_PTHREAD_H static const char *PluginsList[]; diff --git a/src/ncmpcpp.h b/src/ncmpcpp.h index 9db7ebe0..e945acf8 100644 --- a/src/ncmpcpp.h +++ b/src/ncmpcpp.h @@ -27,11 +27,13 @@ #include "menu.h" #include "scrollpad.h" -#ifndef HAVE_PTHREAD_H +#ifdef HAVE_PTHREAD_H +# include +#else # define pthread_mutex_lock(x); # define pthread_mutex_unlock(x); # define pthread_exit(x) return 0; -#endif +#endif // HAVE_PTHREAD_H using namespace NCurses;