Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / RTScheduling / Current / Thread_Task.cpp
blob979c3376d25700ed0b6b292e1f7d989a4c941cd3
1 #include "Thread_Task.h"
2 #include "ace/OS_NS_errno.h"
3 #include "ace/OS_NS_unistd.h"
5 Thread_Task::Thread_Task (CORBA::ORB_ptr orb)
6 : orb_ (CORBA::ORB::_duplicate (orb))
10 int
11 Thread_Task::activate_task (int thr_count)
13 try
15 ACE_NEW_RETURN (shutdown_lock_,
16 TAO_SYNCH_MUTEX,
17 -1);
19 ACE_NEW_RETURN (lock_,
20 TAO_SYNCH_MUTEX,
21 -1);
23 active_thread_count_ = thr_count;
25 CORBA::Object_var current_obj = this->orb_->resolve_initial_references ("RTScheduler_Current");
27 this->current_ = RTScheduling::Current::_narrow (current_obj.in ());
29 const char * name = 0;
30 CORBA::Policy_ptr sched_param = 0;
31 CORBA::Policy_ptr implicit_sched_param = 0;
33 try
35 ACE_DEBUG ((LM_DEBUG,
36 "Making an end_scheduling_segment call without first calling begin_scheduling_segment\n"));
37 this->current_->end_scheduling_segment (name);
39 catch (const CORBA::BAD_INV_ORDER& )
41 ACE_DEBUG ((LM_DEBUG,
42 "End Scheduling Segment is out of context - Expected Exception\n"));
44 catch (const CORBA::Exception& ex)
46 ex._tao_print_exception ("\n");
49 try
51 ACE_DEBUG ((LM_DEBUG,
52 "Making an update_scheduling_segment call without first calling begin_scheduling_segment\n"));
54 this->current_->update_scheduling_segment (name,
55 sched_param,
56 implicit_sched_param);
58 catch (const CORBA::BAD_INV_ORDER& )
60 ACE_DEBUG ((LM_DEBUG,
61 "Update Scheduling Segment is out of context - Expected Exception\n"));
63 catch (const CORBA::Exception& ex)
65 ex._tao_print_exception (
66 "Update Scheduling Segment is out of context:");
69 catch (const CORBA::Exception& ex)
71 ex._tao_print_exception ("Exception:");
74 long flags = THR_NEW_LWP | THR_JOINABLE;
75 if (this->activate (flags,
76 thr_count) == -1)
78 if (ACE_OS::last_error () == EPERM)
79 ACE_ERROR_RETURN ((LM_ERROR,
80 ACE_TEXT ("Insufficient privilege to run this test.\n")),
81 -1);
83 return 0;
86 int
87 Thread_Task::svc ()
89 try
91 const char * name = 0;
92 CORBA::Policy_ptr sched_param = 0;
93 CORBA::Policy_ptr implicit_sched_param = 0;
95 this->current_->begin_scheduling_segment ("Fellowship of the Rings",
96 sched_param,
97 implicit_sched_param);
99 size_t count = 0;
100 RTScheduling::Current::IdType_var id = this->current_->id ();
101 ACE_OS::memcpy (&count,
102 id->get_buffer (),
103 id->length ());
105 ACE_DEBUG ((LM_DEBUG,
106 "Starting Distributable Thread %d with 3 nested scheduling segments....\n",
107 count));
109 //Start - Nested Scheduling Segment
110 this->current_->begin_scheduling_segment ("Two Towers",
111 sched_param,
112 implicit_sched_param);
114 //Start - Nested Scheduling Segment
115 this->current_->begin_scheduling_segment ("The Return of the King",
116 sched_param,
117 implicit_sched_param);
120 RTScheduling::Current::NameList_var segment_name_list =
121 this->current_->current_scheduling_segment_names ();
124 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, *lock_, -1);
125 ACE_DEBUG ((LM_DEBUG,
126 "Segment Names for DT %d :\n",
127 count));
129 for (unsigned int i = 0; i < segment_name_list->length (); i ++)
131 ACE_DEBUG ((LM_DEBUG,
132 "%C\n",
133 (*segment_name_list)[i].in ()));
137 this->current_->end_scheduling_segment (name);
138 //End - Nested Scheduling Segment
140 this->current_->end_scheduling_segment (name);
142 this->current_->end_scheduling_segment (name);
143 //End - Nested Scheduling Segment
145 ACE_DEBUG ((LM_DEBUG,
146 "DT %d terminated ...\n",
147 count));
150 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, *shutdown_lock_,-1);
151 --active_thread_count_;
152 if (active_thread_count_ == 0)
154 // Without this sleep, we will occasionally get BAD_INV_ORDER
155 // exceptions on fast dual processor machines.
156 ACE_OS::sleep (1);
158 orb_->shutdown (false);
162 catch (const CORBA::Exception& ex)
164 ex._tao_print_exception ("Caught exception:");
165 return -1;
168 return 0;
171 Thread_Task::~Thread_Task ()
173 delete shutdown_lock_;
174 delete lock_;