shutdown_count: stop thread in destructor

This commit is contained in:
Stefan Seyfried
2012-10-14 23:53:05 +02:00
parent 46a2a11d5d
commit c37955bdb2
2 changed files with 16 additions and 3 deletions

View File

@@ -4,6 +4,7 @@
Copyright (C) 2001 Steffen Hehn 'McClean' Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/ Homepage: http://dbox.cyberphoria.org/
Copyright (C) 2012 Stefan Seyfried
License: GPL License: GPL
@@ -42,6 +43,16 @@ SHTDCNT::SHTDCNT()
{ {
} }
SHTDCNT::~SHTDCNT()
{
if (thread_running)
{
thread_running = false;
pthread_cancel(thrTime);
pthread_join(thrTime, NULL);
}
}
SHTDCNT* SHTDCNT::getInstance() SHTDCNT* SHTDCNT::getInstance()
{ {
static SHTDCNT* shtdcnt = NULL; static SHTDCNT* shtdcnt = NULL;
@@ -66,9 +77,11 @@ void SHTDCNT::init()
{ {
shutdown_cnt = atoi(g_settings.shutdown_count) * 60; shutdown_cnt = atoi(g_settings.shutdown_count) * 60;
sleep_cnt = atoi(g_settings.shutdown_min)*60; sleep_cnt = atoi(g_settings.shutdown_min)*60;
thread_running = true;
if (pthread_create (&thrTime, NULL, TimeThread, NULL) != 0 ) if (pthread_create (&thrTime, NULL, TimeThread, NULL) != 0 )
{ {
perror("[SHTDCNT]: pthread_create(TimeThread)"); perror("[SHTDCNT]: pthread_create(TimeThread)");
thread_running = false;
return ; return ;
} }
} }

View File

@@ -4,7 +4,7 @@
Copyright (C) 2001 Steffen Hehn 'McClean' Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/ Homepage: http://dbox.cyberphoria.org/
Copyright (C) 2012 Stefan Seyfried
License: GPL License: GPL
@@ -34,6 +34,7 @@ class SHTDCNT
private: private:
pthread_t thrTime; pthread_t thrTime;
bool thread_running;
unsigned int shutdown_cnt; unsigned int shutdown_cnt;
unsigned int sleep_cnt; unsigned int sleep_cnt;
CConfigFile configfile; CConfigFile configfile;
@@ -42,9 +43,8 @@ class SHTDCNT
SHTDCNT(); SHTDCNT();
static void* TimeThread(void*); static void* TimeThread(void*);
public: public:
~SHTDCNT();
void setlcdparameter(void); void setlcdparameter(void);
static SHTDCNT* getInstance(); static SHTDCNT* getInstance();