Skip to content
Snippets Groups Projects
Commit f183a080 authored by Federico's avatar Federico
Browse files

Limited the use of errorHandler() to unrecoverable errors. Fixed a bug in Thread::setPriority()

parent 781cad46
No related branches found
No related tags found
No related merge requests found
...@@ -41,21 +41,8 @@ void errorHandler(Error e) ...@@ -41,21 +41,8 @@ void errorHandler(Error e)
bool interrupts=areInterruptsEnabled(); bool interrupts=areInterruptsEnabled();
if(interrupts) disableInterrupts(); if(interrupts) disableInterrupts();
bool isUnrecoverable=false; //Recoverable errors: None
//Recoverable errors
switch(e)
{
case INVALID_PARAMETERS:
IRQerrorLog("\r\n***Invalid parameter\r\n");
break;
case PROPAGATED_EXCEPTION:
IRQerrorLog("\r\n***An exception propagated through a thread\r\n");
break;
case MUTEX_UNLOCK_NOT_OWNER:
IRQerrorLog("\r\n***unlock() called on a non locked mutex\r\n");
default:
isUnrecoverable=true;
}
//Unrecoverable errors //Unrecoverable errors
switch(e) switch(e)
{ {
...@@ -87,15 +74,9 @@ void errorHandler(Error e) ...@@ -87,15 +74,9 @@ void errorHandler(Error e)
default: default:
break; break;
} }
if(isUnrecoverable)
{
#if _BOARD_SONY_NEWMAN
IRQerrorMarker(e+1);
#endif //_BOARD_SONY_NEWMAN
miosix_private::IRQsystemReboot(); miosix_private::IRQsystemReboot();
}
if(interrupts) enableInterrupts(); //if(interrupts) enableInterrupts(); // Not needed since no recoverable errors
} }
} //namespace miosix } //namespace miosix
...@@ -37,12 +37,7 @@ namespace miosix { ...@@ -37,12 +37,7 @@ namespace miosix {
*/ */
enum Error enum Error
{ {
/// A function/method was called with invalid parameters.<br> /// The heap is full, malloc/new returned NULL.<br>Error is UNRECOVERABLE
/// Error is recoverable.
INVALID_PARAMETERS,
/// The heap is full, malloc/new returned NULL.<br>
/// Whether error is recoverable is architecture specific.
OUT_OF_MEMORY, OUT_OF_MEMORY,
/// The stack of a thread overflowed.<br>Error is UNRECOVERABLE /// The stack of a thread overflowed.<br>Error is UNRECOVERABLE
...@@ -63,20 +58,12 @@ enum Error ...@@ -63,20 +58,12 @@ enum Error
/// Error is UNRECOVERABLE /// Error is UNRECOVERABLE
MUTEX_DEADLOCK, MUTEX_DEADLOCK,
/// An attempt to call unlock() on a mutex without first calling lock
/// has been detected.
MUTEX_UNLOCK_NOT_OWNER,
/// The calls to pauseKernel or disableInterrupts were nested too /// The calls to pauseKernel or disableInterrupts were nested too
///much. Error is UNRECOVERABLE ///much. Error is UNRECOVERABLE
NESTING_OVERFLOW, NESTING_OVERFLOW,
/// An uncaught exception propagated throug a thread's entry point.
/// Error is recoverable.
PROPAGATED_EXCEPTION,
/// Interrupts are wrongly enabled during boot /// Interrupts are wrongly enabled during boot
/// Error is unrecoverable /// Error is UNRECOVERABLE
INTERRUPTS_ENABLED_AT_BOOT INTERRUPTS_ENABLED_AT_BOOT
}; };
......
...@@ -294,11 +294,7 @@ Thread *Thread::create(void *(*startfunc)(void *), unsigned int stacksize, ...@@ -294,11 +294,7 @@ Thread *Thread::create(void *(*startfunc)(void *), unsigned int stacksize,
Priority priority, void *argv, unsigned short options) Priority priority, void *argv, unsigned short options)
{ {
//Check to see if input parameters are valid //Check to see if input parameters are valid
if(priority.validate()==false || stacksize<STACK_MIN) if(priority.validate()==false || stacksize<STACK_MIN) return NULL;
{
errorHandler(INVALID_PARAMETERS);
return NULL;
}
Thread *thread=doCreate(startfunc,stacksize,argv,options,false); Thread *thread=doCreate(startfunc,stacksize,argv,options,false);
if(thread==NULL) return NULL; if(thread==NULL) return NULL;
...@@ -399,7 +395,7 @@ Priority Thread::getPriority() ...@@ -399,7 +395,7 @@ Priority Thread::getPriority()
void Thread::setPriority(Priority pr) void Thread::setPriority(Priority pr)
{ {
if(pr.validate()==false) errorHandler(INVALID_PARAMETERS); if(pr.validate()==false) return;
PauseKernelLock lock; PauseKernelLock lock;
Thread *current=getCurrentThread(); Thread *current=getCurrentThread();
...@@ -657,13 +653,11 @@ void Thread::threadLauncher(void *(*threadfunc)(void*), void *argv) ...@@ -657,13 +653,11 @@ void Thread::threadLauncher(void *(*threadfunc)(void*), void *argv)
#else //__NO_EXCEPTIONS #else //__NO_EXCEPTIONS
try { try {
result=threadfunc(argv); result=threadfunc(argv);
} catch(std::exception& e) } catch(std::exception& e) {
{ errorLog("***An exception propagated through a thread\n");
errorHandler(PROPAGATED_EXCEPTION);
errorLog("what():%s\n",e.what()); errorLog("what():%s\n",e.what());
} catch(...) } catch(...) {
{ errorLog("***An exception propagated through a thread\n");
errorHandler(PROPAGATED_EXCEPTION);
} }
#endif //__NO_EXCEPTIONS #endif //__NO_EXCEPTIONS
//Thread returned from its entry point, so delete it //Thread returned from its entry point, so delete it
......
...@@ -440,8 +440,7 @@ public: ...@@ -440,8 +440,7 @@ public:
* \return a reference to the thread created, that can be used, for example, * \return a reference to the thread created, that can be used, for example,
* to delete it, or NULL in case of errors. * to delete it, or NULL in case of errors.
* *
* Calls errorHandler(INVALID_PARAMETERS) if stacksize or priority are * Can be called when the kernel is paused.
* invalid. Can be called when the kernel is paused.
*/ */
static Thread *create(void *(*startfunc)(void *), unsigned int stacksize, static Thread *create(void *(*startfunc)(void *), unsigned int stacksize,
Priority priority=Priority(), void *argv=NULL, Priority priority=Priority(), void *argv=NULL,
...@@ -564,8 +563,6 @@ public: ...@@ -564,8 +563,6 @@ public:
* another thread. * another thread.
* \param pr desired priority. Must be 0<=pr<PRIORITY_MAX * \param pr desired priority. Must be 0<=pr<PRIORITY_MAX
* *
* Calls errorHandler(INVALID_PARAMETERS) if pr is not within bounds.
*
* Can be called when the kernel is paused. * Can be called when the kernel is paused.
*/ */
static void setPriority(Priority pr); static void setPriority(Priority pr);
......
...@@ -158,10 +158,7 @@ static inline bool IRQdoMutexUnlock(pthread_mutex_t *mutex) ...@@ -158,10 +158,7 @@ static inline bool IRQdoMutexUnlock(pthread_mutex_t *mutex)
{ {
// Safety check removed for speed reasons // Safety check removed for speed reasons
// if(mutex->owner!=reinterpret_cast<void*>(Thread::IRQgetCurrentThread())) // if(mutex->owner!=reinterpret_cast<void*>(Thread::IRQgetCurrentThread()))
// {
// errorHandler(MUTEX_UNLOCK_NOT_OWNER);
// return false; // return false;
// }
if(mutex->recursive>0) if(mutex->recursive>0)
{ {
mutex->recursive--; mutex->recursive--;
...@@ -197,10 +194,7 @@ static inline unsigned int IRQdoMutexUnlockAllDepthLevels(pthread_mutex_t *mutex ...@@ -197,10 +194,7 @@ static inline unsigned int IRQdoMutexUnlockAllDepthLevels(pthread_mutex_t *mutex
{ {
// Safety check removed for speed reasons // Safety check removed for speed reasons
// if(mutex->owner!=reinterpret_cast<void*>(Thread::IRQgetCurrentThread())) // if(mutex->owner!=reinterpret_cast<void*>(Thread::IRQgetCurrentThread()))
// {
// errorHandler(MUTEX_UNLOCK_NOT_OWNER);
// return false; // return false;
// }
if(mutex->first!=0) if(mutex->first!=0)
{ {
Thread *t=reinterpret_cast<Thread*>(mutex->first->thread); Thread *t=reinterpret_cast<Thread*>(mutex->first->thread);
......
...@@ -98,13 +98,11 @@ void *mainLoader(void *argv) ...@@ -98,13 +98,11 @@ void *mainLoader(void *argv)
#else //__NO_EXCEPTIONS #else //__NO_EXCEPTIONS
try { try {
main(0,NULL); main(0,NULL);
} catch(std::exception& e) } catch(std::exception& e) {
{ errorLog("***An exception propagated through a thread\n");
errorHandler(PROPAGATED_EXCEPTION);
errorLog("what():%s\n",e.what()); errorLog("what():%s\n",e.what());
} catch(...) } catch(...) {
{ errorLog("***An exception propagated through a thread\n");
errorHandler(PROPAGATED_EXCEPTION);
} }
#endif //__NO_EXCEPTIONS #endif //__NO_EXCEPTIONS
......
...@@ -209,11 +209,7 @@ bool Mutex::PKtryLock(PauseKernelLock& dLock) ...@@ -209,11 +209,7 @@ bool Mutex::PKtryLock(PauseKernelLock& dLock)
bool Mutex::PKunlock(PauseKernelLock& dLock) bool Mutex::PKunlock(PauseKernelLock& dLock)
{ {
Thread *p=Thread::getCurrentThread(); Thread *p=Thread::getCurrentThread();
if(owner!=p) if(owner!=p) return false;
{
errorHandler(MUTEX_UNLOCK_NOT_OWNER);
return false;
}
if(recursiveDepth>0) if(recursiveDepth>0)
{ {
...@@ -290,11 +286,7 @@ bool Mutex::PKunlock(PauseKernelLock& dLock) ...@@ -290,11 +286,7 @@ bool Mutex::PKunlock(PauseKernelLock& dLock)
unsigned int Mutex::PKunlockAllDepthLevels(PauseKernelLock& dLock) unsigned int Mutex::PKunlockAllDepthLevels(PauseKernelLock& dLock)
{ {
Thread *p=Thread::getCurrentThread(); Thread *p=Thread::getCurrentThread();
if(owner!=p) if(owner!=p) return 0;
{
errorHandler(MUTEX_UNLOCK_NOT_OWNER);
return 0;
}
//Remove this mutex from the list of mutexes locked by the owner //Remove this mutex from the list of mutexes locked by the owner
if(owner->mutexLocked==this) if(owner->mutexLocked==this)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment