summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/TaskMan.cc6
-rw-r--r--src/Threads.cc47
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;
}