Commit 7734a6d8 authored by Eric Cano's avatar Eric Cano
Browse files

Added castor::BaseObject::resetServices.

This allows the deletion of the services allocatated by the castor framework, and leak-free
unit tests.
parent 7607e229
......@@ -116,3 +116,20 @@ castor::Services* castor::BaseObject::services()
return services;
}
//------------------------------------------------------------------------------
// resetServices
//------------------------------------------------------------------------------
void castor::BaseObject::resetServices()
throw (castor::exception::Exception) {
// If the services where not allocated (unlikely), this will have the
// side effect of allocating them. The key will be created anyhow,
// which is what we need.
delete services();
const int rc = pthread_setspecific(s_servicesKey, NULL);
if(0 != rc) {
castor::exception::Exception e(rc);
e.getMessage() << "Failed to reset the thread's servicesKey to NULL after delete";
throw e;
}
}
......@@ -58,6 +58,13 @@ namespace castor {
*/
static Services* services() throw(castor::exception::Exception);
/**
* Static function to reset (deallocate + set the thread specific pointer
* to NULL) the thread-specific services. Useful in test environments and
* for clients which to not run the thread pools (but use the marshallers)
*/
static void resetServices() throw(castor::exception::Exception);
/**
* Static access to the underlying thread-shared Services object
*/
......
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