Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / CSD_Strategy_Tests / TP_Common / OrbRunner.cpp
blobbde60f3b110ef8b2c03f5e33d3ca0bde67056e9e
1 #include "OrbRunner.h"
2 #include "OrbTask.h"
3 #include "TestAppExceptionC.h"
6 OrbRunner::OrbRunner(CORBA::ORB_ptr orb, unsigned num_orb_threads)
7 : orb_(CORBA::ORB::_duplicate(orb)),
8 num_orb_threads_(num_orb_threads)
13 OrbRunner::~OrbRunner()
18 void
19 OrbRunner::run()
21 ACE_ASSERT(this->num_orb_threads_ > 0);
23 // If the num_orb_threads_ is exactly one, then just use the current
24 // (mainline) thread to run the ORB event loop.
25 if (this->num_orb_threads_ == 1)
27 // Since the num_orb_threads_ is exactly one, we just use the current
28 // (mainline) thread to run the ORB event loop.
29 this->orb_->run();
31 else
33 // The num_orb_threads_ is greater than 1, so we will use an OrbTask
34 // (active object) to run the ORB event loop in (num_orb_threads_ - 1)
35 // threads. We use the current (mainline) thread as the other thread
36 // running the ORB event loop.
37 OrbTask orb_task(this->orb_.in(), this->num_orb_threads_ - 1);
39 // Activate the OrbTask worker threads
40 if (orb_task.open(0) != 0)
42 ACE_ERROR((LM_ERROR,
43 "(%P|%t) Failed to open the OrbTask.\n"));
44 throw TestAppException();
47 // This will use the current (mainline) thread to run the ORB event loop.
48 this->orb_->run();
50 // Now that the current thread has unblocked from running the orb,
51 // make sure to wait for all of the worker threads to complete.
52 orb_task.wait();