1 #include "Default_Dispatcher_Impl.h"
3 #include "ace/Sched_Params.h"
7 #if ! defined (__ACE_INLINE__)
8 #include "Default_Dispatcher_Impl.inl"
9 #endif /* __ACE_INLINE__ */
13 Default_Dispatcher_Impl::Default_Dispatcher_Impl ()
19 Default_Dispatcher_Impl::init_i (const Dispatcher_Attributes
& attrs
)
21 //create and init the dispatcher tasks here
23 ACE_DEBUG ((LM_DEBUG
, "entering init_t\n" ));
24 int size
= ACE_Utils::truncate_cast
<int> (attrs
.config_info_set_
.size ());
33 Dispatcher_Task_Auto_Ptr
* tasks_array
= 0;
34 ACE_NEW_RETURN (tasks_array
, Dispatcher_Task_Auto_Ptr
[ntasks_
], -1);
36 //ACE_DEBUG ((LM_DEBUG, "after new on task array\n" ));
37 tasks_
.reset(tasks_array
);
39 //ACE_DEBUG ((LM_DEBUG, "task array unique_ptr set\n" ));
41 ConfigInfoSet
& config_set
=
42 const_cast<ConfigInfoSet
&> (attrs
.config_info_set_
);
43 ConfigInfoSet::ITERATOR
iter(config_set
);
47 for (;i
<size
&& iter
.next (config
);iter
.advance ())
49 //ACE_DEBUG ((LM_DEBUG, "iter = %d\n", i));
50 Dispatcher_Task
* task
=0;
52 Dispatcher_Task (*config
,
53 ACE_Thread_Manager::instance()),
55 std::unique_ptr
<Dispatcher_Task
> tmp_task_unique_ptr (task
);
56 tasks_
[i
++] = std::move(tmp_task_unique_ptr
);
59 this->thr_creation_flags_
= attrs
.thread_creation_flags ();
61 if (attrs
.immediate_activation_
&& !this->activated_
)
66 curr_config_info_
= attrs
.config_info_set_
;
71 Default_Dispatcher_Impl::activate_i ()
78 for(i
=0; i
<ntasks_
; ++i
)
81 tasks_
[i
]->get_curr_config_info ().thread_priority_
;
83 if (this->tasks_
[i
]->activate (this->thr_creation_flags_
,
84 1, 1, priority
) == -1)
86 ACE_ERROR_RETURN ((LM_ERROR
,
87 ACE_TEXT ("EC (%P|%t) cannot activate queue.")
88 ACE_TEXT ("Need superuser privilege to run in RT class\n")),
98 Default_Dispatcher_Impl::find_task_with_preemption_prio (Priority_t prio
)
104 for( i
=0; i
<ntasks_
; ++i
)
106 if ( tasks_
[i
]->preemption_priority () == prio
)
107 return tasks_
[i
].get();
115 Default_Dispatcher_Impl::dispatch_i (const Dispatch_Command
* cmd
,
116 const QoSDescriptor
& qos_info
)
118 //delegate to the appropriate task
119 if (qos_info
.preemption_priority_
< 0)
122 Dispatcher_Task
* task
=
123 find_task_with_preemption_prio (qos_info
.preemption_priority_
);
125 //@@VS - We should insert this into the lowest prio queue.
126 //How do we know that the last queue is the lowest prio queue.
128 task
= tasks_
[ntasks_
-1].get ();
130 return task
->enqueue (cmd
, qos_info
);
134 Default_Dispatcher_Impl::shutdown_i ()
136 //This needs to be revisited based on mode transition and
137 //consistent cut through the queues
139 //post shutdown command to all tasks
142 for(i
=0; i
<ntasks_
; ++i
)
144 QoSDescriptor qos_info
;
145 Shutdown_Task_Command
* shutdown_cmd
= 0;
146 ACE_NEW_RETURN (shutdown_cmd
, Shutdown_Task_Command
, -1);
147 tasks_
[i
]->enqueue (shutdown_cmd
, qos_info
);
150 //wait for all tasks to exit
151 for (i
=0; i
<ntasks_
; ++i
)
160 Shutdown_Task_Command::execute ()