diff options
Diffstat (limited to 'TAO/tests/CSD_Strategy_Tests/TP_Common/OrbRunner.cpp')
-rw-r--r-- | TAO/tests/CSD_Strategy_Tests/TP_Common/OrbRunner.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/TAO/tests/CSD_Strategy_Tests/TP_Common/OrbRunner.cpp b/TAO/tests/CSD_Strategy_Tests/TP_Common/OrbRunner.cpp new file mode 100644 index 00000000000..0cc9c9bd5ad --- /dev/null +++ b/TAO/tests/CSD_Strategy_Tests/TP_Common/OrbRunner.cpp @@ -0,0 +1,58 @@ +// $Id$ +#include "OrbRunner.h" +#include "OrbTask.h" +#include "TestAppExceptionC.h" + + +OrbRunner::OrbRunner(CORBA::ORB_ptr orb, unsigned num_orb_threads) + : orb_(CORBA::ORB::_duplicate(orb)), + num_orb_threads_(num_orb_threads) +{ +} + + +OrbRunner::~OrbRunner() +{ +} + + +void +OrbRunner::run(ACE_ENV_SINGLE_ARG_DECL) +{ + ACE_ASSERT(this->num_orb_threads_ > 0); + + // If the num_orb_threads_ is exactly one, then just use the current + // (mainline) thread to run the ORB event loop. + if (this->num_orb_threads_ == 1) + { + // Since the num_orb_threads_ is exactly one, we just use the current + // (mainline) thread to run the ORB event loop. + this->orb_->run(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + } + else + { + // The num_orb_threads_ is greater than 1, so we will use an OrbTask + // (active object) to run the ORB event loop in (num_orb_threads_ - 1) + // threads. We use the current (mainline) thread as the other thread + // running the ORB event loop. + OrbTask orb_task(this->orb_.in(), this->num_orb_threads_ - 1); + + // Activate the OrbTask worker threads + if (orb_task.open(0) != 0) + { + ACE_ERROR((LM_ERROR, + "(%P|%t) Failed to open the OrbTask.\n")); + ACE_THROW(TestAppException()); + } + + // This will use the current (mainline) thread to run the ORB event loop. + this->orb_->run(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + // Now that the current thread has unblocked from running the orb, + // make sure to wait for all of the worker threads to complete. + orb_task.wait(); + } +} + |