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
))
11 Thread_Task::activate_task (int thr_count
)
15 ACE_NEW_RETURN (shutdown_lock_
,
19 ACE_NEW_RETURN (lock_
,
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;
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
& )
42 "End Scheduling Segment is out of context - Expected Exception\n"));
44 catch (const CORBA::Exception
& ex
)
46 ex
._tao_print_exception ("\n");
52 "Making an update_scheduling_segment call without first calling begin_scheduling_segment\n"));
54 this->current_
->update_scheduling_segment (name
,
56 implicit_sched_param
);
58 catch (const CORBA::BAD_INV_ORDER
& )
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
,
78 if (ACE_OS::last_error () == EPERM
)
79 ACE_ERROR_RETURN ((LM_ERROR
,
80 ACE_TEXT ("Insufficient privilege to run this test.\n")),
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",
97 implicit_sched_param
);
100 RTScheduling::Current::IdType_var id
= this->current_
->id ();
101 ACE_OS::memcpy (&count
,
105 ACE_DEBUG ((LM_DEBUG
,
106 "Starting Distributable Thread %d with 3 nested scheduling segments....\n",
109 //Start - Nested Scheduling Segment
110 this->current_
->begin_scheduling_segment ("Two Towers",
112 implicit_sched_param
);
114 //Start - Nested Scheduling Segment
115 this->current_
->begin_scheduling_segment ("The Return of the King",
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",
129 for (unsigned int i
= 0; i
< segment_name_list
->length (); i
++)
131 ACE_DEBUG ((LM_DEBUG
,
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",
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.
158 orb_
->shutdown (false);
162 catch (const CORBA::Exception
& ex
)
164 ex
._tao_print_exception ("Caught exception:");
171 Thread_Task::~Thread_Task ()
173 delete shutdown_lock_
;