Bugfix of Exception Handling

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2021-05-03 19:20:52 +09:00
parent 8a2d28a5e4
commit 4478eafc8d
11 changed files with 43 additions and 30 deletions

View File

@@ -13,12 +13,13 @@
* Contributors:
* Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
**************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include <Timer.h>
#include <exception>
#include <getopt.h>
@@ -252,13 +253,17 @@ MultiTaskProcess::MultiTaskProcess()
theMultiTaskProcess = this;
_threadCount = 0;
_stopCount = 0;
_abortThreadNo = -1;
}
MultiTaskProcess::~MultiTaskProcess()
{
for (int i = 0; i < _threadCount; i++)
{
_threadList[i]->stop();
if ( i != _abortThreadNo)
{
_threadList[i]->stop();
}
}
}
@@ -281,20 +286,20 @@ void MultiTaskProcess::run(void)
while (true)
{
if (theProcess->checkSignal() == SIGINT )
if (theProcess->checkSignal() == SIGINT || _abortThreadNo > -1)
{
return;
}
else if (_stopCount > 0)
{
throw Exception("Task stopped !!\n\n");
}
sleep(1);
}
}
void MultiTaskProcess::waitStop(void)
{
/* Let threads exit from Select() */
pid_t pid = getpid();
kill(pid, SIGINT);
while (_stopCount < _threadCount)
{
sleep(1);
@@ -309,11 +314,19 @@ void MultiTaskProcess::threadStopped(void)
}
void MultiTaskProcess::attach(Thread* thread)
void MultiTaskProcess::abort(int threadNo)
{
_abortThreadNo = threadNo;
threadStopped();
}
int MultiTaskProcess::attach(Thread* thread)
{
int indexNo = 0;
_mutex.lock();
if (_threadCount < MQTTSNGW_MAX_TASK)
{
indexNo = _threadCount;
_threadList[_threadCount] = thread;
_threadCount++;
}
@@ -323,6 +336,7 @@ void MultiTaskProcess::attach(Thread* thread)
throw Exception("Full of Threads");
}
_mutex.unlock();
return indexNo;
}
int MultiTaskProcess::getParam(const char* parameter, char* value)