Commit a778a8fb authored by Nicolas Philipps's avatar Nicolas Philipps
Browse files

Moved fwTest thread exception throwing to fwTest thread helper

--HG--
branch : fw4spl_0.9.0
extra : rebase_source : 803dbe2be7b29870bf84a9529c20e17589809740
parent e6270cfd
......@@ -98,15 +98,6 @@ void MTLockTest::multipleLockTest()
CPPUNIT_ASSERT(thread2.timedJoin(2500));
CPPUNIT_ASSERT_MESSAGE(m_string->value(), m_string->value()=="lili" || m_string->value()=="toto");
if (thread.hasFailed())
{
throw thread.getException();
}
if (thread2.hasFailed())
{
throw thread2.getException();
}
}
//-----------------------------------------------------------------------------
......
......@@ -102,13 +102,6 @@ void AppConfigParametersTest::concurentAccessToAppConfigParametersTest()
CPPUNIT_ASSERT_MESSAGE(str.str(), threads[i]->timedJoin(1000));
}
for (int i=0 ; i<nbThreads ; ++i)
{
if (threads[i]->hasFailed())
{
throw threads[i]->getException();
}
}
}
//------------------------------------------------------------------------------
......
......@@ -186,14 +186,6 @@ void AppConfigTest::concurentAccessToAppConfigTest()
std::vector< std::string > allCconfigs = ::fwServices::registry::AppConfig::getDefault()->getAllConfigs();
CPPUNIT_ASSERT(allCconfigs.empty());
for (int i=0 ; i<nbThreads*3 ; ++i)
{
if (threads[i]->hasFailed())
{
throw threads[i]->getException();
}
}
}
//------------------------------------------------------------------------------
......
......@@ -81,15 +81,6 @@ void ServiceConfigTest::concurentAccessToServiceConfigTest()
currentServiceConfig->clearRegistry();
std::vector< std::string > allCconfigs = currentServiceConfig->getAllConfigForService("::fwServices::ut::TestService");
CPPUNIT_ASSERT(allCconfigs.empty());
for (int i=0 ; i<nbThreads ; ++i)
{
if (threads[i]->hasFailed())
{
throw threads[i]->getException();
}
}
}
//------------------------------------------------------------------------------
......
......@@ -93,13 +93,6 @@ void FwIDTest::conccurentAccessOnFwIDMapTest()
CPPUNIT_ASSERT_MESSAGE(str.str(), threads[i]->timedJoin(1000));
}
for (int i=0 ; i<nbThreads ; ++i)
{
if (threads[i]->hasFailed())
{
throw threads[i]->getException();
}
}
}
//-----------------------------------------------------------------------------
......@@ -159,13 +152,6 @@ void FwIDTest::conccurentAccessOnSameObjFwIDTest()
CPPUNIT_ASSERT_MESSAGE(str.str(), threads[i]->timedJoin(1000));
}
for (int i=0 ; i<nbThreads ; ++i)
{
if (threads[i]->hasFailed())
{
throw threads[i]->getException();
}
}
}
//-----------------------------------------------------------------------------
......
......@@ -79,13 +79,6 @@ void UUIDTest::conccurentAccessOnUUIDMapTest()
CPPUNIT_ASSERT_MESSAGE(str.str(), threads[i]->timedJoin(1000));
}
for (int i=0 ; i<nbThreads ; ++i)
{
if (threads[i]->hasFailed())
{
throw threads[i]->getException();
}
}
}
//-----------------------------------------------------------------------------
......@@ -130,13 +123,6 @@ void UUIDTest::conccurentAccessOnSameObjUUIDTest()
CPPUNIT_ASSERT_MESSAGE(str.str(), threads[i]->timedJoin(1000));
}
for (int i=0 ; i<nbThreads ; ++i)
{
if (threads[i]->hasFailed())
{
throw threads[i]->getException();
}
}
}
//-----------------------------------------------------------------------------
......
......@@ -46,14 +46,14 @@ public:
FWTEST_API virtual ~Thread();
/// Waits the thread execution to complete
FWTEST_API void join();
FWTEST_API void join(bool raise = true);
/**
* @brief Waits the thread of execution to complete
* @param time time to waits for the thread stop
* @return true if the thread of execution has completed before the call times out
*/
FWTEST_API bool timedJoin(int time);
FWTEST_API bool timedJoin(int time, bool raise = true);
/// Return the exception raised in function launched by thread
CPPUNIT_NS::Exception getException() {return m_exception;}
......@@ -61,6 +61,11 @@ public:
/// Return true if function launched by thread raised exception
bool hasFailed() {return m_hasFailed;}
/**
* @brief If any, throws the exception raised by the thread function.
*/
void throwException();
private :
/// Method launched by thread : call run(f) surrounded by try/catch
......
......@@ -21,14 +21,31 @@ Thread::~Thread()
{
}
void Thread::join()
void Thread::join(bool raise)
{
m_thread.join();
if (raise)
{
this->throwException();
}
}
bool Thread::timedJoin(int time)
bool Thread::timedJoin(int time, bool raise)
{
return m_thread.timed_join(boost::posix_time::milliseconds(time));
bool joined = m_thread.timed_join(boost::posix_time::milliseconds(time));
if (raise)
{
this->throwException();
}
return joined;
}
void Thread::throwException()
{
if (this->hasFailed())
{
throw this->getException();
}
}
void Thread::run(FunctionType f)
......
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