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.
This commit is contained in:
Andrzej Rybczak
2009-03-26 16:18:11 +01:00
parent c634059834
commit 344fc21d76
5 changed files with 22 additions and 16 deletions

View File

@@ -27,9 +27,6 @@
# else # else
# include <sys/stat.h> # include <sys/stat.h>
# endif // WIN32 # endif // WIN32
# ifdef HAVE_PTHREAD_H
# include <pthread.h>
# endif
# include "curl/curl.h" # include "curl/curl.h"
# include "helpers.h" # include "helpers.h"
#endif #endif
@@ -53,7 +50,7 @@ const std::string Info::Folder = home_folder + "/.ncmpcpp/artists";
bool Info::ArtistReady = 0; bool Info::ArtistReady = 0;
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_H
pthread_t Info::Downloader = 0; pthread_t *Info::Downloader = 0;
#endif // HAVE_PTHREAD_H #endif // HAVE_PTHREAD_H
#endif // HAVE_CURL_CURL_H #endif // HAVE_CURL_CURL_H
@@ -83,8 +80,9 @@ void Info::Update()
if (!ArtistReady) if (!ArtistReady)
return; return;
pthread_join(Downloader, NULL); pthread_join(*Downloader, NULL);
w->Flush(); w->Flush();
delete Downloader;
Downloader = 0; Downloader = 0;
ArtistReady = 0; ArtistReady = 0;
} }
@@ -158,8 +156,12 @@ void Info::GetArtist()
static_cast<Window &>(*w) << "Fetching artist's info..."; static_cast<Window &>(*w) << "Fetching artist's info...";
# ifdef HAVE_PTHREAD_H # ifdef HAVE_PTHREAD_H
if (!Downloader) if (!Downloader)
pthread_create(&Downloader, NULL, PrepareArtist, artist); {
Downloader = new pthread_t;
pthread_create(Downloader, NULL, PrepareArtist, artist);
}
# else # else
w->Window::Refresh();
PrepareArtist(&artist); PrepareArtist(&artist);
w->Flush(); w->Flush();
# endif // HAVE_PTHREAD_H # endif // HAVE_PTHREAD_H

View File

@@ -61,7 +61,7 @@ class Info : public Screen<Scrollpad>
static bool ArtistReady; static bool ArtistReady;
# ifdef HAVE_PTHREAD_H # ifdef HAVE_PTHREAD_H
static pthread_t Downloader; static pthread_t *Downloader;
# endif // HAVE_PTHREAD_H # endif // HAVE_PTHREAD_H
# endif // HAVE_CURL_CURL_H # endif // HAVE_CURL_CURL_H

View File

@@ -54,7 +54,7 @@ bool Lyrics::Ready = 0;
std::string Lyrics::Filename; std::string Lyrics::Filename;
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_H
pthread_t Lyrics::Downloader = 0; pthread_t *Lyrics::Downloader = 0;
pthread_mutex_t Global::CurlLock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t Global::CurlLock = PTHREAD_MUTEX_INITIALIZER;
#endif // HAVE_PTHREAD_H #endif // HAVE_PTHREAD_H
@@ -134,8 +134,12 @@ void Lyrics::SwitchTo()
# endif // HAVE_CURL_CURL_H # endif // HAVE_CURL_CURL_H
# ifdef HAVE_PTHREAD_H # ifdef HAVE_PTHREAD_H
if (!Downloader) if (!Downloader)
pthread_create(&Downloader, NULL, Get, &itsSong); {
Downloader = new pthread_t;
pthread_create(Downloader, NULL, Get, &itsSong);
}
# else # else
w->Window::Refresh();
Get(&itsSong); Get(&itsSong);
w->Flush(); w->Flush();
# endif // HAVE_PTHREAD_H # endif // HAVE_PTHREAD_H
@@ -297,8 +301,9 @@ void Lyrics::Take()
{ {
if (!Ready) if (!Ready)
return; return;
pthread_join(Downloader, NULL); pthread_join(*Downloader, NULL);
w->Flush(); w->Flush();
delete Downloader;
Downloader = 0; Downloader = 0;
Ready = 0; Ready = 0;
} }

View File

@@ -26,9 +26,6 @@
#include "screen.h" #include "screen.h"
#ifdef HAVE_CURL_CURL_H #ifdef HAVE_CURL_CURL_H
# ifdef HAVE_PTHREAD_H
# include <pthread.h>
# endif
# include "curl/curl.h" # include "curl/curl.h"
#endif #endif
@@ -88,7 +85,7 @@ class Lyrics : public Screen<Scrollpad>
static bool Ready; static bool Ready;
# ifdef HAVE_PTHREAD_H # ifdef HAVE_PTHREAD_H
static pthread_t Downloader; static pthread_t *Downloader;
# endif // HAVE_PTHREAD_H # endif // HAVE_PTHREAD_H
static const char *PluginsList[]; static const char *PluginsList[];

View File

@@ -27,11 +27,13 @@
#include "menu.h" #include "menu.h"
#include "scrollpad.h" #include "scrollpad.h"
#ifndef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_H
# include <pthread.h>
#else
# define pthread_mutex_lock(x); # define pthread_mutex_lock(x);
# define pthread_mutex_unlock(x); # define pthread_mutex_unlock(x);
# define pthread_exit(x) return 0; # define pthread_exit(x) return 0;
#endif #endif // HAVE_PTHREAD_H
using namespace NCurses; using namespace NCurses;