Commit 5b9b481b authored by Eric Cano's avatar Eric Cano
Browse files

Added support for Cthread_init and castor::BaseObject::resetServices in tape...

Added support for Cthread_init and castor::BaseObject::resetServices in tape threads and unit tests.

This will ensure that all tests and clients will be protected from memory leaks and race conditions.
parent 7734a6d8
......@@ -27,6 +27,8 @@
#include <typeinfo>
#include <stdlib.h>
#include <cxxabi.h>
#include "../../../../h/Cthread_api.h"
#include "castor/BaseObject.hpp"
/* Implmentations of the threading primitives */
......@@ -204,6 +206,9 @@ throw (castor::exception::Exception) {
void * castor::tape::threading::Thread::pthread_runner (void * arg) {
Thread * _this = (Thread *) arg;
// The threading init is needing by many castor components, so better do
// it all the time (this should not have side effects)
Cthread_init();
try {
_this->run();
} catch (std::exception & e) {
......@@ -217,6 +222,11 @@ void * castor::tape::threading::Thread::pthread_runner (void * arg) {
}
free(demangled);
_this->m_what = e.what();
} catch (...) {
_this->m_hadException = true;
_this->m_type = "unknown";
_this->m_what = "uncaught non-standard exception";
}
BaseObject::resetServices();
return NULL;
}
......@@ -24,10 +24,18 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "../h/Cthread_api.h"
#include "castor/BaseObject.hpp"
int main(int argc, char** argv) {
// The call to Cthread_init is necessary at the beginning of any program
// relying on the old "Cthread" collection. Calling should not have side
// effects.
Cthread_init();
// The following line must be executed to initialize Google Mock
// (and Google Test) before running the tests.
::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
int ret = RUN_ALL_TESTS();
castor::BaseObject::resetServices();
return ret;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment