Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / examples / RTScheduling / MIF_Scheduler / MIF_Task.cpp
blobd60b0961c979f8f4debac3b1a3a2cef1e2b107ca
1 #include "MIF_Task.h"
2 #include "test.h"
4 #include "ace/OS_NS_errno.h"
5 #include "ace/Countdown_Time.h"
7 MIF_Task::MIF_Task (int importance,
8 time_t start_time,
9 int load,
10 int iter,
11 int dist,
12 char *job_name,
13 DT_Creator *dt_creator)
15 this->load_ = load;
16 this->iter_ = iter;
17 this->start_time_ = start_time;
18 this->importance_ = importance;
19 this->dt_creator_ = dt_creator;
20 this->dist_ = dist;
21 this->job_name_ = CORBA::string_dup (job_name);
23 // create the stat object.
24 ACE_NEW (task_stats_, Task_Stats);
25 task_stats_->init (iter_);
29 MIF_Task::~MIF_Task (void)
31 delete task_stats_;
34 void
35 MIF_Task::pre_activate (void)
37 DT_TEST::instance ()->scheduler ()->incr_thr_count ();
40 void
41 MIF_Task::post_activate (void)
43 DT_TEST::instance ()->scheduler ()->wait ();
46 int
47 MIF_Task::activate_task (RTScheduling::Current_ptr current,
48 CORBA::Policy_ptr sched_param,
49 long flags,
50 ACE_Time_Value* base_time)
53 if (TAO_debug_level > 0)
54 ACE_DEBUG ((LM_DEBUG,
55 "MIF_Task::activate %d\n",
56 importance_));
58 char msg [BUFSIZ];
59 ACE_OS::sprintf (msg, "MIF_Task::activate task\n");
60 dt_creator_->log_msg (msg);
62 base_time_ = base_time;
64 current_ = RTScheduling::Current::_narrow (current);
66 sched_param_ = CORBA::Policy::_duplicate (sched_param);
68 pre_activate ();
70 if (this->activate (flags,
71 1) == -1)
73 if (ACE_OS::last_error () == EPERM)
74 ACE_ERROR_RETURN ((LM_ERROR,
75 ACE_TEXT ("Insufficient privilege to run this test.\n")),
76 -1);
79 post_activate ();
80 return 0;
83 int
84 MIF_Task::perform_task (void)
86 try
89 ACE_TCHAR msg [BUFSIZ];
90 ACE_OS::sprintf (msg,
91 ACE_TEXT("MIF_Task::perform_task ")
92 ACE_SIZE_T_FORMAT_SPECIFIER
93 ACE_TEXT("\n"),
94 count_);
95 dt_creator_->log_msg (ACE_TEXT_ALWAYS_CHAR(msg));
97 static CORBA::ULong prime_number = 9619;
98 CORBA::Policy_var sched_param;
99 sched_param = dt_creator_->sched_param (this->importance_);
100 const char * name = 0;
102 for (int i = 0; i < this->iter_; i++)
104 ACE_Time_Value run_time = ACE_OS::gettimeofday () - *base_time_;
105 TASK_STATS::instance ()->sample (run_time.sec (), count_);
107 ACE_Time_Value count_down_time (1);
108 ACE_Countdown_Time count_down (&count_down_time);
110 while (count_down_time > ACE_Time_Value::zero)
112 ACE::is_prime (prime_number,
114 prime_number / 2);
116 count_down.update ();
119 current_->update_scheduling_segment (name,
120 sched_param.in (),
121 sched_param.in ());
124 if (this->dist_)
126 this->job_->work (this->load_,
127 this->importance_);
129 for (int j = 0; j < this->iter_; j++)
131 ACE_Time_Value run_time = ACE_OS::gettimeofday () - *base_time_;
132 TASK_STATS::instance ()->sample (run_time.sec (), count_);
134 ACE_Time_Value count_down_time (1);
135 ACE_Countdown_Time count_down (&count_down_time);
137 while (count_down_time > ACE_Time_Value::zero)
140 ACE::is_prime (prime_number,
142 prime_number / 2);
143 count_down.update ();
146 current_->update_scheduling_segment (name,
147 sched_param.in (),
148 sched_param.in ());
155 catch (const CORBA::Exception& ex)
157 ex._tao_print_exception ("Caught exception:");
158 return -1;
161 if (TAO_debug_level > 0)
162 ACE_DEBUG ((LM_DEBUG,
163 "Thread %d\n",
164 this->count_));
166 if (dist_)
167 job_->shutdown ();
169 return 0;