simple_display: stop thread on shutdown

TODO: tripledragon code needs testing
This commit is contained in:
Stefan Seyfried
2012-10-14 23:48:44 +02:00
parent 32597561a0
commit 46a2a11d5d
2 changed files with 18 additions and 1 deletions

View File

@@ -173,6 +173,7 @@ class CLCD
void setled(int red, int green); void setled(int red, int green);
static void *TimeThread(void *); static void *TimeThread(void *);
pthread_t thrTime; pthread_t thrTime;
bool thread_running;
#endif #endif
public: public:
bool has_lcd; bool has_lcd;
@@ -234,6 +235,9 @@ class CLCD
void Clear(); void Clear();
void ShowIcon(vfd_icon icon, bool show); void ShowIcon(vfd_icon icon, bool show);
void ShowText(const char *s) { showServicename(std::string(s)); }; void ShowText(const char *s) { showServicename(std::string(s)); };
#ifndef HAVE_TRIPLEDRAGON
~CLCD();
#endif
#ifdef LCD_UPDATE #ifdef LCD_UPDATE
private: private:
CFileList* m_fileList; CFileList* m_fileList;

View File

@@ -100,6 +100,17 @@ CLCD::CLCD()
/* do not show menu in neutrino... */ /* do not show menu in neutrino... */
has_lcd = false; has_lcd = false;
servicename = ""; servicename = "";
thread_running = false;
}
CLCD::~CLCD()
{
if (thread_running)
{
thread_running = false;
pthread_cancel(thrTime);
pthread_join(thrTime, NULL);
}
} }
CLCD* CLCD::getInstance() CLCD* CLCD::getInstance()
@@ -116,7 +127,7 @@ void CLCD::wake_up()
void* CLCD::TimeThread(void *) void* CLCD::TimeThread(void *)
{ {
while(1) { while (CLCD::getInstance()->thread_running) {
sleep(1); sleep(1);
CLCD::getInstance()->showTime(); CLCD::getInstance()->showTime();
/* hack, just if we missed the blit() somewhere /* hack, just if we missed the blit() somewhere
@@ -134,8 +145,10 @@ void* CLCD::TimeThread(void *)
void CLCD::init(const char *, const char *, const char *, const char *, const char *, const char *) void CLCD::init(const char *, const char *, const char *, const char *, const char *, const char *)
{ {
setMode(MODE_TVRADIO); setMode(MODE_TVRADIO);
thread_running = true;
if (pthread_create (&thrTime, NULL, TimeThread, NULL) != 0 ) { if (pthread_create (&thrTime, NULL, TimeThread, NULL) != 0 ) {
perror("[neutino] CLCD::init pthread_create(TimeThread)"); perror("[neutino] CLCD::init pthread_create(TimeThread)");
thread_running = false;
return ; return ;
} }
} }