diff options
author | Pixel <pixel@nobis-crew.org> | 2012-04-06 11:07:28 -0700 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2012-04-06 11:08:57 -0700 |
commit | 7fbb819bf6f590bf2337d2277f77487ef7a5ce86 (patch) | |
tree | 1ae26f0dd2259900276ea7e881af9a88ba2a1e01 /src | |
parent | 64de8836d4924862d6cc352f250b802e346c29be (diff) |
Making the threads (as well as the taskman thread) a bit more exception-robust.
Diffstat (limited to 'src')
-rw-r--r-- | src/TaskMan.cc | 6 | ||||
-rw-r--r-- | src/Threads.cc | 47 |
2 files changed, 46 insertions, 7 deletions
diff --git a/src/TaskMan.cc b/src/TaskMan.cc index 0f205cf..d91581e 100644 --- a/src/TaskMan.cc +++ b/src/TaskMan.cc @@ -356,9 +356,10 @@ void Balau::TaskMan::stop(int code) { } void * Balau::TaskMan::TaskManThread::proc() { - m_taskMan = new Balau::TaskMan(); bool success = false; + m_taskMan = NULL; try { + m_taskMan = new Balau::TaskMan(); m_taskMan->mainLoop(); success = true; } @@ -390,7 +391,8 @@ void * Balau::TaskMan::TaskManThread::proc() { Printer::log(M_ERROR | M_ALERT, "The TaskMan thread caused an unknown exception"); } if (!success) { - delete m_taskMan; + if (m_taskMan) + delete m_taskMan; m_taskMan = NULL; TaskMan::stop(-1); } diff --git a/src/Threads.cc b/src/Threads.cc index fe90394..867013d 100644 --- a/src/Threads.cc +++ b/src/Threads.cc @@ -2,6 +2,7 @@ #include "Threads.h" #include "Local.h" #include "Atomic.h" +#include "TaskMan.h" namespace Balau { @@ -39,11 +40,47 @@ Balau::RWLock::RWLock() { } void * Balau::ThreadHelper::threadProc(void * arg) { - void * tls = g_tlsManager->createTLS(); - g_tlsManager->setTLS(tls); - Balau::Thread * thread = reinterpret_cast<Balau::Thread *>(arg); - void * r = thread->proc(); - free(tls); + void * r = NULL; + bool success = false; + try { + void * tls = g_tlsManager->createTLS(); + g_tlsManager->setTLS(tls); + Balau::Thread * thread = reinterpret_cast<Balau::Thread *>(arg); + r = thread->proc(); + free(tls); + success = true; + } + catch (Exit e) { + Printer::log(M_ERROR, "We shouldn't have gotten an Exit exception here... exitting anyway"); + auto trace = e.getTrace(); + for (String & str : trace) + Printer::log(M_ERROR, "%s", str.to_charp()); + } + catch (RessourceException e) { + Printer::log(M_ERROR | M_ALERT, "The Thread got a ressource problem: %s", e.getMsg()); + const char * details = e.getDetails(); + if (details) + Printer::log(M_ERROR, " %s", details); + auto trace = e.getTrace(); + for (String & str : trace) + Printer::log(M_DEBUG, "%s", str.to_charp()); + } + catch (GeneralException e) { + Printer::log(M_ERROR | M_ALERT, "The Thread caused an exception: %s", e.getMsg()); + const char * details = e.getDetails(); + if (details) + Printer::log(M_ERROR, " %s", details); + auto trace = e.getTrace(); + for (String & str : trace) + Printer::log(M_DEBUG, "%s", str.to_charp()); + } + catch (...) { + Printer::log(M_ERROR | M_ALERT, "The Thread caused an unknown exception"); + } + + if (!success) + TaskMan::stop(-1); + return r; } |