Bugfix of Handling Exception #236

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2021-04-27 21:34:08 +09:00
parent 60fcab2504
commit aaad3a0122
11 changed files with 56 additions and 60 deletions

View File

@@ -135,7 +135,7 @@ void Mutex::lock(void)
}
} catch (char* errmsg)
{
throw Exception( -1, "The same thread can't aquire a mutex twice.");
throw Exception( -1, "The same thread can't acquire a mutex twice.");
}
}
}
@@ -263,11 +263,6 @@ void NamedSemaphore::timedwait(uint16_t millsec)
/*=========================================
Class RingBuffer
=========================================*/
RingBuffer::RingBuffer()
{
RingBuffer(MQTTSNGW_KEY_DIRECTORY);
}
RingBuffer::RingBuffer(const char* keyDirectory)
{
int fp = 0;
@@ -506,6 +501,7 @@ void RingBuffer::reset()
Thread::Thread()
{
_threadID = 0;
_taskName = nullptr;
}
Thread::~Thread()
@@ -539,11 +535,6 @@ int Thread::start(void)
return pthread_create(&_threadID, 0, _run, runnable);
}
void Thread::stopProcess(void)
{
theMultiTaskProcess->threadStopped();
}
void Thread::stop(void)
{
if ( _threadID )
@@ -552,3 +543,13 @@ void Thread::stop(void)
_threadID = 0;
}
}
void Thread::setTaskName(const char* name)
{
_taskName = name;
}
const char* Thread::getTaskName(void)
{
return _taskName;
}

View File

@@ -92,8 +92,7 @@ private:
class RingBuffer
{
public:
RingBuffer();
RingBuffer(const char* keyDirctory);
RingBuffer(const char* keyDirctory = MQTTSNGW_KEY_DIRECTORY);
~RingBuffer();
void put(char* buffer);
int get(char* buffer, int bufferLength);
@@ -124,15 +123,17 @@ public:
#define MAGIC_WORD_FOR_THREAD \
public: void EXECRUN() \
{ \
try \
{ \
run(); \
stopProcess(); \
} \
catch(...) \
{ \
throw; \
} \
try \
{ \
run(); \
theMultiTaskProcess->threadStopped(); \
} \
catch ( Exception &ex ) \
{ \
theMultiTaskProcess->threadStopped(); \
WRITELOG("%s catch exception\n", getTaskName()); \
ex.writeMessage(); \
} \
}
/*=====================================
@@ -146,12 +147,14 @@ public:
static pthread_t getID();
static bool equals(pthread_t*, pthread_t*);
virtual void initialize(int argc, char** argv);
void stopProcess(void);
void waitStop(void);
void stop(void);
const char* getTaskName(void);
void setTaskName(const char* name);
private:
static void* _run(void*);
pthread_t _threadID;
const char* _taskName;
};
}