Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / Kokyu / tests / DSRT_MIF / MIF.cpp
blobc4da2b46de56c555ff46b0b18dc1448d72ce73d7
1 #include "ace/ACE.h"
2 #include "ace/Task.h"
3 #include "ace/Sched_Params.h"
4 #include "ace/Atomic_Op.h"
5 #include "ace/High_Res_Timer.h"
6 #include "ace/Barrier.h"
7 #include "ace/Lock_Adapter_T.h"
8 #include "ace/Countdown_Time.h"
10 #include "Kokyu_dsrt.h"
12 ACE_Atomic_Op<ACE_SYNCH_MUTEX, long> guid=0;
14 struct mif_scheduler_traits
16 typedef int Guid_t;
18 struct QoSDescriptor_t
20 typedef long Importance_t;
22 long importance_;
26 static Time_t now()
28 ACE_Time_Value now = ACE_OS::gettimeofday ();
29 return now.sec () * 10000000 + now.usec () * 10;
33 typedef Kokyu::MIF_Comparator<QoSDescriptor_t> QoSComparator_t;
35 struct Guid_Hash
37 u_long operator () (const Guid_t& guid)
39 return guid;
45 class MyTask : public ACE_Task_Base
47 public:
48 MyTask (ACE_Barrier& bar,
49 Kokyu::DSRT_Dispatcher<mif_scheduler_traits>* dispatcher,
50 mif_scheduler_traits::QoSDescriptor_t& qos,
51 int exec_duration)
52 :barrier_ (bar),
53 dispatcher_ (dispatcher),
54 qos_ (qos),
55 guid_ (++guid),
56 exec_duration_ (exec_duration)
59 int svc ();
61 private:
62 ACE_Barrier& barrier_;
63 Kokyu::DSRT_Dispatcher<mif_scheduler_traits>* dispatcher_;
64 mif_scheduler_traits::QoSDescriptor_t qos_;
65 mif_scheduler_traits::Guid_t guid_;
66 int exec_duration_;
69 int MyTask::svc ()
71 ACE_hthread_t thr_handle;
72 ACE_Thread::self (thr_handle);
74 ACE_DEBUG ((LM_DEBUG, "(%t|%T): task activated\n"));
75 ACE_ASSERT (dispatcher_ != 0);
77 (void) dispatcher_->schedule (guid_, qos_);
79 barrier_.wait ();
81 long prime_number = 9619899;
83 ACE_High_Res_Timer timer;
84 ACE_Time_Value elapsed_time;
85 ACE_Time_Value seconds_tracker(0,0);
87 ACE_Time_Value one_second (1,0);
88 ACE_Time_Value compute_count_down_time (exec_duration_, 0);
89 ACE_Countdown_Time compute_count_down (&compute_count_down_time);
91 timer.start ();
92 while (compute_count_down_time > ACE_Time_Value::zero)
94 ACE::is_prime (prime_number,
96 prime_number / 2);
98 compute_count_down.update ();
99 timer.stop ();
100 timer.elapsed_time (elapsed_time);
101 seconds_tracker += elapsed_time;
102 if (seconds_tracker >= one_second)
104 seconds_tracker.set (0,0);
105 ACE_DEBUG ((LM_DEBUG,
106 ACE_TEXT ("(%t) Currently running guid=%d")
107 ACE_TEXT (", qos_.importance=%d\n"),
108 guid_, qos_.importance_));
110 timer.reset ();
111 timer.start ();
114 dispatcher_->cancel_schedule (this->guid_);
115 return 0;
118 int ACE_TMAIN (int,ACE_TCHAR**)
120 Kokyu::DSRT_ConfigInfo config_info;
122 // config_info.scheduler_type_ = Kokyu::SCHED_MIF;
123 config_info.impl_type_ = Kokyu::DSRT_OS_BASED;
125 ACE_Barrier bar (3);
127 ACE_DEBUG ((LM_DEBUG, "before create_dispatcher\n" ));
129 config_info.sched_strategy_ = Kokyu::DSRT_MIF;
131 Kokyu::DSRT_Dispatcher_Factory<mif_scheduler_traits>::DSRT_Dispatcher_Auto_Ptr
132 disp (Kokyu::DSRT_Dispatcher_Factory<mif_scheduler_traits>::
133 create_DSRT_dispatcher (config_info));
135 ACE_DEBUG ((LM_DEBUG, "after create_dispatcher\n" ));
137 ACE_ASSERT (disp.get () != 0);
139 mif_scheduler_traits::QoSDescriptor_t qos1, qos2, qos3;
141 qos1.importance_ = 1;
142 qos2.importance_ = 2;
143 qos3.importance_ = 3;
145 MyTask mytask1 (bar, disp.get (), qos1, 15);
146 MyTask mytask2 (bar, disp.get (), qos2, 6);
147 MyTask mytask3 (bar, disp.get (), qos3, 4);
149 long flags = THR_BOUND | THR_SCHED_FIFO;
151 if (mytask1.activate (flags) == -1)
153 flags = THR_BOUND;
154 if (mytask1.activate (flags) == -1)
155 ACE_ERROR ((LM_ERROR,
156 "EC (%P|%t) cannot activate task\n"));
159 if (mytask2.activate (flags) == -1)
161 flags = THR_BOUND;
162 if (mytask2.activate (flags) == -1)
163 ACE_ERROR ((LM_ERROR,
164 "EC (%P|%t) cannot activate task\n"));
167 if (mytask3.activate (flags) == -1)
169 flags = THR_BOUND;
170 if (mytask3.activate (flags) == -1)
171 ACE_ERROR ((LM_ERROR,
172 "EC (%P|%t) cannot activate task\n"));
175 disp->shutdown ();
177 ACE_DEBUG ((LM_DEBUG, "main thread exiting\n"));
179 return 0;