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
18 struct QoSDescriptor_t
20 typedef long Importance_t
;
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
;
37 u_long
operator () (const Guid_t
& guid
)
45 class MyTask
: public ACE_Task_Base
48 MyTask (ACE_Barrier
& bar
,
49 Kokyu::DSRT_Dispatcher
<mif_scheduler_traits
>* dispatcher
,
50 mif_scheduler_traits::QoSDescriptor_t
& qos
,
53 dispatcher_ (dispatcher
),
56 exec_duration_ (exec_duration
)
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_
;
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_
);
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
);
92 while (compute_count_down_time
> ACE_Time_Value::zero
)
94 ACE::is_prime (prime_number
,
98 compute_count_down
.update ();
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_
));
114 dispatcher_
->cancel_schedule (this->guid_
);
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
;
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)
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)
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)
170 if (mytask3
.activate (flags
) == -1)
171 ACE_ERROR ((LM_ERROR
,
172 "EC (%P|%t) cannot activate task\n"));
177 ACE_DEBUG ((LM_DEBUG
, "main thread exiting\n"));