summaryrefslogtreecommitdiff
path: root/trunk/TAO/tests/CSD_Strategy_Tests/TP_Common/OrbRunner.cpp
blob: 812495cc732ddf514c01a64016378ea0d36a28b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// $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(void)
{
  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();
    }
  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"));
          throw TestAppException();
        }

      // This will use the current (mainline) thread to run the ORB event loop.
      this->orb_->run();

      // 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();
    }
}