3 #include "ace/Sched_Params.h"
4 #include "ace/SString.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_strings.h"
7 #include "ace/OS_NS_sys_time.h"
10 ACE_CString sched_policy_str
= "fifo";
12 int parse_args (int argc
, ACE_TCHAR
*argv
[]);
14 class MyCommand
: public Kokyu::Dispatch_Command
18 :Kokyu::Dispatch_Command(1),id_(i
)
27 int MyCommand::execute()
29 ACE_hthread_t thr_handle
;
30 ACE_Thread::self (thr_handle
);
33 if (ACE_Thread::getprio (thr_handle
, prio
) == -1)
38 ACE_TEXT ("getprior not supported on this platform\n")
42 ACE_ERROR_RETURN ((LM_ERROR
,
44 ACE_TEXT ("getprio failed")),
49 ACE_TEXT ("(%t|prio=%d) | command %d executed\n"),
54 int ACE_TMAIN (int argc
, ACE_TCHAR
** argv
)
56 Kokyu::ConfigInfoSet
config_info(3);
58 int sched_policy
=ACE_SCHED_FIFO
;
60 Kokyu::Dispatcher_Attributes attrs
;
62 if (parse_args (argc
, argv
) == -1)
65 if (ACE_OS::strcasecmp(sched_policy_str
.c_str(), "fifo") == 0)
67 sched_policy
= ACE_SCHED_FIFO
;
69 else if (ACE_OS::strcasecmp(sched_policy_str
.c_str(), "other") == 0)
71 sched_policy
= ACE_SCHED_OTHER
;
73 else if (ACE_OS::strcasecmp(sched_policy_str
.c_str(), "rr") == 0)
75 sched_policy
= ACE_SCHED_RR
;
78 attrs
.sched_policy (sched_policy
);
80 Kokyu::Priority_t min_prio
=
81 ACE_Sched_Params::priority_min (sched_policy
);
83 config_info
[0].preemption_priority_
= 1;
84 config_info
[0].thread_priority_
= min_prio
;
85 config_info
[0].dispatching_type_
= Kokyu::DEADLINE_DISPATCHING
;
87 ACE_DEBUG ((LM_DEBUG
, "before create_dispatcher\n" ));
89 attrs
.config_info_set_
= config_info
;
90 std::unique_ptr
<Kokyu::Dispatcher
>
91 disp (Kokyu::Dispatcher_Factory::create_dispatcher (attrs
));
93 ACE_ASSERT (disp
.get() != 0);
95 MyCommand
cmd1(1), cmd2(2), cmd3(3);
97 Kokyu::QoSDescriptor qos1
, qos2
, qos3
;
99 // Get the current time.
100 ACE_Time_Value current_time
= ACE_OS::gettimeofday ();
102 ACE_Time_Value deadline1
, deadline2
, deadline3
;
104 deadline1
= current_time
+ ACE_Time_Value(150,0);
105 deadline2
= current_time
+ ACE_Time_Value(200,0);
106 deadline3
= current_time
+ ACE_Time_Value(100,0);
108 qos1
.preemption_priority_
= 1;
109 qos1
.deadline_
= deadline1
;
110 qos2
.preemption_priority_
= 1;
111 qos2
.deadline_
= deadline2
;
112 qos3
.preemption_priority_
= 1;
113 qos3
.deadline_
= deadline3
;
115 ACE_DEBUG ((LM_DEBUG
, "Deadline of command1 is %d\n",
116 qos1
.deadline_
.sec ()));
117 disp
->dispatch (&cmd1
, qos1
);
119 ACE_DEBUG ((LM_DEBUG
, "Deadline of command2 is %d\n",
120 qos2
.deadline_
.sec ()));
121 disp
->dispatch (&cmd2
, qos2
);
123 ACE_DEBUG ((LM_DEBUG
, "Deadline of command3 is %d\n",
124 qos3
.deadline_
.sec ()));
125 disp
->dispatch (&cmd3
, qos3
);
131 ACE_DEBUG ((LM_DEBUG
, "after shutdown\n"));
136 int parse_args (int argc
, ACE_TCHAR
*argv
[])
138 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("p:"));
141 while ((c
= get_opts ()) != -1)
145 sched_policy_str
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
150 ACE_ERROR_RETURN ((LM_ERROR
,
154 "-p <fifo|rr|other>"),
157 // Indicates successful parsing of the command line