Update: Thread Termination procedure

to release all pthread allocate memories.

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2016-10-26 11:33:25 +09:00
parent c3e8470812
commit 5026c94502
5 changed files with 17 additions and 4 deletions

View File

@@ -255,7 +255,10 @@ MultiTaskProcess::MultiTaskProcess()
MultiTaskProcess::~MultiTaskProcess() MultiTaskProcess::~MultiTaskProcess()
{ {
for (int i = 0; i < _threadCount; i++)
{
_threadList[i]->stop();
}
} }
void MultiTaskProcess::initialize(int argc, char** argv) void MultiTaskProcess::initialize(int argc, char** argv)
@@ -309,6 +312,7 @@ void MultiTaskProcess::threadStoped(void)
_mutex.lock(); _mutex.lock();
_stopCount++; _stopCount++;
_mutex.unlock(); _mutex.unlock();
} }
void MultiTaskProcess::attach(Thread* thread) void MultiTaskProcess::attach(Thread* thread)

View File

@@ -235,7 +235,7 @@ void Gateway::run(void)
MultiTaskProcess::run(); MultiTaskProcess::run();
/* stop threads */ /* stop Tasks */
Event* ev = new Event(); Event* ev = new Event();
ev->setStop(); ev->setStop();
_packetEventQue.post(ev); _packetEventQue.post(ev);
@@ -246,7 +246,7 @@ void Gateway::run(void)
ev->setStop(); ev->setStop();
_clientSendQue.post(ev); _clientSendQue.post(ev);
/* wait until all threads stop */ /* wait until all Task stop */
MultiTaskProcess::waitStop(); MultiTaskProcess::waitStop();
WRITELOG("\n%s MQTT-SN Gateway stoped\n\n", currentDateTime()); WRITELOG("\n%s MQTT-SN Gateway stoped\n\n", currentDateTime());

View File

@@ -25,7 +25,7 @@ namespace MQTTSNGW
/*================================= /*=================================
* Starting prompt * Starting prompt
==================================*/ ==================================*/
#define GATEWAY_VERSION " * Version: 0.9.4" #define GATEWAY_VERSION " * Version: 0.9.5"
#define PAHO_COPYRIGHT0 " * MQTT-SN Transparent Gateway" #define PAHO_COPYRIGHT0 " * MQTT-SN Transparent Gateway"
#define PAHO_COPYRIGHT1 " * Part of Project Paho in Eclipse" #define PAHO_COPYRIGHT1 " * Part of Project Paho in Eclipse"

View File

@@ -514,3 +514,11 @@ void Thread::stopProcess(void)
theMultiTaskProcess->threadStoped(); theMultiTaskProcess->threadStoped();
} }
void Thread::stop(void)
{
if ( _threadID )
{
pthread_join(_threadID, NULL);
_threadID = 0;
}
}

View File

@@ -128,6 +128,7 @@ public:
virtual void initialize(int argc, char** argv); virtual void initialize(int argc, char** argv);
void stopProcess(void); void stopProcess(void);
void waitStop(void); void waitStop(void);
void stop(void);
private: private:
static void* _run(void*); static void* _run(void*);
pthread_t _threadID; pthread_t _threadID;