summaryrefslogtreecommitdiff
path: root/TAO/tao/RTCORBA/Pool_Per_Endpoint.cpp
blob: 6dbd6bfa4cc81d167191bd3059cfedd98f584d47 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// $Id$

#include "Pool_Per_Endpoint.h"
#include "tao/ORB.h"
#include "tao/ORB_Core.h"
#include "tao/Acceptor_Registry.h"
#include "tao/Thread_Lane_Resources.h"
#include "tao/Pluggable.h"
#include "Priority_Mapping_Manager.h"
#include "tao/debug.h"
#include "ace/Sched_Params.h"

#if !defined (__ACE_INLINE__)
# include "Pool_Per_Endpoint.i"
#endif /* ! __ACE_INLINE__ */

ACE_RCSID(tao, Pool_Per_Endpoint, "$Id$")

TAO_Pool_Per_Endpoint::TAO_Pool_Per_Endpoint (CORBA::ORB_ptr orb,
                                              int policy,
                                              int poolsize,
                                              int flags)
  :  orb_ (CORBA::ORB::_duplicate (orb)),
     policy_ (policy),
     poolsize_ (poolsize),
     flags_ (flags)
{
  this->thr_mgr (&this->thread_manager_);
}

TAO_Pool_Per_Endpoint::~TAO_Pool_Per_Endpoint (void)
{
}

void
TAO_Pool_Per_Endpoint::run (CORBA::Environment &ACE_TRY_ENV)
{
  CORBA::Object_var obj =
    this->orb_->resolve_initial_references (TAO_OBJID_PRIORITYMAPPINGMANAGER,
                                            ACE_TRY_ENV);

  TAO_Priority_Mapping_Manager_var mapping_manager =
    TAO_Priority_Mapping_Manager::_narrow (obj.in (),
                                           ACE_TRY_ENV);
  ACE_CHECK;

  RTCORBA::PriorityMapping *pm =
    mapping_manager.in ()->mapping ();

  TAO_Acceptor_Registry &ac =
    this->orb_->orb_core ()->lane_resources ().acceptor_registry ();

  for (TAO_AcceptorSetIterator i = ac.begin (); i != ac.end (); ++i)
    {
      int priority =
        ACE_Sched_Params::priority_min (this->policy_);

      const CORBA::Short corba_priority = (*i)->priority ();
      CORBA::Short native_priority;
      if (pm->to_native (corba_priority, native_priority) == 1)
        priority = native_priority;
      else
        ACE_THROW (CORBA::DATA_CONVERSION ());

      if (TAO_debug_level > 3)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("TAO (%P|%t) - creating thread at ")
                    ACE_TEXT ("priority %d:%d\n"),
                    priority,
                    corba_priority));

      if (this->activate (this->flags_,
                          this->poolsize_, /* number of threads */
                          1, /* force active */
                          priority) == -1)
        {
          ACE_THROW (CORBA::INTERNAL ());
        }
    }
  this->thread_manager_.wait ();
}

int
TAO_Pool_Per_Endpoint::svc (void)
{
  if (TAO_debug_level > 3)
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("TAO (%P|%t) - TAO_Pool_Per_Endpoint::svc: ")
                ACE_TEXT (" using reactor <%x> in this thread\n"),
                this->orb_->orb_core ()->reactor ()));

  this->orb_->run ();  // @@ Where's the error/exception check?

  if (TAO_debug_level > 3)
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("TAO (%P|%t) - TAO_Pool_Per_Endpoint::svc: ")
                ACE_TEXT (" ORB::run() finished\n")));
 return 0;
}

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)

#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)

#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */