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/Threads.cc | |
parent | 64de8836d4924862d6cc352f250b802e346c29be (diff) |
Making the threads (as well as the taskman thread) a bit more exception-robust.
Diffstat (limited to 'src/Threads.cc')
-rw-r--r-- | src/Threads.cc | 47 |
1 files changed, 42 insertions, 5 deletions
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; } |