Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / RTScheduling / MIF_Scheduler / MIF_DT_Creator.cpp
blob884f1fb2f4223351b7b9434558a63b63d0500b21
1 #include "MIF_DT_Creator.h"
2 #include "test.h"
3 #include "MIF_Task.h"
5 MIF_DT_Creator::MIF_DT_Creator (void)
7 DT_TEST::instance ()->dt_creator (this);
10 Thread_Task*
11 MIF_DT_Creator::create_thr_task (int importance,
12 time_t start_time,
13 int load,
14 int iter,
15 int dist,
16 char *job_name)
18 MIF_Task* task;
19 ACE_NEW_RETURN (task,
20 MIF_Task (importance,
21 start_time,
22 load,
23 iter,
24 dist,
25 job_name,
26 this),
27 0);
28 return task;
31 CORBA::Policy_ptr
32 MIF_DT_Creator::sched_param (int importance)
34 return DT_TEST::instance ()->scheduler ()->create_segment_scheduling_parameter (importance);
37 void
38 MIF_DT_Creator::yield (time_t suspend_time,
39 Thread_Task*)
41 try
43 CORBA::Object_var object =
44 this->orb_->resolve_initial_references ("RTScheduler_Current");
45 RTScheduling::Current_var current =
46 RTScheduling::Current::_narrow (object.in ());
48 ACE_Time_Value const sus_time_value (suspend_time);
49 ACE_Time_Value now (ACE_OS::gettimeofday ());
50 while (((now - *base_time_) < sus_time_value) || (suspend_time == 1))
53 ACE_OS::sleep (1);
54 CORBA::Policy_var sched_param;
55 sched_param = this->sched_param (100);
56 const char * name = 0;
57 current->update_scheduling_segment (name,
58 sched_param.in (),
59 sched_param.in ());
60 now = ACE_OS::gettimeofday ();
61 if (suspend_time == 1)
62 break;
65 catch (const CORBA::Exception& ex)
67 ex._tao_print_exception ("Caught exception:");
71 int
72 MIF_DT_Creator::total_load (void)
74 return 1000;
77 void
78 MIF_DT_Creator::wait (void)
80 while (active_dt_count_ > 0 || active_job_count_ > 0)
82 try
84 (void)this->orb_->work_pending ();
86 catch (const CORBA::BAD_INV_ORDER &)
88 // If there is BAD_INV_ORDER exception there is
89 // no point in running this loop any more.
90 break;
92 yield(1,0);
96 ACE_STATIC_SVC_DEFINE(MIF_DT_Creator,
97 ACE_TEXT ("MIF_DT_Creator"),
98 ACE_SVC_OBJ_T,
99 &ACE_SVC_NAME (MIF_DT_Creator),
100 ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
103 ACE_FACTORY_DEFINE (ACE_Local_Service, MIF_DT_Creator)