00001
00002
00003 #include "orbsvcs/Event/EC_Priority_Dispatching.h"
00004 #include "orbsvcs/Event/EC_Dispatching_Task.h"
00005 #include "orbsvcs/Event/EC_Event_Channel_Base.h"
00006 #include "orbsvcs/Event/EC_QOS_Info.h"
00007
00008 #include "orbsvcs/Event_Service_Constants.h"
00009 #include "orbsvcs/RtecSchedulerC.h"
00010
00011 #include "ace/Sched_Params.h"
00012
00013 ACE_RCSID(Event, EC_Priority_Dispatching, "EC_Priority_Dispatching.cpp,v 1.22 2006/03/14 06:14:25 jtc Exp")
00014
00015 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00016
00017 TAO_EC_Priority_Dispatching::TAO_EC_Priority_Dispatching (TAO_EC_Event_Channel_Base *ec)
00018 : ntasks_ (0),
00019 tasks_ (0)
00020 {
00021 CORBA::Object_var tmp = ec->scheduler ();
00022 this->scheduler_ = RtecScheduler::Scheduler::_narrow (tmp.in ());
00023 }
00024
00025 void
00026 TAO_EC_Priority_Dispatching::activate (void)
00027 {
00028 if (this->tasks_ != 0)
00029 return;
00030
00031
00032 this->ntasks_ = ACE_Scheduler_MAX_PRIORITIES;
00033 ACE_NEW (this->tasks_, TAO_EC_Dispatching_Task*[this->ntasks_]);
00034
00035
00036 int priority =
00037 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO) +
00038 ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
00039 priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO, priority);
00040
00041 ACE_DECLARE_NEW_CORBA_ENV;
00042 for (int i = 0; i < this->ntasks_; ++i)
00043 {
00044 ACE_TRY
00045 {
00046 RtecScheduler::Period_t period =
00047 ACE_CU64_TO_CU32 (ACE_Scheduler_Rates[i]);
00048 char buf[128];
00049 ACE_OS::sprintf (buf, "Dispatching_Task-%d.us", period);
00050
00051 RtecScheduler::handle_t rt_info =
00052 this->scheduler_->create (buf ACE_ENV_ARG_PARAMETER);
00053 ACE_TRY_CHECK;
00054
00055 this->scheduler_->set (rt_info,
00056 RtecScheduler::VERY_LOW_CRITICALITY,
00057 0,
00058 0,
00059 0,
00060 period,
00061 RtecScheduler::VERY_LOW_IMPORTANCE,
00062 0,
00063 1,
00064 RtecScheduler::OPERATION
00065 ACE_ENV_ARG_PARAMETER);
00066 ACE_TRY_CHECK;
00067 }
00068 ACE_CATCHANY
00069 {
00070
00071 }
00072 ACE_ENDTRY;
00073
00074 ACE_NEW (this->tasks_[i],
00075 TAO_EC_Dispatching_Task (&this->thread_manager_));
00076
00077
00078 long flags = THR_BOUND | THR_SCHED_FIFO;
00079 if (this->tasks_[i]->activate (flags, 1, 1, priority) == -1)
00080 {
00081 flags = THR_BOUND;
00082 priority = ACE_Sched_Params::priority_min (ACE_SCHED_OTHER,
00083 ACE_SCOPE_THREAD);
00084 if (this->tasks_[i]->activate (flags, 1, 1, priority) == -1)
00085 ACE_ERROR ((LM_ERROR,
00086 "EC (%P|%t) cannot activate queue %d", i));
00087 }
00088 }
00089 }
00090
00091 void
00092 TAO_EC_Priority_Dispatching::shutdown (void)
00093 {
00094 if (this->tasks_ == 0)
00095 return;
00096
00097 for (int i = 0; i < this->ntasks_; ++i)
00098 this->tasks_[i]->putq (new TAO_EC_Shutdown_Task_Command);
00099
00100 this->thread_manager_.wait ();
00101
00102 for (int j = 0; j < this->ntasks_; ++j)
00103 delete this->tasks_[j];
00104
00105 delete[] this->tasks_;
00106 this->tasks_ = 0;
00107 }
00108
00109 void
00110 TAO_EC_Priority_Dispatching::push (TAO_EC_ProxyPushSupplier* proxy,
00111 RtecEventComm::PushConsumer_ptr consumer,
00112 const RtecEventComm::EventSet& event,
00113 TAO_EC_QOS_Info& qos_info
00114 ACE_ENV_ARG_DECL)
00115 {
00116 RtecEventComm::EventSet event_copy = event;
00117 this->push_nocopy (proxy, consumer, event_copy, qos_info ACE_ENV_ARG_PARAMETER);
00118 }
00119
00120 void
00121 TAO_EC_Priority_Dispatching::push_nocopy (TAO_EC_ProxyPushSupplier* proxy,
00122 RtecEventComm::PushConsumer_ptr consumer,
00123 RtecEventComm::EventSet& event,
00124 TAO_EC_QOS_Info& qos_info
00125 ACE_ENV_ARG_DECL)
00126 {
00127 if (this->tasks_ == 0)
00128 this->activate ();
00129
00130 int i = qos_info.preemption_priority;
00131 if (i < 0 || i >= this->ntasks_)
00132 {
00133
00134 i = 0;
00135 }
00136
00137
00138 this->tasks_[i]->push (proxy, consumer, event ACE_ENV_ARG_PARAMETER);
00139 }
00140
00141 TAO_END_VERSIONED_NAMESPACE_DECL