From 7fbb819bf6f590bf2337d2277f77487ef7a5ce86 Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 6 Apr 2012 11:07:28 -0700 Subject: Making the threads (as well as the taskman thread) a bit more exception-robust. --- src/TaskMan.cc | 6 ++++-- src/Threads.cc | 47 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 7 deletions(-) (limited to 'src') 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(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(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; } -- cgit v1.2.3